4

I have so many images more than 100 in a folder such as:

apple.jpg
grapes.jpg
orange.jpg
....

I want to rename all of them at once with ascending order numbers such as:

1.jpg
2.jpg
3.jpg
....

How can I do it using Ubuntu 10.04? Is there any terminal command to do it.

3 Answers 3

6

I'm not sure how you want them numbered, but the following Perl script should do it (haven't tested it out, but should probably work):

#!/usr/bin/perl
@a=glob("*.jpg");
$n=1;
for(@a){
    rename $_,($n++).".jpg";
}
6

Try the following in terminal:

 find . -name '*.jpg'| awk 'BEGIN{ i=0 } { printf "mv %s %d.jpg\n", $0, i++ }'| bash
1

Pure bash solution (bash version of o_o's perl script):

n=1; for f in ./*.jpg; do mv "$f" $n.jpg; n=$((n+1)); done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .