How do I delete a file whose name begins with "-" (hyphen a.k.a. dash or minus)?
Use "--" to make rm stop parsing command line options, like this:
rm -- --help
Or you can do
rm ./--help
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.