This is a script for renaming files with a regexp.
I found this on the 'net. I think the original source was the Perl
Cookbook (or something like that). It is trivial to change it so that
it copies instead of renaming.
rename
From pbier Fri Feb 16 16:15:34 +1300 2007 From: pbier Date: Fri, 16 Feb 2007 16:15:34 +1300 Subject: Message-ID: <20070216161534+1300@www.cmiss.org> This script did not work for me so I grabbed the original from the perl cook book http://www.unix.org.ua/orelly/perl/cookbook/ch09_10.htm#!/usr/bin/perl
$op = shift or die "Usage: rename expr [files]\n";
chomp(@ARGV =) unless @ARGV;
for (@ARGV) {
$was = $_;
eval $op;
die $@ if $@;
rename($was, $_) unless $was eq $_;
}
# The first argument to the script should be a Perl expression that will be
# evaluated for every file named on the command line, or (if there are none)
# every file on the standard input stream, one per line. When the expression
# is evaluated, $_ (the default variable) will contain a file name. If
# evaluating the expression changes $_, the file will be renamed to the new
# value of $_.
#
# Examples:
#
# Change spaces to underscores:
# rename 's/ /_/g'
# or
# rename 'tr/ /_/'
#
# Change .foo extensions to .bar:
# rename 's/\.foo$/.bar/' *
#
# Change .foo to .bar in an entire directory tree:
# find . -type f | rename 's/\.foo$/.bar/'
#
# Append a .bak extension to all .cc files:
# rename '$_ .= ".bak" if /\.cc$/' *