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

Possible Duplicate:
Removing file with strange characters in filename in OS X

I have a folder that has a file who's name is Icons and ends with an additiona unprintable character. I can see the unprintable if I ls with -B option:

$ ls -B
$ Icon\015

if I use ls -b I get:

$ ls -b
$ Icon\r

I would like to delete file but I cannot find a way to type the unprintable character. If I do:

$ rm Icon\015

I get:

$ Icon\015: No such file or directory

If I do:

$ rm Icon\r

I get:

$ Icon\r: No such file or directory

I could just delete the whole folder, but I need a more generic way to do this since such files pop up on many users folders.

share|improve this question

marked as duplicate by Ƭᴇcʜιᴇ007, Synetech, Simon Sheehan, 8088, Renan Dec 26 '12 at 3:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

If there are no other files that start with Icon, try rm Icon*. Alternatively, type rm Icon and then press the <Tab> key (it would complete the filename, if there is only one file starting with Icon). – lupincho Dec 25 '12 at 13:02
@lupincho: The <Tab> key method does work, I actually get Icon^M this way. But I need something I can write into a shell script to automate the removal of such files. BTW: Typing Icon^M does not work.... – Periodic Maintenance Dec 25 '12 at 13:21
What happens if you try rm -i Icon*?, Also, are there other files staring with Icon in the same directory, but that you don't want to delete? – lupincho Dec 25 '12 at 14:14
@lupincho: rm -i Icon* will work, howeve it will require operator attention. There could be other files starting with Icon, so I cannot take chance that these otehr files will be erased. – Periodic Maintenance Dec 25 '12 at 14:30
These files contain a user-specified folder-icon. Why would you want to remove them in the first place? After all it's a users decision to give that folder a customized look. The name contains that character on purpose so that it is not easy to remove. – heiglandreas Dec 26 '12 at 6:38
up vote 3 down vote accepted

The shell will automatically transform every CR (\r) in a LF (\n) and execute the preceding command. However, you can use echo to produce a LF character. All of these should work:

rm $(echo -e "Icon\r")

rm $(echo -e "Icon\015")

echo -e "Icon\r" | xargs rm

echo -en "Icon\r" | xargs -0 rm

The last option should be fairly robust and deal with all possible strange characters.

share|improve this answer
The Icon is a file not directory, so your method work, replacing rmdir with rm. This method could work in shell scripts so it does the work for me.The -e option to echo does not appear in the man page, how did you come by it? In any case I will accept the answer - thanks! – Periodic Maintenance Dec 25 '12 at 16:42
Right, I misread the question's first sentence. men echo shows -e enable interpretation of backslash escapes. – Dennis Dec 25 '12 at 18:44

There are several ways to include non-printing characters in a command line. The simplest (bash-only) option is to use $ before a single-quoted string, which makes bash do escape substitution within the string. Note that it handles several kinds of escape sequences, so both of these would work:

rm $'Icon\r'
rm $'Icon\015'

Or, you can type Control-V before Control-M (aka return), which tells the shell "the next character I type should be included literally in the command":

rm Icon^V^M

(Note that the ^V isn't really part of the command, so it won't echo on the command line).

share|improve this answer
The $ method works as well as the echo -e method. It's a good solution - thanks. – Periodic Maintenance Dec 26 '12 at 8:23

For a one unprintable character you can use '?' as a wildcard for one character. So, abc?def?.zip would mean and also abc!

share|improve this answer

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