Saturday 13 October 2018

linux - Can't rename a file the name of which starts with a hyphen


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'

Answer



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
$

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...