Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to rename a file with a hyphen at the beginning of its name and both this:

mv -example-file-name example-file-name

and this:

mv '-example-file-name' example-file-name

result in:

mv: invalid option -- 'e'
share|improve this question
    
Either use the relative path of the file (./tmp/-example), the full path (/home/a/tmp/-example) or tell mv that you're done giving options with -- and that what follows are file names. – Ярослав Рахматуллин Nov 25 '12 at 15:30
up vote 9 down vote accepted

Most GNU/Linux commands allow a -- option to indicate end of options so that subsequent - prefixed words are not treated as options.

  mv -- -example-file-name example-file-name

A small test

$ touch -- -example
$ ls -l -- *ample
-rw-r--r-- 1 rgb rgb 0 Nov 25 09:57 -example
$ mv -- -example example
$
share|improve this answer

RedGrittyBrick's answer is very good. Another option is:

mv ./-example-file-name example-file-name

A small test:

$ touch ./-example
$ ls -l ./*ample
-rw-r--r-- 1 me me 0 Nov 25 16:02 ./-example
$ mv ./-example example
$ ls -l ./*ample
-rw-r--r-- 1 me me 0 Nov 25 16:02 ./example
share|improve this answer

You can use this:

rename -- "s/\-//g" *

that it can rename all file :) if your file name :

-ng--sh-ay-01[------------]-FLV

after run code, your file name become:

ngshay01[]FLV
share|improve this answer
1  
The other approaches (the one by RedGrittyBrick, and gniourf_gniourf) are more likely to work with several other commands. – TOOGAM Dec 17 '15 at 21:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.