9

How can I handle (e.g. apply mv command) in a command shell the files with leading dash (-) in names? The command

mv -weirdfilename.zip normalfilename.zip 

naturally accepts - at the beginning of a filename as an argument.

Rahul
  • 13,589
astrsk
  • 91

1 Answers1

16

Two ways:

  • -- indicates end of command options, so everything follows that are treated as arguments:

    mv -- -weirdfilename.zip normalfilename.zip 
    
  • Use ./ to indicate a file name explicitly:

    mv ./-weirdfilename.zip normalfilename.zip 
    
heemayl
  • 56,300
  • 2
    It's worth noting that -- might not always work for just - as a file name since it might have special meaning (e.g. stdin/stdout) in some programs. – phk Aug 17 '16 at 12:54