Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

How do you remove a file whose filename begins with a dash (hyphen or minus) -? I'm ssh'd into a remote OSX server and I have this file in my directory:

tohru:~ $ ls -l
total 8
-rw-r--r--    1 me  staff  1352 Aug 18 14:33 --help

How in the world can I delete --help from a CLI? This issue is something that I come across in different forms on occasion, these files are easy to create, but hard to get rid of.

I have tried using backslash

rm \-\-help

I have tried quotes

rm "--help"

How do I prevent the minus (dash or hyphen) character to be interpreted as an option?

share|improve this question
Would be great if this question was renamed to "How to delete a file whose name starts with --". – Sandy Sep 2 '10 at 21:04
@Sandy Agreed; I normally dislike changing a question's meaning, but in this case the accepted answer is specific to this problem – Michael Mrozek Sep 2 '10 at 21:52
i find it a bit ironic that rm --help actually explains how to delete filenames beginning with a -. good question nevertheless. – lesmana Sep 3 '10 at 6:44
@lesmana irony indeed :D. I think there is a good lesson to be learned here (read the help - it may indeed be helpful). – jw013 Dec 26 '11 at 21:45
@jw013 Sometimes the help is easy for experienced users to understand, but overwhelming and confusing to newbs. – iconoclast Jun 13 '12 at 3:37

9 Answers 9

up vote 128 down vote accepted

Use "--" to make rm stop parsing command line options, like this:

rm -- --help
share|improve this answer
I knew it was something very simple like this... – Bryan Rehbein Sep 2 '10 at 19:37
Do all versions of the rm command support the -- argument? – Keith Thompson Dec 6 '11 at 7:18
@KeithThompson -- is a feature of most GNU tools, so it won't work on most non-GNU ("non-Linux") Unix'es (e.g. BSD variants or some embedded systems) – dtech Apr 6 '13 at 17:00
THANKS! That saved my day. And of course it works on BSD (OSX) and with other commands! – raskhadafi Dec 2 '13 at 8:46
@dtech, getopt() and -- predate GNU (SysIII, 1980) and are standard/POSIX. Standard utilities except for a few exceptions (like echo) understand --. YMMV for other commands if they don't use the getopt() API to parse options. – Stéphane Chazelas Jun 17 at 12:08

Or you can do

rm ./--help
share|improve this answer
Not that it matters but this seems the most "proper". – James M. Sep 6 '10 at 9:10
This is the one that I remember. Using "rm -- --help" is something I always have to look up. – user603 Sep 21 '10 at 4:12
This method always works even for commands that don't treat -- specially. – jw013 Dec 26 '11 at 21:47
And it also works to avoid special treatment by some commands for other types (beside options) of specially named arguments like the - of text utilities or cd, the foo=bar of awk... – Stéphane Chazelas Jun 17 at 10:31

The answers of Vegar Nilsen and edfuh are very good and the proper solutions to a problem like this.

I do want to add a general response to this question that allows you to delete any file with a difficult file name. First its inode number is obtained using ls -i or some form of stat and then the file is removed by searching for files in the current directory by inode number and executing the rm command on the file with a matching inode number

find . -inode <inode> -exec rm {}\;

Since inode numbers are unique in each file system you can remove any file using this; unicode or using escape characters. It is how ever very annoying to type out so I would recommend adding the line

TAB: menu-complete             # Tab: Cycles through the command
"\e[Z": menu-complete-backward # Shift-Tab: Cycles backwards

into your .inputrc file if you're using bash. This allows you to cycle through the list of possible completions (for further information).

share|improve this answer
This way has two problems: 1) do not use -exec rm when you can use -delete; 2) obtaining the inode and using that is needlessly overcomplicated when you can just use: find -name '--help' -delete – aculich Dec 6 '11 at 1:36
I don't think that will work. It traverses all the files in the current directory and all its subdirectories, and after all that it still invokes rm --help, which still won't remove the file. Just use rm ./--help (or rm -i *. – Keith Thompson Dec 6 '11 at 7:16
@KeithThompson find prefixes the command line argument path to all files, so it would run rm ./--help and rm ./sub/dirs/--help. To fix the second, one would have to add -maxdepth 1, but all of this is essentially applying @edfuh's solution in a more roundabout, convoluted way, and -delete is safer than -exec rm anyways. – jw013 Dec 26 '11 at 21:39
One more issue with this command is that there must be a space between {} and \;, otherwise it won't work. – Eugene S May 22 '12 at 14:08
inodes may be unique but there may be several directory entries with the same inode. Those are called hardlinks. And they're only unique per file system, so you'd need to use -xdev. That won't help you to run that ls -i --help. – Stéphane Chazelas Jun 17 at 12:16

Use find to do it:

find . -name '--help' -delete

And this is a good method because if you have more then a few files like this that you can delete you can get a preview list of the files by simply running find without the -delete option first, and then if the list of files look good just run it again with -delete.

In fact, you avoiding rm in favor of find (especially with preview first) is a good habit that will help you avoid mistakes with rm * that will inevitably bite you some day.

Note, though, that find will recurse through all your subdirectories, so you might want to run it with a subdirectory depth constraint like this:

find . -maxdepth 1 -name '--help' -delete

which limits the find to the current directory.

share|improve this answer
Portably, you need to give find a list of files/dirs to look into. So find . -name.... -delete and -maxdepth are not standard options either. – Stéphane Chazelas Jun 17 at 12:17

A brutal solution:

perl -e "unlink '--help' or die 'Could not unlink.';"

perl -e "rmdir '-d' or die 'Could not rmdir.';"
share|improve this answer

Linux Walkthrough of creating a file with dashes and spaces, then removing it.

BE CAREFUL! Don't accidentally run a rm -rf / or similar cascade delete command.

If your file you are trying to remove includes asterisks or slashes, do not accidentally pump a . or /* or * or some other wildcard which could cascade delete your operating system.

Create a file called "--yo yo"

eric@dev ~ $ touch -- "--yo yo"
eric@dev ~ $ ls
bin  --yo yo

First, find it with find:

eric@dev ~ $ find . -name "*--yo yo*"
./--yo yo

Make sure the find command ONLY finds the ONE file you want to delete:

Then pass the -delete option to find, to delete them:

eric@dev ~ $ find . -name "*--yo yo*" -delete
eric@dev ~ $ ls

Aaaannd it's gone.

share|improve this answer

Midnight Commander (mc) is the easiest, just point at it and hit F8 ;)

share|improve this answer
The OP wants a command line (CLI) solution. – Francesco Turco Sep 14 '12 at 13:11
Midnight Commander IS a CLI solution. Just use your package manger to install it. (It even works over ssh...) – daviewales Sep 20 '13 at 0:41
How is apt-get install mc || yum install mc; mc various arrow keys and F8 easier than rm ./--help? – Josh Dec 11 '14 at 16:33
@daviewales: Midnight Commander is started from the command line, and it runs in the terminal, but all keyboard actions within Midnight Commander are not from the CLI (Command Line Interface) - they are from Midnight Commander's Interface. - Typically, command line utilities can be run within a script (an exception is bash command line history) – Peter.O Aug 17 at 21:33

There are 2 methods i know

Use "--" to make rm stop parsing command line options, like this:

rm -- --help

or you can use / before any symbol you don't want to treat as command like

rm /-help

though these are repeated.. still wanted to help

share|improve this answer
If you duplicate others answers, at least do it right (rm ./--help). Linking the original answers ( and would also be a good gesture. – Javier Aug 17 at 21:21

If you want to rename the file,, (mv won't work), try this:

cat > <

before using the command:

rm --

You should be able to examine the original file's contents in

share|improve this answer
Making a copy of the file is not a very efficient solution for renaming it. – jw013 Dec 26 '11 at 21:42
You could use vidir; but that is probably just as (or even more) inefficient - and much more dangerous. – Stephen Menasian Dec 27 '11 at 0:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.