I accidently create a "\" file into my linux how to revert it. I tried rm \ (as it's the escaping character it didn't work), rm '\' and rm \\ nothing worked.

link|improve this question
How do you escape the escape character? With another escape character of course. – John Gardeniers Oct 12 '10 at 2:49
Oh god I tried to show a double backslash and the editor of serverfault.com just escape it, so you were seeing only one blackslash. I need to escape this one too. Infinite looping question! – Gopoi Oct 12 '10 at 2:59
You can use backticks to represent a double-backslash. See my formatting test at meta.stackoverflow.com/questions/3122/formatting-sandbox/… – Stefan Lasiewski Oct 12 '10 at 3:44
feedback

1 Answer

up vote 6 down vote accepted

As you said, you can't remove the file "\" directory, since \ is used as the shell escape character.

So instead, use the \ character to escape the file/directory named "\":

$ rm -i \\

Here's my test:

# Make and verify the problem
$ touch \\
$ ls -ld \\
-rw-r--r--  1 me  me  0 Oct 11 16:59 \

# Remove the file:
$ rm -i \\
remove \? y
$ ls -ld \\
ls: \: No such file or directory
link|improve this answer
1  
I tried it and it did the same thing as \, but I redid it with a new fresh termial and it worked. +1 for providing a proof. – Gopoi Oct 12 '10 at 0:07
1  
Good thinking to try with a new terminal. It sounds like you old terminal might have gotten corrupt. – Stefan Lasiewski Oct 12 '10 at 0:13
+1 for rm -i ; if all else fails, rm -i ./* will prompt for removal of every file individually... including the troublingly-named one. – pjz Oct 12 '10 at 0:52
I had the same problem recently with the tilde (~). Solved it by using quotes: rm "~", and it looks the same holds true for \: rm "\\". – churnd Oct 12 '10 at 11:04
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.