I have a folder with about 1700 files. They are all named like 1.txt
or 1497.txt
etc. I would like to rename all the files so that all the filenames are 4 digits long.
IE 23.txt
becomes 0023.txt
.
What is a shell script that will do this? Or a related question: How do I use grep to only match lines that contain \d.txt
(IE 1 digit, then a period, then the letters txt
)?
Here's what I have so far:
for a in [command i need help with]
do
mv $a 000$a
done
Basically, run that 3 times, with commands there to find 1 digit, 2 digit, and 3 digit filenames (with the number of initial zeros changed)