--- Eduardo Sanz Garcia <[EMAIL PROTECTED]> wrote:
> Does anyone know how to rename a batch of files?
> 
> Situation, I have a bunch of pictures:
> 1503.jpg
> 1504.jpg
> 1505.jpg
> etc...
> 
> I want to rename all of them at once to, for example:
> 1.jpg
> 2.jpg
> 3.jpg
> 
> Is there any command to do this?
> Thank you in advance.


I ran across a general-purpose file renaming script a few years back.
I keep it on all of my systems as /usr/local/bin/plrename, and it's
included below.

I usually use it with regular expressions or character translations.
The one I use most often is

  plrename "y/A-Z/a-z/" *

which, of course, changes all filenames to lowercase.

For what you describe, this should work:

  plrename '{my $old = $_; $old =~ s/.txt//; my $new = $old - 1502;
s/$old/$new/;}' *



Here's the script:

#!/usr/bin/perl
# rename -- Larry's Filename Fixer

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



--------------------
BYU Unix Users Group 
http://uug.byu.edu/ 

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG. 
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to