Re: [Hampshire] mmv & wildcard expansion in bash

Top Page

Reply to this message
Author: Simon Huggins
Date:  
To: hampshire
Subject: Re: [Hampshire] mmv & wildcard expansion in bash
On Mon, Jun 18, 2007 at 10:40:50AM +0100, john lewis wrote:
> I came across the mmv command whilst looking to see what
> http://debaday.debian.net/ had to offer and thought it would be
> useful for renaming a batch of images from my camera from
> p1010001.jpg through to p101015.jpg to something a little more useful
> like barbecue1.jpg through to barbecue15.jpg


> I thought this command would work
> mmv "*.jpg" "barbecue#1.jpg"


If you know perl then at least Debian and Ubuntu ship rename which is a
trivial perl script. You give it some perl and it magics the files
into the right place.

e.g.
rename 's/p1010*/barbecue/' *.jpg

It saves me having to know the syntax of another specific tool but also
saves me writing out the long hand:
for f in *.jpg; do mv $f `echo $f|sed -e 's/p1010*/barbecue/'`; done
(normally you'd stick an echo before the mv to see what it's about to do
and make sure you got the regexp right etc).

You can do it in pure bash too but I never remember the syntax for that
without looking :)

Simon.

--
"Ah, here we are - `How to Raise the Dead.'" - Bart Simpson