I've got bunch of files with ill-formed numbering:
prefix-#.ext | for files with number 1-9
prefix-##.ext | for files with number 10-99
prefix-###.ext | for files with number 100-999
Due to further processing I need all of their names to be in format: prefix-###.ext
. Is there any easy way to do that?
Best Answer
On Debian, Ubuntu and derivatives, you can use the
rename
Perl script:Some systems may have this command installed as
prename
orperl-rename
. Note that this is not therename
utility from the util-linux suite which does not provide an easy way to do this.In zsh, you can use
zmv
to rename and thel
parameter expansion flag to pad with zeroes.You can also do this with a plain shell loop. Shells don't have nice string manipulation constructs; one way to pad with zeroes is to add 1000 and strip off the leading
1
.Another way is to call the
printf
utility.