Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a pesky little file whose name appears to be single character, and that character is a \r

How can I delete this?

This is what I get with ls -bl:

-rw-rwxr--+   1 root             snapplewriters        0 Aug 29  2011 \r

ls -l just display it "?"

share|improve this question
    
How did you even end up with a file named like that? –  mkaito Apr 4 '12 at 1:57
    
Accepted answer would be appreciated! –  Garrett Aug 8 '12 at 3:31

5 Answers 5

Us ls -li to get the inode number for the file (first column), then use find to delete it (assuming inode is 12345):

find . -inum 12345 -exec rm -i {} \;

share|improve this answer
    
Thank you - this is extremely helpful - I felt like there must be some kind of unequivocal system reference to the file but couldn't find it (quickly anyway). –  Colin Apr 3 '12 at 16:44
    
Depending on the version of find installed, you could also do find . -inum 12345 -delete –  William Jackson Apr 3 '12 at 21:01
    
For me, the more version-agnostic it is, the better. But good suggestion none-the-less. :) –  Garrett Apr 3 '12 at 21:10

use ANSI-C quoting: rm $'\r'

http://www.gnu.org/software/bash/manual/bashref.html#ANSI_002dC-Quoting

share|improve this answer
1  
+1 Single line; guaranteed to work. –  l0b0 May 15 '12 at 14:21

I would personally reach for Python:

>>> import os
>>> '\r' in os.listdir('.')
True
>>> os.unlink('\r')

But you can also do this from the shell if you understand escape characters.

$ ls $(printf '\r')
?
$ rm -vi $(printf '\r')
rm: remove regular empty file `\r'? y
removed `\r'
share|improve this answer
    
Brilliant - thanks! –  Colin Apr 3 '12 at 16:43

Single-character file names are unusual, and if you don't have any other such files in your directory, you can try this:

rm ?

I'm too lazy to learn or look up how to quote strange characters, so I've used variants of this a number of times when I was stuck with files with difficult names.

share|improve this answer
    
-1 This matches all files with a single character name - See "Pathname Expansion" in man bash. Try touch a b c d $'\r'; rm ? –  l0b0 May 15 '12 at 14:20
1  
@l0b0: Yes? As I wrote, single-character file names are unusual. It is fairly likely that there are no other such files in the directory, and in that case, this works. Otherwise "rm -i ?" can be used. –  Thomas Padron-McCarthy May 15 '12 at 20:11

Another quick way to remove a file called <carriage return> if you're using the Bash shell is:

$ rm <control-v><control-m>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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