Go monk

rename

· Larry Wall

Larry Wall’s bulk file renamer. The renaming rule is not an option or a pattern language; it is any Perl expression that edits $_, so rename 's/\.bak$//' *.bak and rename 'y/A-Z/a-z/' * both just work.

#!/usr/bin/perl
($op = shift) || die "Usage: rename perlexpr [filenames]\n";
if (!@ARGV) {
    @ARGV = <STDIN>;
    chop(@ARGV);
}
for (@ARGV) {
    $was = $_;
    eval $op;
    die $@ if $@;
    rename($was,$_) unless $was eq $_;
}

Source: eg/rename in the Perl distribution.