Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explaining the rm ./-rf "trick"

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?

like image 659
Chris Cooper Avatar asked Dec 17 '13 17:12

Chris Cooper


1 Answers

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.

like image 68
Donovan Avatar answered Sep 20 '22 23:09

Donovan