Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using terminal on a Ubuntu machine and there is a file that I would like to delete. The file's name is \ (just a backslash).

Now usually I would just do

rm filename

However if I do rm \ then it thinks I'm trying to write a multi-line command.

How can I delete this file? I know that I could just use the GUI file system, but that's not very efficient.

So, how can I delete (in terminal) a file called \?

share|improve this question
Why do you have a file named that? (It doesn't even let me put it in a code block here in this comment!) – AJMansfield Jul 29 '13 at 19:59
More fun is trying to delete a file called <BEL>, aka Ctrl-G if I recall correctly. Everytime you do a ls the keyboard beeps at you until you (a) discovered the invisible file; and (b) determined how to delete a file with only one unprintable character in its name. – Pieter Geerkens Jul 30 '13 at 0:48
More importantly, how do you delete a file named "/" ? – Curt Jul 30 '13 at 1:44
I always liked the file named * myself... – RBerteig Jul 31 '13 at 5:53
@Pieter Geerkens, +10, I shall try this! How do you create a file with the name of unprintable character? – Vorac Jul 31 '13 at 14:40
up vote 45 down vote accepted

Use rm \\ (escape the backslash with another backslash). Note that this also works similarily, for directories named \ (using either rmdir, or rm with the -r flag).


>mkdir demo
>cd demo
>touch \\
>ls -l
total 0
-rw-------  1 hennes  users  0 Jul 29 20:25 \
>rm \\
>ls -l
total 0
share|improve this answer
Or, under the same principle, rm '\' (but not rm "\"). – evilsoup Jul 30 '13 at 17:06
@evilsoup just to provide some additional clarification on that, the \ character is used as an escape character in double-quote delimited strings. Saying rm "\" will be parsed into an unclosed string, as the second quotation mark is used with an escape character (and thus will be parsed as the double-quote character itself, and not the end of a string). Thus, the terminal will wait until you finish the string with another ". The equivalent method to use double quotes here would be rm "\\" (which is directly equivalent to both rm '\' and rm \\ , as you already confirmed). – Breakthrough Jul 31 '13 at 17:50

A general tactic for manually deleting files with awkward characters in their names is

rm -i ./*

This will prompt you to choose whether or not to delete each file in the directory.

share|improve this answer
Or, single it was a single char. rm -i ./? – Hennes Jul 30 '13 at 11:52
Yeah. If you can write a more specific glob than ./*, that's always a good idea, especially when doing something destructive. – zwol Jul 30 '13 at 13:31
+1 for prefixing your glob with ./ – evilsoup Jul 30 '13 at 17:08

You can also unlink by referencing the inode of a file

linus ~/test $ touch \\
linus ~/test $ ls -li
total 0
15204561 -rw-r--r-- 1 pat sudo 0 Jul 29 23:03 \
linus ~/test $ find . -inum 15204561 -exec rm -v {} \;
removed `./\\'
linus ~/test $ ls -li
total 0
linus ~/test $ 
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .