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'

4 Answers 4


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
  • 3
    This resolves the same problem for rename, too. (at least the version that works like rename [options] <expression> <replacement> <file>..., whichever one that is.) Oct 10, 2016 at 8:48
  • 1
    Damn, BSD / Mac OS X mv doesn't have this :( Jul 25, 2017 at 4:03

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
  • very nice workaround, this never occurred to me. And unlike the accepted answer, this will work on BSD / Mac OS X Jul 25, 2017 at 4:11
  • Thats a little more catchy than --. Oct 15, 2018 at 6:43

This trick works for me in times of desperation. YMMV

rename \- '' *

You have to escape the hyphen for rename to recognize it. Why rename doesn't respect single quotes or offer an override of some kind is beyond me.

This is the only method I've seen that reliably handles a leading hyphen using rename. I agree with the other posts on using mv, but if you can't use mv for any reason, this works.


You can use this:

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

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


after run code, your file name become:

  • 1
    The other approaches (the one by RedGrittyBrick, and gniourf_gniourf) are more likely to work with several other commands.
    – TOOGAM
    Dec 17, 2015 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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