rm -blah
Being the resident Unix nerd in my group, about once a year, someone asks me “How do I remove file named -blah”. The problem arises because the hyphen character is the option delimiter for the shell commands. So, typing “rm -blah” or even “rm \-blah” usually results in “rm: Not a recognized flag: b” on most systems. The solution to this problem is so amazingly stupid that the asker usually walks away with his or her pride obliterated. The answer? rm ./-blah. Ivo told me about the alternate solution of using rm — -blah to do it. I like the ./ way better though because it’s so obvious once you know it. I think Jerome might know a better way though.
Trackbacks
Use this link to trackback from your own site.







Nope, i never got that problem before…how were they able to create such file other than a mv from blah to -blah is unlikely.
I thought using double-quotes around the filename would work (it does for other strangely named files like #emacs_scratch_save#)
It seems rm ./ and rm — are the best solutions for this problem done by people paid more than us…well me at least.
using rm ./-blah is bad practice (from security standpoint of view), rm — “-blah” is better (also notice quotes around).
Why? Imagine that you have root cron job on multiuser system doing some kind of rm through home dirs.
some evil user could do “evil mkdir”, like:
mkdir -p “evil /etc/passwd”
it will make argument to rm like (if not using quotes): rm “evil” “/etc/passwd”. So, that will eventually delete /etc/passwd. Or even worse:
mkdir -p “evil -r /etc”
That will delete /etc/ (not using quotes and not using –).
In short, beware what you are doing with rm/mv/cp in your (cron/whatever) scripts as root!! “–” and quotes(“”) are must!!!
Also, if you don’t like command line, you can use mc (midnight commander) for deleting such files.