Tuesday, September 26, 2023
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 13298  / 2 Years ago, sun, january 23, 2022, 1:35:40

I used Sound Juicer to rip a CD of audio for a language learning book so that I could listen to them on my Android. However, Sound Juicer seems to only have the option of numbering files without leading zeros. Like this:



track_1.mp3
track_10.mp3
track_11.mp3


This leads to some confused ordering on my music player. So, I want to add some zeros to the name, so that they're ordered properly, like this:



track_01.mp3
track_02.mp3
track_03.mp3


How do I accomplish this? I tried using GPRename, but while it has the ability to add numbers, it doesn't seem to have any options for adding leading zeros.



Is there a better program or something I can do at the command line?


More From » rename

 Answers
0

I'm assuming that you just need to rename the files 1-9, since those are the ones that need padding. There are multiple ways of doing this.



You can execute the below command:



for n in $(seq 9); do mv track_$n.mp3 track_0$n.mp3; done;


This will rename tracks track_1.mp3 - track_9.mp3 to track_01.mp3 - track_09.mp3.






To break it down, it looks like this:



for n in $(seq 9)
do
mv track_$n.mp3 track_0$n.mp3
done



  • for n in $(seq 9): for every number in the output of the command seq 9, which is a command that just lists numbers 1 to 9, do,

  • mv track_$n.mp3 track_0$n.mp3: this is the actual command that renames the files. It substitutes the value of n iterating through all numbers. So it does mv track_1.mp3 track_01.mp3, mv track_2.mp3 track_02.mp3, until that last number which is 9.


[#23948] Sunday, January 23, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
inaterested

Total Points: 500
Total Questions: 104
Total Answers: 92

Location: Virgin Islands (U.S.)
Member since Fri, May 7, 2021
2 Years ago
inaterested questions
Fri, Aug 12, 22, 21:24, 1 Year ago
Wed, Apr 27, 22, 17:14, 1 Year ago
Tue, Oct 26, 21, 20:41, 2 Years ago
;