I have some files named as A1.txt A2.txt ... A11.txt A12.txt, etc. I want to rename them to A0001.txt A0002.txt ... A0011.txt etc. Am I doing it right?
for file in A*.txt
do
mv ${file} ${file/-#.txt-/-"%5d".txt}
done
|
I have some files named as A1.txt A2.txt ... A11.txt A12.txt, etc. I want to rename them to A0001.txt A0002.txt ... A0011.txt etc. Am I doing it right?
|
||||
|
Using Perl's rename utility:
Debian-like distributions, among others, have Perl's rename/prename installed by default. If your distribution does not, instructions for installing it can be found here (Hat tip to Steeldriver for improved version of the command.) ExampleConsider a directory with these files:
Now, let's run prename:
How it worksA single substitute command is used:
|
|||||||||||||
|
|
If you don't have the
|
|||||||||
|
"%5d". However, if you have GNU utilities on your system (which you probably do unless you are using BSD), check outman 1 printforinfo -f coreutils printf. That might do what you want. Alternately, try @John1024's idea. – thb 6 hours ago