UNIX: Remove a file with a name starting with - character
Q. Accidentally, I had created a file called -foo. Now how do I remove a file with a name starting with '-' under UNIX or Linux operating system?
A. Use standard UNIX rm command, as follows:
rm command
Use rm command to remove files or directories as follows
rm ./-foo
rm ./-filename
rm -- -foo
Alternatively, you can also use UNIX / Linux inode number to delete a file with strange names.
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Other Helpful FAQs:
- Linux or Unix find and remove files with one find command on fly
- Linux/UNIX: Rules for naming file and directory names
- Linux Rules for file names
- Howto: Linux command line utilities for removing blank lines from text files
- Exclude certain files when creating a tarball using tar command
Discussion on This FAQ
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: inode number, linux operating system, remove strange names file, rm command, rm filename, unix linux



November 30th, 2007 at 7:03 pm
The following will work as well.
rm — \-foo
Any unix utility that uses getopt will see the — as an end of options.
December 12th, 2007 at 10:23 pm
[self-promotion warning, but I do think that it's topical ...]
I wrote an article for Sys Admin a while back about deleting files with unusual characters in their filenames on many Unix-likes.
Litter Delenda Est: part one
Litter Delenda Est: part two
January 2nd, 2008 at 1:03 pm
$ rm — -file
this will also work.