7

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!

chaos
  • 4,304
Alex
  • 227

8 Answers8

12

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

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

Just ecape all the characters with a single \.

chaos
  • 4,304
5

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
Lambert
  • 269
2

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 \\\;\:\$\"\\\'.

Random832
  • 641
2

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.)

Brian
  • 201
1

If you are not limited to using bash or another shell script environment, an easy way to remove such a file would probably be to either write a short program that simply calls unlink() in your favorite language, or use a file manager such as Gnome Commander or Midnight Commander to delete the file manually. The latter option would allow you to select the file in question and delete it without ever having to enter the file name anywhere, which would remove the possibility of metacharacters having any special meaning at all.

user
  • 30,336
0

Try this,

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

"\" is used as escape sequence in bash scripting which has a litral meaning.

Vengat
  • 17
0

I find it easiest in such cases to type/escape at most a few characters and then let bash complete the command with <TAB>: bash then makes sure to quote the stuff suitable for its own purposes.

In this case, if I do

touch '\;:$"\'\'
rm \ <TAB>

the completion for repeated <TAB> subsequently goes to

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

Now I am actually a bit at a loss explaining the intermediate stages, but the final proposal is sensible.

As a rule of thumb when not using completion, I tend to quote everything by including it in '...' marks. Obviously, you then need to write ' itself as '\'', namely end the quotes, write \; to produce a single ' and reenter another quoted string. That's the recipe I used for the touch command except for omitting the final resulting '' since it does not add anything.

0

Another good solution is to install oh-my-zsh,
type rm, and tab over to the file you want to delete. ;)