Main image
13th January
2009
written by Nick Anderson

I was restoring some files from backup today and ran into a few files that had leading slashes. Whenever I see those kind of things I rename the files since they are a pain to work with in the shell.

If you find yourself at a shell and need to work with files that have a leading dash just use the relative path and include the dashed filename in quotes.

mv ./"-somefile.txt" ./somefile.txt
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • Slashdot
  • TwitThis

5 Comments

  1. arne Mac OS X Safari 3.2.1
    14/01/2009

    Couldn’t you also do:

    mv — -somefile.txt somefile.txt

  2. peje Debian Unknow
    14/01/2009

    Or, you can use a double dash to make mv, cp to stop interpreting options:

    mv — -somefile.txt somefile.txt

  3. NM Linux Firefox 3.0.5
    14/01/2009

    Or simply use “–” to signal the end of options. As in:

    mv — -somefile.txt somefile.txt

  4. Dan C Windows 2000 Internet Explorer 6.0
    14/01/2009

    You could double dash.

    Or backslash escape the offending character.

    mv \-somefile.txt somefile.txt

  5. Dan C Windows XP Firefox 3.0.5
    14/01/2009

    Oh no you can’t. Ignore that ;)

Leave a Reply

To submit your comment, click the image below where it asks you to... Clickcha - The One-click Captcha

BLOGROLL

ARCHIVE