Moving a file with a hyphen in it in Linux
If you have a file that begins with a hyphen, like “-TODO-” in Linux, and you try to access it from the command line (by using vim, mv, cat, etc.), you’ll be greeted with the nice error:
sontek@inspidell:~> cat -TODO-
cat: invalid option — O
Try `cat –help’ for more information.
the reason for this is because its actually processing the filename as the commandline arguments -T -O -D -O -, so if you have a file that begins with a hyphen and you need to access it via the command line you need to tell bash not to process arguments, you can do this with the argument ‘–’, like:
sontek@inspidell:~> mv — -TODO- tasklist








Alternatively, just prefix the filename with a path, e.g. “vim ./-TODO-”. This is particularly handy for programs which don’t support the ‘–’ “escape” argument.
Comment by Jonathan Pryor — October 11, 2007 @ 5:45 am