7
1
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.
2If 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 – 2012-12-25T13:02:31.573@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 – 2012-12-25T13:21:05.973
What happens if you try
rm -i Icon*
?, Also, are there other files staring withIcon
in the same directory, but that you don't want to delete? – lupincho – 2012-12-25T14:14:12.690@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 – 2012-12-25T14:30:43.813
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 – 2012-12-26T06:38:13.523
Did you try putting the name into single quotes?
rm 'Icon\r'
should do the trick. – heiglandreas – 2012-12-26T06:47:03.653Just single quotes will not do. You need the '$' as @Gordon Davisson mentions in an answer below. – Periodic Maintenance – 2012-12-26T10:42:24.343