tags:

views:

57

answers:

3

So I have:

01.jpg 02.jpg 3.jpg 4.jpg 05.jpg

and want to make them all like below using a shell script or a command on linux

1.jpg 2.jpg 3.jpg 4.jpg 5.jpg

+2  A: 

If you have the command rename on your system,

rename "s/0(\\d+\\.jpg)/\$1/" *.jpg
Kinopiko
+1  A: 
for i in 0*.jpg; do
    mv $i ${i:1}
done
soulmerge
+1  A: 

To remove any number of zeros from the start and prevent collisions:

for old in 0*.jpg; do
    new=$(echo ${old} | sed 's/^00*//')
    if [[ ! -f ${new} ]] ;then
        mv ${old} ${new}
    else
        echo "${old} conflicts with ${new}"
    fi
done

Of course, rename is a better option if available. I'm just including this for completeness in case you're running on a UNIX box that doesn't have that tool.

paxdiablo