October 16, 2006
Just ran into an issue with a file named '-t6' on an AIX system. (No, I didn't put it there.)
After taking a few stabs at deleting it unsuccessfully, a quick google search showed the solution. I thought it was pretty cool so I thought I would share it:
How do you delete a file called "-xx"? You can of course use a graphical file manager and select the file graphically but how do you delete it with the rm command? rm will normally interpret the -xx as an option because it starts with a minus sign. There are two ways to avoid that:
- Make sure the file name does not start with a minus: For files this is always possible. You can e.g use the full absolute path to the file. (e.g rm /tmp/-xx assuming that the file -xx is in /tmp)
You can also write -xx as ./-xx :
rm ./-xx- Most unix commands accept a double minus (--) to indicate that this is the end of the options list.
rm -- -xx
will therefore tell rm that -xx is a file and not an option.



