"rename" shell command

Cordula's Web cpghost at cordula.ws
Mon Jan 26 06:48:40 PST 2004


> 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/



More information about the freebsd-questions mailing list