Home   Profile   Fun
#71 Linux  03.04.2007

How to handle unusual file or directory names


As an example we use the command touch.

Single quotes: Create the file 'FILE1'
touch "'FILE1'"

Double quotes: Create the file FILE"2"
touch FILE\"2\"

Blanks: Create the file FILE 3
touch "FILE 3"
or
touch FILE\ 3

Generally the backslash (\) can be used to handle special characters:

Create the file FILE$4
touch FILE\$4

Create the file FILE\4
touch FILE\\4

Leading dashes are an exception, touch \-FILE5 will not work. To create the file -FILE5 use instead
touch -- -FILE5
or
touch ./-FILE5

The "--" means no options will follow, take everything as arguments

File or directory names containing a slash are not allowed.