How to remove a file with name starting with "-r" using cli [duplicate]

I have been creating odd-named files every once in a while, e.g.

$ls -rthl
$-rw-r--r--  1 shamil hep  290 Aug 13 11:58 -rf

And interestingly it is impossible to remove this file with

rm -f -rf

I know I need to escape the special symbols like "-", so the issue is clear. And I used to know the solution, but have since forgotten.

How do I properly delete it?

I have tried things like this

rm -f \-rf

but to no avail.


-- switch means: End of flags, everything after it is assumed to be a file name. So you can do:

rm -- -rf

Include the full path to the file also works:

rm /full/path/to/-rf

Actually, this is kind of hilarious but this command line can give you the answer :)

$man rm | cat | grep -B4 -A3 -- "rm --"

To remove a file whose name starts with a `-', for example `-foo', use 
one of these commands:

rm -- -foo
rm ./-foo

You can do

rm -rf ./-rf

This will make it so that -rf does not start with a -.


another way:

find -name "-rf" -exec rm {} \;