Where art thou 'rename'
Rashkae
ubuntu at tigershaunt.com
Tue Aug 5 19:05:44 UTC 2008
Paul Johnson wrote:
> On Tue, Aug 5, 2008 at 1:41 PM, Romain Kang <romain at kzsu.stanford.edu> wrote:
>> Here's something posted to USENET ca. 1991. I've been carrying around
>> my own copy ever since:
>>
>> #! /usr/local/bin/perl
>> $op = shift;
>> for (@ARGV) {
>> $was = $_;
>> eval $op;
>> die $@ if $@;
>> rename($was,$_) unless $was eq $_;
>> }
>>
>> --
>
> I've been using this same scritp since 1995. It is from the Unix
> Powertools examples, I think. Anyway, my version has some usage
> examples at the top. I don't think people could figure it out without
> them. If you know perl or sed s/before/after/ this will be familiar
> to you.
> ###########################
>
> #!/usr/bin/perl
> #
> # rename script examples from lwall:
> # rename 's/\.orig$//' *.orig
> # rename 'y/A-Z/a-z/ unless /^Make/' *
> # rename '$_ .= ".bad"' *.f
> # rename 'print "$_: "; s/foo/bar/ if <stdin> =~ /^y/i' *
>
> $op = shift;
> for (@ARGV) {
> $was = $_;
> eval $op;
> die $@ if $@;
> rename($was,$_) unless $was eq $_;
> }
>
>
> ##########################
>
> Here are some examples I regularly do after downloading things
>
> ## replace spaces with _ in all file names ending in mp3
>
> rename s/\ /_/g *.mp3
>
> (recall the g means "for all instances". Without it, it only does first one).
>
> ## Change " - " to "-"
>
> rename s/\ - \ /-/ g *
>
> ## THis accepts regular expressions, so you can use ^ and $ in a handy way.
>
> ### Insert "My" at beginning of all file names
>
> rename s/^/My/ *
>
> ### Add "-orig" to end of all file names
>
> rename s/$/-orig/ *
>
> Anything you can do with Perl/sed and regex
>
>
>
Ok, I've finished answering my own question.
the program you describe is actually already implemented and installed.
It's called prename.
In Ubuntu, rename is an alt link that points to prename (ie, you don't
need your own script, it's already included, and the new version. Also,
the new prename doesn't overwrite existing files unless you use the -f
option)
The rename from util-linux I'm familiar with is in a binary named
reanme.ul Fair enough. Now I just need to figure out the proper way of
changing an alternative in Ubuntu. But that's low priority for me atm.
More information about the ubuntu-users
mailing list