Ubuntu – How to rename more than one files in ubuntu

command linefilesrename

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.

Best Answer

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";
}