bash - Rename files numerically in place, multiple folders -


i able rename files numerically, in place, in multiple folders. however, not result looking for. file structure looks follows:

pictures-     vacation-         img.001.jpg                                                             img.002.jpg                                                            img.003.jpg                                                         holidays-         img.004.jpg         img.005.jpg                                                             img.006.jpg                                                        fun-         img.007.jpg 

what i'd achieve is:

pictures-                                                                        vacation-         img.001.jpg         img.002.jpg         img.003.jpg     holidays-         img.001.jpg         img.002.jpg         img.003.jpg     fun-         img.001.jpg 

so far have come following:

a=1 in $vm/holiday/*;     new=$(printf "%03d.jpg" ${a})     mv ${i} $vm/holiday/${new}     let a=a+1 done 

how can achieve desired result without having separately run on every single directory within pictures folder?

take version , make iterate on folders well.

#!/bin/bash  dir in ~/code/stack/pictures/*;         [ -d "${dir}" ] || continue         i=1         img in "${dir}"/*.jpg;                 [ -e "${img}" ] || break                 new="$(printf "%03d.jpg" "${i}")"                 echo mv "${img}" "$(dirname "${img}")/${new}"                 ((i++))         done done 

change location of pictures folder , dryrun echo in place first. wanted...?


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -