Linux Apache (6) Network (11) shell (12)
Exchange Links About this site Links to us 
|
How to remove a file with special characters in its name (space, semicolon, backslash)
6 comments. Current rating: (2 votes). Leave comments and/ or rate it.
Question: I have a file with a semicolon in its name and cannot delete it. How can I delete a file with strange characters in its name (space, semicolon, backslash)?
Answer: In Unix you can string commands together with semicolons, so Unix will interpret a semicolon in a filename as a separator. You can try the following:
- putting the filename in quotes
- put a \ in front of each of the special characters
- if the filename starts with a special character e.g. '-', put a ./ in front of it
Finally you can try using an FTP client, ftp into that directory and issue an MDELETE command (short: mde). It will offer to delete all files - say 'no' in all cases except for the chosen one. That way you do not have to specify the file name.
 | |  | | rm "file;name"
rm "./-filename";
| |  | |  |
Comments:
|
anonymous from United States
|
|
|
|
You also can use unix wild characters in this case:
rm -i file*
will remove any file that its name starts with 'file' while it does not delete without asking.
|
|
anonymous from United States
|
|
|
|
Worked perfectly. Thank you !!
|
|
anonymous from India
|
|
|
|
Thanks. your suggestion with the './' worked perfectly..
|
|
anonymous from India
|
|
|
|
thanks i know but i forgot to mention (quot's) ' ' 's
|
|
anonymous from United States
|
 |
|
|
Very useful info. Thank you very much.
|
|
anonymous
|
 |
|
THANK you! I had tried everything (I thought) single-quotes, double-quotes, back-tics, a back-tic and a forward-tic, back-slashes ... the file name was nd I couldn't make it go away! but worked BEAUTIFULLY ! Thank you thank you thank you! I did this on a production system by accident and was trying to get rid of it before anybody noticed, and I was frantic! Thannnnkk youuuuu !!!!!
|
|