How to remove a file with unprintable charaters in Mac OS X Terminal [duplicate]
Solution 1:
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.
Solution 2:
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).