This happened originally with an AIX box, but I’ve just tried it on Linux and it works the same. It’s not rocket science (but then again, which is rocket science, except actually working in rocketry?), but it can be useful.
A colleague had, by mistake, created a file beginning with a “-”, due to a badly placed redirect (“>”). And, now, the file was hard to delete, because the system assumed that I was giving parameters to the “rm” command.
rm -file didn’t work, of course.
rm "-file" … nope.
rm \-file … nah.
rm "\-file" … no way.
rm -i * , intending to say “yes” to that file and “no” to everything else… nope.
Of course, I could have moved all the other files somewhere else, then delete the directory. But that was a production system, and you know how that is.
A little googling gave me the answer: you can use “--” to say that there are no more parameters after that.
rm -- -file . Simple as that.
Related posts:





















Or:
rm ./-file
Oops, didn’t try that one… I guess I need more sleep. It is the end of the day… and a Friday…
What about ‘rm ?file’ ?