How to remove files starting with double hyphen?

cb0 picture cb0 · Apr 1, 2009 · Viewed 15.6k times · Source

I have some files on my Unix machine that start with

 --

e.g. --testings.html

If I try to remove it I get the following error:

cb0$ rm --testings.html
rm: illegal option -- -
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file

I tried

rm "--testings.html" || rm '--testings.html' 

but nothing works.

How can I remove such files on terminal?

Answer

Steve Jessop picture Steve Jessop · Apr 1, 2009
rm -- --testings.html

The -- option tells rm to treat all further arguments as file names, not as options, even if they start with -.

This isn't particular to the rm command. The getopt function implements it, and many (all?) UNIX-style commands treat it the same way: -- terminates option processing, and anything after it is a regular argument.

http://www.gnu.org/software/hello/manual/libc/Using-Getopt.html#Using-Getopt