4

So, on a CentOS box, I accidentally executed :w<Down> in a vim editor, with "<Down>" being literally pressing the down arrow key on the keyboard (rendered onscreen as "<Down>"), and now I have a file named "<Down>" which I can't seem to get rid of; running "rm <Down>" (literally spelling out "less-than, D, o, w, n, greater-than") gives a syntax error.

How can I get rid of this file with the funky name?

5 Answers 5

12

Use singlequotes to keep the control characters from being processed:

rm -f '<Down>'
1
  • We have all ran into this issue at some point when we first started out with linux. I for the longest time had trouble editing files with spaces in the name until I realized I could just put quotes around it. Jul 15, 2010 at 19:33
9

Use \ to escape special characters. In this case, you would use

rm \<Down\>
5

As an alternate solution:

$ ls -il .
total 0
1439039 -rw-r--r-- 1 medina foo 0 2010-07-15 16:48 ?????

# http://www.gnu.org/software/findutils/manual/html_mono/find.html#Deleting-Files
$ find . -inum 1439039 -delete
2

The easiest way I found to deal with all cases of escaping is using a scripting language:

$ cd /tmp/test/
$ ls
<Down>
$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.unlink('<Down>')
>>> quit()
$ ls
1

type rm <D and then press TAB , it will show suggestions, for the name of the desired file..

1
  • 1
    I deleted your duplicate answer - 'interesting' choice of icon by the way...
    – Chopper3
    Jul 16, 2010 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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