Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Jan 2004 11:34:37 +0000
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        Andrew Kotsopoulos <a.kotsopoulos@tue.nl>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: "rename" shell command
Message-ID:  <20040126113437.GA19625@happy-idiot-talk.infracaninophile.co.uk>
In-Reply-To: <4014F3FB.1030204@tue.nl>
References:  <4014F3FB.1030204@tue.nl>

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

--9jxsPFA5p3P2qPhR
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...
E_O_USAGE
}		  =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!
#

	Cheers,

	Matthew

--=20
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFAFPtNdtESqEQa7a0RAt1HAJ4guajRRL17eaLvXl6a+4ns+nlFvACfVrc3
hXWlPSFkzUqyfyeY05pKTUo=
=jxzH
-----END PGP SIGNATURE-----

--9jxsPFA5p3P2qPhR--



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?20040126113437.GA19625>