June 12, 2007
Unix: How to Delete Files That Start with Special Characters
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
Came across this neat trick today. I find that if I don’t write about them somewhere, I forget and have to hunt around next time it happens. So why not here.
I found a file that was created accidentally that was named starting with hyphens, like –filename.
You cannot simply type rm –filename as the command line parser treats the filename as a command line switch. There are other characters that work the same way, as I discovered, like #, which gets created by some text editors as a backup file, e.g., #myfile#.
A simple way to delete these files is to find another way to access them so the special character isn’t the first character after the whitespace. This can be done by referencing them via their path location, or most simply by preceding the filename with ./ which is the current directory.
The files in the above examples can be deleted with the following commands:
$ rm ./--filename
$rm ./#myfile#


Add New Comment
Viewing 13 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks
(Trackback URL)