質問

I've made a mistake somewhere when scraping (and automatically naming) images, and now in hunderds of folders they're called ...08.jpg, 09.jpg, 010.jpg, 11.jpg, 12.jpg... The problem is the 010.jpg, which got a leading zero.

Is there a terminal command to recursively (the image sets all have their own folder) rename all images called 010.jpg to 10.jpg?

役に立ちましたか?

解決

I'm no bash pro, but this should do it.

for i in /path/to/directory/*
do
    mv ${i}/010.jpg ${i}/10.jpg
done

他のヒント

This helps you find the file you're looking for in the target directory (/tmp/), and it will remove the leading zero from any file name, so it's a little more flexible than specifying to full "move to" name.

for i in $(find /tmp/ -name 010.jpg) ; { mv $i $(dirname $i)/$(basename $i | sed 's/^0//'); }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top