From man rename, 'expression' seems to be (sort-of anyway) a 'mini-regex',
so it can't handle ./whatever (tho the 3rd arg, the filenames, can be ./stuff)
Those 2 expression replacement operate on just the
name, not shell directory syntax!
Like sed s/expression/replacement/
rename -v -- - _ -
worked for me, and renamed my `mkdir -- -` to a dir named underscore
The -- is needed by getargs/getopts, to stop 'switch processing'.
So, to 'null-out' the first dash/hyphen, try: rename -v -- - '' <normal shell filename pattern>
First check: ls -d -- <that patttern, like -myODDfileORdirName>
errors&all, but this shows 'proof' (on Slackware
)
Code:
login as: user
user@127.0.0.1's password:
Last login: Wed Mar 1 09:15:15 2017
Linux 4.4.14.
user@darkstar:~$ ls
PACKAGES.TXT myjunk z zfind zloc
user@darkstar:~$ mkdir -- -mydir; touch -myfile1 my-file2 myfile3- myfile4--
touch: invalid option -- 'y' EDITNOTE: needed -- so -my... NOT switches!
Try 'touch --help' for more information.
user@darkstar:~$ touch -- -myfile1 my-file2 myfile3- myfile4--
user@darkstar:~$ ls
-mydir/ PACKAGES.TXT myfile3- myjunk zfind
-myfile1 my-file2 myfile4-- z zloc
user@darkstar:~$ rename -- -v - '' *my*
user@darkstar:~$ ls #ooops, -- stopped the -v AND made -v THE expr!
-mydir/ PACKAGES.TXT myfile3- myjunk zfind
-myfile1 my-file2 myfile4-- z zloc
user@darkstar:~$ rename -v -- - '' *my*
`-mydir' -> `mydir'
`-myfile1' -> `myfile1'
`my-file2' -> `myfile2'
`myfile3-' -> `myfile3'
`myfile4--' -> `myfile4-'
user@darkstar:~$ ls
PACKAGES.TXT myfile1 myfile3 myjunk zfind
mydir/ myfile2 myfile4- z zloc
user@darkstar:~$
Hmmm.../ooops: the regex 'magic' seems to be
more than I thought:
Code:
user@darkstar:~$ rm myf*; rmdir mydir
user@darkstar:~$ mkdir -- -mydir; touch -- -myfile1 my-file2 myfile3- myfile4--
user@darkstar:~$ rename -v -- './-' '' ./*my*
`./-mydir' -> `mydir'
`./-myfile1' -> `myfile1'
user@darkstar:~$
Ok, overSolved
Then there's always util-linux/
rename.c