What command do I need to use to remove a file called `-rf`?

Solution 1:

unlink -rf

Or

rm -- -rf

Solution 2:

Another option:

rm ./-rf

... asuming your current directory is the one where the file resides.

Solution 3:

Alternatively you can always edit the directory its in and remove the file that way.

vim .

and then just delete the line with the file on it (using D, dd won't work).

Solution 4:

A generic technique for deleting weird filenames is to use.

 ls -li

to find the inode number of file and then use.

find ./ -inum <number of file> -delete

No need to remember all the special cases.

Solution 5:

Even though I know about the "rm -- -filename" trick, generally when I somehow get a file with a leading - in its name that I want to remove I start a GUI file manager and do it from there, to eliminate the chance of mistakes.