If by any chance your rename
command is not perl-rename, you can use this perl code:
foreach (<*.jpg>) { rename $_, sprintf("%03d.jpg", $1) if /^(\d+).jpg/; }
When we say foreach
we can refer to the files by $_
But you can install the propper perl-rename
with this commands
cpan
cpan1> install File::Rename
Another way of renaming these files easily is opening the folder with ranger file manager, select all files, run :bulkrename
and use this vim command:
:%s/^\d\+/\=printf("%03d", submatch(0))
I have also tried using ls + awk
ls -1 | awk -F. '{printf "%s%s%s%03d.%s\n", "mv ", $0, " ", $1, $2}'
Each string or number must be associated on the printf function, the result output will be something like this:
mv 9.jpg 009.jpg
To really perform the renaming with this you have to add | sh
at the end of it:
ls -1 | awk -F. '{printf "%s%s%s%03d.%s\n", "mv ", $0, " ", $1, $2}' | sh
ls -v
unix.stackexchange.com/questions/33909/…pyrenamer
.