Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

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";
}
share|improve this answer

Try the following in terminal:

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

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.