Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create files with special characters in Linux?

I am using the touch command to try and create a file with the name "\?$*'KwaMe'*$?\" (quotation marks included as part of the file name). However when I type touch "\?$*'KwaMe'*$?\" in the Terminal, it doesn't give me the result I am expecting. How can I create this file?

like image 455
Cameron Shirley Avatar asked Apr 23 '18 19:04

Cameron Shirley


1 Answers

You need to escape special characters with the backslash symbol (\).


This command will create a file named "\?$*'KwaMe'*$?\":

touch \"\\\?\$\*\'KwaMe\'\*\$\?\\\"

Explanation

  1. Double your \, like this: \\, so that your shell does not interpret the backslashes from your filename as escape characters.
  2. Escape " and ', like this: \", \', so that your shell interprets the double quotes as part of the filename.
  3. Escape $, like this: \$, otherwise your shell will think you're using a variable.
  4. Escape ? and *, like this: \?, \*, to prevent filename expansion.
like image 66
Ronan Boiteau Avatar answered Nov 13 '22 20:11

Ronan Boiteau