Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
rename(1)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Bill Cosby
Guru
Guru


Joined: 22 Jan 2005
Posts: 430
Location: Aachen, Germany

PostPosted: Sat Aug 29, 2009 8:01 am    Post subject: rename(1) Reply with quote

Hi there,

I was wondering, why doesn't Gentoo use the fabulous rename(1) e.g. Ubuntu uses?
The default rename(1) is useless to begin with, then Gentoo has renamexm(?) which looks like a dirty hack, needs regexp as some option delivered , and doesn't even have a complete man page.

In Ubuntu I get a nice rename(1) that works like
Code:
% rename 's/pat1/pat2/' *.ext


Why doesn't Gentoo use such a nice tool? Or where can I actually find that Ubuntu tool and replace the existing, and would I run into heavy breakage then? Do some scripts rely on crappy rename?
_________________
The Creature from Jekyll Island.
Back to top
View user's profile Send private message
mikegpitt
Advocate
Advocate


Joined: 22 May 2004
Posts: 3221

PostPosted: Sat Aug 29, 2009 3:27 pm    Post subject: Reply with quote

The rename utility that comes with Gentoo is the standard rename binary. It looks like the rename tool you are talking about is actually part of perl: http://unixhelp.ed.ac.uk/CGI/man-cgi?rename

I'm not exactly sure where/how the perl one is distributed.
Back to top
View user's profile Send private message
Bill Cosby
Guru
Guru


Joined: 22 Jan 2005
Posts: 430
Location: Aachen, Germany

PostPosted: Sun Aug 30, 2009 1:35 pm    Post subject: Reply with quote

Thanks, I did some searches, but couldn't come up with anything useful, I report back if I have found anything.
_________________
The Creature from Jekyll Island.
Back to top
View user's profile Send private message
Bill Cosby
Guru
Guru


Joined: 22 Jan 2005
Posts: 430
Location: Aachen, Germany

PostPosted: Sun Aug 30, 2009 6:47 pm    Post subject: Reply with quote

That's the script, for anyone interested:

Code:
#!/usr/bin/perl -w
#
#  This script was developed by Robin Barker (Robin.Barker@npl.co.uk),
#  from Larry Wall's original script eg/rename from the perl source.
#
#  This script is free software; you can redistribute it and/or modify it
#  under the same terms as Perl itself.
#
# Larry(?)'s RCS header:
#  RCSfile: rename,v   Revision: 4.1   Date: 92/08/07 17:20:30
#
# $RCSfile: rename,v $$Revision: 1.5 $$Date: 1998/12/18 16:16:31 $
#
# $Log: rename,v $
# Revision 1.5  1998/12/18 16:16:31  rmb1
# moved to perl/source
# changed man documentation to POD
#
# Revision 1.4  1997/02/27  17:19:26  rmb1
# corrected usage string
#
# Revision 1.3  1997/02/27  16:39:07  rmb1
# added -v
#
# Revision 1.2  1997/02/27  16:15:40  rmb1
# *** empty log message ***
#
# Revision 1.1  1997/02/27  15:48:51  rmb1
# Initial revision
#

use strict;

use Getopt::Long;
Getopt::Long::Configure('bundling');

my ($verbose, $no_act, $force, $op);

die "Usage: rename [-v] [-n] [-f] perlexpr [filenames]\n"
    unless GetOptions(
   'v|verbose' => \$verbose,
   'n|no-act'  => \$no_act,
   'f|force'   => \$force,
    ) and $op = shift;

$verbose++ if $no_act;

if (!@ARGV) {
    print "reading filenames from STDIN\n" if $verbose;
    @ARGV = <STDIN>;
    chop(@ARGV);
}

for (@ARGV) {
    my $was = $_;
    eval $op;
    die $@ if $@;
    next if $was eq $_; # ignore quietly
    if (-e $_ and !$force)
    {
   warn  "$was not renamed: $_ already exists\n";
    }
    elsif ($no_act or rename $was, $_)
    {
   print "$was renamed as $_\n" if $verbose;
    }
    else
    {
   warn  "Can't rename $was $_: $!\n";
    }
}

__END__

=head1 NAME

rename - renames multiple files

=head1 SYNOPSIS

B<rename> S<[ B<-v> ]> S<[ B<-n> ]> S<[ B<-f> ]> I<perlexpr> S<[ I<files> ]>

=head1 DESCRIPTION

C<rename>
renames the filenames supplied according to the rule specified as the
first argument.
The I<perlexpr>
argument is a Perl expression which is expected to modify the C<$_>
string in Perl for at least some of the filenames specified.
If a given filename is not modified by the expression, it will not be
renamed.
If no filenames are given on the command line, filenames will be read
via standard input.

For example, to rename all files matching C<*.bak> to strip the extension,
you might say

   rename 's/\.bak$//' *.bak

To translate uppercase names to lower, you'd use

   rename 'y/A-Z/a-z/' *

=head1 OPTIONS

=over 8

=item B<-v>, B<--verbose>

Verbose: print names of files successfully renamed.

=item B<-n>, B<--no-act>

No Action: show what files would have been renamed.

=item B<-f>, B<--force>

Force: overwrite existing files.

=back

=head1 ENVIRONMENT

No environment variables are used.

=head1 AUTHOR

Larry Wall

=head1 SEE ALSO

mv(1), perl(1)

=head1 DIAGNOSTICS

If you give an invalid Perl expression you'll get a syntax error.

=head1 BUGS

The original C<rename> did not check for the existence of target filenames,
so had to be used with care.  I hope I've fixed that (Robin Barker).

=cut

_________________
The Creature from Jekyll Island.
Back to top
View user's profile Send private message
CurtE
Guru
Guru


Joined: 17 Apr 2004
Posts: 364
Location: Minneapolis, MN

PostPosted: Sun Aug 30, 2009 7:33 pm    Post subject: Reply with quote

I'm curious. Why don't you use the 'mv' command?

mv a.txt b.txt
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Sun Aug 30, 2009 8:01 pm    Post subject: Reply with quote

CurtE wrote:
I'm curious. Why don't you use the 'mv' command?

mv a.txt b.txt

When you want to rename several files at the same times, rename is handy, eg:
Code:
ls
foo_1 foo_2 foo_34

Code:
rename 'foo_' 'bar' foo*

Code:
ls
bar1 bar2 bar34

_________________
The End of the Internet!
Back to top
View user's profile Send private message
boeroboy
n00b
n00b


Joined: 28 Mar 2006
Posts: 8

PostPosted: Mon Sep 13, 2010 7:11 pm    Post subject: Reply with quote

Thank you for posting the script. I've been headaching over this for a while on both my Gentoo and my Redhat boxes. I'm surprised this hasn't taken place of the bin rename in portage. None of the how-to's out there mention the conflicting versions of rename.
Back to top
View user's profile Send private message
Corona688
Veteran
Veteran


Joined: 10 Jan 2004
Posts: 1204

PostPosted: Thu Sep 23, 2010 10:34 pm    Post subject: Reply with quote

I use the mmv tool for this.
Code:
mmv '*.jpe' '#1.jpg'

_________________
Petition for Better 64-bit ATI Drivers - Sign Here
http://www.petitiononline.com/atipet/petition.html
Back to top
View user's profile Send private message
fenugreek
n00b
n00b


Joined: 27 Apr 2011
Posts: 1

PostPosted: Wed Apr 27, 2011 4:22 pm    Post subject: Reply with quote

dev-perl/rename, in Portage since October
Back to top
View user's profile Send private message
tallgirl
n00b
n00b


Joined: 26 Apr 2011
Posts: 14

PostPosted: Thu Apr 28, 2011 12:40 pm    Post subject: Reply with quote

Corona688 wrote:
I use the mmv tool for this.
Code:
mmv '*.jpe' '#1.jpg'


mmv is the sweetness and it's been around for a very long time.
_________________
Big: AMD Phenom quad core, 3.2GHz, 8GB DDR3, 3TB Disk, Dual 1000BaseT NICs.
Little: AMD Geode, 400MHz, 256MB DDR, 16GB CF, 100BaseT NIC.

Seek balance in life.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum