rename multiple files alphabetical order in Ubuntu rename multiple files alphabetical order in Ubuntu unix unix

rename multiple files alphabetical order in Ubuntu


One way using only bash

a=({a..d}{a..z}{a..z}{a..z})x=0for i in *;do echo mv "${i}" "${a[$((x++))]}.${i##*.}";done

remove the echo if you are happy with the output.

or with perl

perl -e '$prefix="aaaa";map{rename "$_",$prefix++.".$1" if /.*\.(.*)/} <*>'


  • 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