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