Delete File with Dash/Hyphen in Name Within Linux/Unix

If you have a file named “-file” without the quotes, you would typically delete it using:

rm -rf -file

Except that doesn’t work. My CentOS complained to me with the following message (though not all operating systems may supply this, so this is mainly for those whose OS does not supply this tip):

rm: invalid option -- 'l'
Try `rm ./-file' to remove the file `-file'.
Try `rm --help' for more information.

The suggested tip here works well. Simply running the following command should delete the “-file” file.

rm -rf ./-file

Keep in mind this limitation does not apply only to the rm command, but a large number of commands including touch and others. It is the most annoying for the rm command, since you are trying to remove the file. For these other commands, you would also have to prepend the file name with a ./ in order for this to work.