Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Jan 2004 15:47:58 +0100 (CET)
From:      Cordula's Web <cpghost@cordula.ws>
To:        a.kotsopoulos@tue.nl
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: "rename" shell command
Message-ID:  <20040126144758.56F0740824@fw.farid-hajji.net>
In-Reply-To: <4014F3FB.1030204@tue.nl> (message from Andrew Kotsopoulos on Mon, 26 Jan 2004 12:03:23 %2B0100)
References:  <4014F3FB.1030204@tue.nl>

next in thread | previous in thread | raw e-mail | index | archive | help
> I'm looking for the "rename" shell command for the macosx version of 
> bsd.  In redhat and possibly other linux distributions the command 
> renames files and supports wildcards and multiple file conversions, as 
> you most likely know.  To be more precise here is the man page:

Here's a script in perl. Use like this:

  ### Append .bak to all *.c files
  $ rename '$_ .= ".bak"' *.c

  ### Remove .bak from all *.c.bak files
  $ rename 's/\.bak$//' *.c.bak

  ### Convert to lowercase, but not for Makefile
  $ rename 'tr/A-Z/a-z/ unless /^Makefile/' *

#!/usr/bin/perl -w
# rename -- Larry's filename fixer

$op = shift or die "Usage: rename expr [files]\n";
chomp(@ARGV = <STDIN>) unless @ARGV;
for (@ARGV) {
    $was = $_;
    eval $op;
    die $@ if $@;
    rename($was,$_) unless $was eq $_;
}    

-- 
Cordula's Web. http://www.cordula.ws/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040126144758.56F0740824>