DelphiFAQ Home Search:

How to remove a file with special characters in its name (space, semicolon, backslash)


comments6 comments. Current rating: 5 stars (2 votes). Leave comments and/ or rate it.


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)?


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:
  1. putting the filename in quotes
  2. put a \ in front of each of the special characters
  3. 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.

# for files with ;
rm "file;name"

# to remove '-filename'
rm "./-filename";

Content-type: text/html


2006-12-26, 07:37:48
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.
2008-07-02, 09:02:14
anonymous from United States  
Worked perfectly. Thank you !!
2008-09-17, 02:04:10
anonymous from India  
Thanks. your suggestion with the './' worked perfectly..
2008-12-14, 20:40:26
anonymous from India  
thanks i know but i forgot to mention (quot's) ' ' 's
2009-05-14, 12:58:23
anonymous from United States  
Very useful info. Thank you very much.
2009-05-23, 00:56:06
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
-------------- a
nd I couldn't make it go away! but
rm ./--------------
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 !!!!!



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: