Linux: files with white spaces, backslashes and more.

Subject:

Tip #1: Put filenames in quotes

The following command is required to copy or delete files with spaces in their name, for example:

$ cp "my resume.doc" /secure/location/ $ rm "my resume.doc"

The quotes also prevent the many special characters interpreted by your shell, for example:

$ rm -v ">file" removed `>file'

The double quotes preserve the value of all characters enclosed, except for the dollar sign, the backticks and the backslash. You can also try single quotes as follows:

$ rm -v 'a long file name here' $ cp 'my mp3 file.mp3' /backup/disk/

Tip #2: Try a backslash

You can always insert a backslash (\) before the special character in your filename:

$ cp "my\ resume.doc" /secure/location/ $ rm "\*file"

Tip #3: Try a ./ at the beginning of the filename

The syntax is as follows to delete a file called '-file':

$ rm -v ./-file removed `./-file'

The ./ at the beginning of the filename forces rm not to interpret - as option to the rm command.

Tip #4: Try a -- at the beginning of the filename

A -- signals the end of options and disables further option processing by shell. Any arguments after the -- are treated as filenames and arguments. An argument of - is equivalent to --. The syntax is:

$ rm -v -- -file $ rm -v -- --file $ rm -v -- "@#$%^&file" $ rmdir -v -- "--dirnameHere"

Tip #5: Remove file by an inode number

The -i option to ls displays the index number (inode) of each file:

ls -li

Use find command as follows to delete the file if the file has inode number 4063242:

$ find . -inum 4063242 -delete

OR

$ find . -inum 4063242 -exec rm -i {} \;

2014-10-09 19:03:40gstlouis