Tips & How-To's

Removing file named -rf in Unix

I did something crazy at some point that created a file called “-rf” on my filesystem. Now I can’t figure out how to delete it.

I’ve tried:

rm "-rf"
rm \-rf

But these just exit immediately. Arrgh!

Anyone know how to remove this file? Preferably without accidentally cleaning out my whole folder.

heh. What’re the odds, eh?

via Removing “-rf” file in Unix – Super User.


  1. Pingback: Sathya
  2. LOL, that was fun! I created a file with the name ‘-rf’ and tried to delete it in all possible ways, but i couldn’t! I was _this_ close to use python for this, bu instead i read the man page! I thought this was a bug, but turns not!

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

    So … rm -- -rf
    Now it’s gone :)

  3. Just in case, if you weren’t aware, — on itself tells that there are no more options to follow and process whatever follows as arguments (startx uses this trick to pass arguments to xserver it calls).

Leave a Reply

Your email address will not be published. Required fields are marked *