Fixing Strange and Peculiar Filenames in Linux
Strange and Peculiar Files Lurking
![]() |
rm -filewill not work. rm will treat this as indicating the use of the four options -f, -i, -l, and -e, and will die on -l, which isn't a valid option.
You might try using a shell escape:
rm \-fileHowever, if you think about what this actually does, it still won't work. The shell will see the escape, remove it, and pass plain -file into rm; so you run straight into the same problem. What you need is an escape sequence for rm itself, not for the shell.
There are two ways around this. The first one is to use --, which is used by many commands to indicate the end of the options. If you'd created a directory called -test and wanted to remove that directory and everything in it, this command line would work:
rm -rf -- -testThe -rf sets actual options; the -- signals that we're done with options, and that everything after this should be treated as something to be passed in to the command. In this case, that's the name of the directory to get rid of.
Test it out like this:
mkdir -- -test ls -l -- -test rm -rf -- -test
The other option is to specify the directory of the file. To remove the file -file in your current directory, use:
rm ./-fileThis will work with other commands as well. To test it out, try:
touch ./-file ls -l ./-file rm ./-fileNow, when you discover strange and peculiar files lurking in your directories, you can clear them up without any difficulty.
Juliet Kemp has been messing around with Linux systems, for financial reward and otherwise, for about a decade. She is also the author of "Linux System Administration Recipes: A Problem-Solution Approach" (Apress, 2009).
Article courtesy of Serverwatch.

Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.