This is a script I wrote and use all the time. It allows you to use a regex to rename files. For example, if you wanted to anything with extension .TXT to .txt, you would do
Code:
pmv 's/TXT$/txt$/' *.TXT
And here's the script, I call it pmv (perl mv). It's pretty much right out of Programming Perl with a little embellishment.
Code:
#!/usr/bin/perl
use warnings;
use strict;
my ($verbose, $test);
my $separator = " => ";
GetOptions (
"test|dryrun" => \$test,
"separator=s" => \$separator,
"verbose" => \$verbose,
) or die "$0: options error\n";
$verbose = 1 if $test;
my $op = shift or die "Usage: $0 REGEX file1 [ file2 ... ]\n";
for (@ARGV) {
my $was = $_;
eval $op;
die "Invalid regex" if $@;
unless ($was eq $_) {
if (not $test) {
rename $was, $_ or warn "Rename of $was failed";
}
print "$was$separator$_\n" if $verbose;
}
}