Remove a file with <Down> in the name?
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?
Use singlequotes to keep the control characters from being processed:
rm -f '<Down>'
Use \ to escape special characters. In this case, you would use
rm \<Down\>
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
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