A non-elegant, non-flexible way of doing this would be something like this:
for path in *.jpg # IMG_1067_CR2.jpg, MG_1068_CR2.jpg, etc.
do
mv "$path" "${index-0}.jpg"
let index+=1
done
unset index
A much better way should support leading zeros (for example for ffmpeg), avoid tainting the environment with dummy variables, have a dry-run option (like rename), and should not require specifying the extension twice. Is this supported by existing tools?
Alternatively, how can I make this solution work with leading zeros:
rename -n 's/IMG_([0-9]*)\.jpg/$1/; $_="IMG_".($_-1067).".jpg"' *.jpg
You can do:
which will render “0” as “0000” and “907” as “0907”.