Domanda

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?

È stato utile?

Soluzione

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

Altri suggerimenti

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//'); }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top