How to rename a long list of photo filenames?

Bill Jonas bill at billjonas.com
Wed Nov 9 07:35:33 MST 2005


On Tue, Nov 08, 2005 at 06:25:41PM -0700, Josef Lowder wrote:
> I've been making a shell script like this to rename them, 
> but even doing this in a text editor, editing one line at a time, 
> gets tedious: 
> 
> mv pict0001.jpg a001.jpg 
> mv pict0002.jpg a002.jpg 
> mv pict0003.jpg a003.jpg 

for file in pict*.jpg; do mv $file ${file//pict/a/}; done

> mv 02800001.jpg b001.jpg 
> mv 02800002.jpg b002.jpg 
> mv 02800003.jpg b003.jpg 

for file in 028*.jpg; do mv $file ${file//02800/b/}; done

> mv 02810001.jpg c001.jpg 
> mv 02810002.jpg c002.jpg 
> mv 02810003.jpg c003.jpg 

for file in 0281*.jpg; do mv $file ${file//02810/c/}; done

The semantics are similar to sed's (and perl's) s/// command, except the
pattern is a shell-style glob and not a regex.  See the "Parameter
Expansion" section in bash(1) for more details on this and other bash
environment variable tricks.

-- 
Bill Jonas    *    bill at billjonas.com    *    http://www.billjonas.com/
"It's a dangerous business, Frodo, going out your front door.  You step
into the Road,  and if you don't keep your feet,  there  is  no knowing
where you might be swept off to."  --  Bilbo Baggins
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.plug.phoenix.az.us/pipermail/plug-discuss/attachments/20051109/730911e7/attachment.pgp


More information about the PLUG-discuss mailing list