Remove linux file named with set of shell responsive characters

I've created a file named \;:$"\' to test a software of mine. I ended up with an error, because I cannot delete the file property. I'm trying to find a precise character combination to remove it via rm, but I cannot find a way.

rm \\;:$\"\\\'
rm: cannot remove `\\': No such file or directory

rm "\\"\;:$\"\\\'
rm: cannot remove `\\;:$"\\\'': No such file or directory

rm '\;:$"\'''
rm: cannot remove `\\;:$"\\': No such file or directory

(This last try killed me)

And many many other attempts. Helping hand needed!


If the files name is exactly \;:$"\', then you should be able to remove it with:

rm \\\;\:\$\"\\\'

Just ecape all the characters with a single \.


You can try ls -li in the directory containing the file and deleting the file with the inode returned by issuing find . -inum <inode-number> -exec rm -i {} \;

I added the -i to the find command to prompt before deletion in case another file is found by the find command than you expect.

In addition to the comment I tried to create and remove the file myself:

ls -l
total 0
-rw-r--r-- 1 test test 0 mrt 24 14:11 \;:$"\'

[test@testhost +1] /tmp/ff$ rm \\\;\:\$\"\\\' 

[test@testhost +1] /tmp/ff$ ls -l
total 0

You can use single quotes, and then you only have to worry about quoting the single quote itself.

rm '\;:$"\'\'

In interactive use, you could simply use tab completion, starting with '\ or \\. Tab completion from '\ yields '\;:$"\'\''', since bash simply replaces every embedded single quote with '\''. Tab completion from nothing or from \\ yields \\\;\:\$\"\\\'.


In bash and similar shells

read -r; rm "$REPLY"

then just type in the filename literally, \;:$"\', and press Enter. The read command reads a line from standard input and saves it to the variable REPLY. The -r flag tells it to read the line literally and not interpret backslashes as escape sequences. Quoting $REPLY ensures that the contents of REPLY will be passed to rm as a single argument so this will also work even if the filename contains spaces or tabs.

(Note: If the filename contains newline characters, apparently you can use the -d option to read to change the terminating character for the string you want to enter.)