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.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop



![Linux Copy File Command [ cp Command Examples ]](http://s13.cyberciti.org/images/shared/rp/3/11.jpg)









{ 6 comments… read them below or add one }
The following will work as well.
rm — \-foo
Any unix utility that uses getopt will see the — as an end of options.
[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
$ rm — -file
this will also work.
I had a directory named “–help” on accident.
# rm — “–help”
rm: cannot remove `–help’: Is a directory
so you have to do it this way:
# rm -rf — “–help”
thanks man it help
my 4050n nerowtk printer doesn’t work with large images and certain pdf files in linux.. windows 7 it works flawlessly. I was impressed with Ubuntu’s printing , but it isn’t up to windows spec. It’s also a lot slower with my nerowtk printer.