Unix tip of the day

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:

  1. WordPress quick tip for multi-author blogs
  2. Ubuntu vs SUSE
  3. AdSense tip: randomizing ads
  4. Unix and Windows admins
  5. IPsec woes

3 Responses to “Unix tip of the day”

  1. Dehumanizer says:

    Oops, didn’t try that one… I guess I need more sleep. It is the end of the day… and a Friday… :)

  2. James says:

    What about ‘rm ?file’ ?


Creative Commons Attribution-NonCommercial-NoDerivs 2.5 Portugal
This work by Pedro Timóteo is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 2.5 Portugal.