I have a folder with about 1,700 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 four digits long.
I.e., 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
(i.e., one 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 three times, with commands there to find one digit, two digits, and three digit filenames (with the number of initial zeros changed).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…