Explaining the rm ./-rf "trick"

bash, command-line, rm, unix

Solution

`rm ./-rf` and/or `rm -- -rf` would attempt to remove a file named, specifically, `-rf`

The only trick here is that you normally can't delete a file that starts with a "-" because the command will assume it's a command argument. By preceding the file with a full path, or using the `--` option (which means, end all options) the command will no longer assume it's an argument.

It should be noted that the `--` version of this trick may or may not work with all shell commands either, so it's best to use the first version.

Problem

This question states: It is amazing how many users don't know about the `rm ./-rf` or `rm -- -rf` tricks. I am afraid to try these, but curious as to what they do. They are also very difficult to search... Can someone enlighten me?

Original source

Related problems