Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Jan 2004 11:34:37 +0000
From:      Matthew Seaman <>
To:        Andrew Kotsopoulos <>
Subject:   Re: "rename" shell command
Message-ID:  <>
In-Reply-To: <>
References:  <>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help

Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Jan 26, 2004 at 12:03:23PM +0100, Andrew Kotsopoulos wrote:

> I'm looking for the "rename" shell command for the macosx version of=20
> bsd.  In redhat and possibly other linux distributions the command=20
> renames files and supports wildcards and multiple file conversions, as=20
> you most likely know.  To be more precise here is the man page:

Interesting.  Sounds like it would make a good port.  However, check
out the misc/mmv port -- it sounds like it has very similar
functionality to the rename command you've been using.

Anyhow, it's a pretty trivial script to write.  Here's a perl verion I
cooked up in a few minutes -- use with care as it has only had minimal
testing.  Note too that the 'from' expression is actually a perl
regular expression, rather than a literal match.

#!/usr/bin/perl -w

$0 =3D~ s@.*/@@;

if (@ARGV < 3) {
	die <<E_O_USAGE;
$0: Usage:
    $0 from to file...
}		  =20

$::from =3D shift @ARGV;
$::to   =3D shift @ARGV;

foreach my $file (@ARGV) {
	my $nfile;

	($nfile =3D $file) =3D~ s/$::from/$::to/;

	if ($nfile ne $file) {
		rename $file, $nfile
			or die "$0: Couldn't rename \"$file\" to \"$nfile\" -- $!\n";
# That's All Folks!



Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP:         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.2.4 (FreeBSD)



Want to link to this message? Use this URL: <>