As it has already been suggested I've always used the syntax
rm -rf -- filename
when I had to remove a file with a dash as prefix because the -- says to the command that it does not search for any other parameter but just file names.
Keeping it in mind, in order to protect my important folder by accidental file deletion I was used to create an empty file called simply -i which is normally put at the top of the file list when resolving the * search. So the command
rm -rf *
when excuted on my protected folder is exploded, dureing execution, in the command:
rm -rf -i filename1 filename2 .... (all the other files in the folder)
and the shell, instead of deleting everything immediately, stops asking for a confirmation (as the -i option requires).
rm
a file called-rf
from your system without remembering the exact syntax!rm
(in it'sargc
andargv
) Thus, both of those result in the array["rm", "-rf"]
being passed torm
, which does what you would expect.*
into a folder. Include one named-rf
as well and watch the fun ;-)mkdir './-rf '
(ls --classify, a common default in a shell alias, will append a /)