rename multiple files alphabetical order in Ubuntu
- First, you need to extract all the extensions.
- Then, foreach extension, you must rename all the files, and increment the name.
I've quickly done a Perl script to achieve that, because list support is easier than bash.
#!/usr/bin/env perluse strict;use warnings;my @files = <*>;my @extensions = map { my ($f) = m/\.(.*?)$/; $f; } @files;my @unique_ext;my %seen;foreach my $value (@extensions) { if (! $seen{$value}) { push @unique_ext, $value; $seen{$value} = 1; }}use Data::Dumper;foreach my $current (@unique_ext){ my $start = 'aaaaaa'; my @file_list = <*$current>; foreach my $file (@file_list) { rename $file, "$start.$current"; $start ++; }}
Still requires improvements, but current that version has renamed all the file (and the perl script as well... :)) in my directory:
$ lsLKG.JPG jlgaej.gif owutljff.JPG uoeoo.jpg$ perl rename.pl$ lsaaaaaa.JPG aaaaaa.gif aaaaaa.jpg aaaaaa.pl aaaaab.JPG