UNIX: Remove A File With A Name Starting With – (dash) Character

by on November 30, 2007 · 7 comments· LAST UPDATED December 2, 2013

in , ,

I am a new Unix shell user at my university shell server. Accidentally, I had created a file called -foo. Now, how do I remove a file with a name starting with '-' under UNIX-like or Linux operating system?

You can use standard UNIX/Linux rm command. All you have to do is instruct the rm command not to follow end of command line flags by passing double dash -- option before -foo file name.
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Estimated completion time1m

rm command syntax

Use rm command to remove files or directories as follows:
rm -- -foo
rm ./-foo
rm ./-filename

Alternatively, you can also use UNIX / Linux inode number to delete a file with strange names.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 7 comments… read them below or add one }

1 Rich November 30, 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.


2 Royce December 12, 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.


3 Jadu January 2, 2008 at 1:03 pm

$ rm — -file

this will also work.


4 Daevid Vincent April 17, 2009 at 6:14 pm

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”


5 iqbal January 5, 2012 at 2:08 pm

thanks man it help


6 irem February 10, 2012 at 4:16 am

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.


7 shailesh December 15, 2014 at 1:10 pm

i typed dash on linux terminal and it changed. now their is only $ sign but not its full [user_name@user]$
please tell me how to disable this dash


Leave a Comment

Tagged as: , , , , ,

Previous Faq:

Next Faq: