sontek ( John M. Anderson )

October 10, 2007

Moving a file with a hyphen in it in Linux

Filed under: Linux — Tags: , — sontek @ 6:46 pm

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

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • description
  • Pownce
  • Slashdot
  • StumbleUpon
  • TwitThis

1 Comment »

  1. 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

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress