I have a set of file as follow :
- oldname_1.txt
- oldname_1.pdf
- oldname_1.bak
etc.. with a different extension for each, I need to rename "oldname" by "newname" so I tried :
rename -v 's/\oldname_*.*$/\newname_*.*/’ oldname_*.*
but that doesn't work..
Any suggestion ?
First, you should really specify what "doesn't work" actually means. Does it do nothing? Does it rename them incorrectly? Does it deliver electrical pulses to certain private parts of your anatomy? :-)
In any case, I'd start with:
There's no need to include the wildcard stuff in the actual expression, especially since it means something different to what you think (
xyz_*
meansxyz
followed by zero or more_
characters, it does not meanxyz_
followed by anything, and.*
is just asking for trouble since that means zero or more of any character).The filtering of the filenames is done by the final argument. Since you know that only files matching that argument will be renamed, you can just tailor your regular expression to change the first bit.
In addition, make sure you have the right
rename
. There's a differentrename
available to Linux that has a different syntax:In those systems, the regex variant is often called
prename
.Lastly, and forgive what may be a silly question, are you sure that the files are of the name you expect them to be? A simple
ls -al oldname*
should show this.As an aside, this works fine under my Debian box:
One way to rename your files: