Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Mar 2004 15:39:34 +0200
From:      "Toni Heinonen" <Toni.Heinonen@teleware.fi>
To:        <zhangweiwu@realss.com>, <questions@freebsd.org>
Cc:        *IPGroup <IPGroup@teleware.fi>
Subject:   RE: fast way to rename files?
Message-ID:  <B36C365832C90E47A37F4FFCDDEFC46D8F412D@hkisrv08.tw.fi>

next in thread | raw e-mail | index | archive | help
> Say, I have photo_1.jpg, photo_2.jpg ... photo_500.jpg in a directory.
>=20
> Is there a fast way to rename these files to 001.jpg, 002.jpg=20
> ... 500.jpg?

for old in directory/photo*; do new=3D`echo $old | sed 's/photo_//g'`; =
mv -v $old $new; done

Would give you 1.jpg, 2.jpg...500.jpg. If you display those with Apache, =
try IndexOptions VersionSort which I think should display them in the =
correct order. If you really want 001, 002.. etc that's possible too, =
but harder:

for old in directory/photo*; do new=3D`echo $old | sed =
's/photo_//g;s/\.jpg//g' | xargs printf "%03d.jpg"`; mv -v $old $new; =
done

--=20
TONI HEINONEN
     TELEWARE OY
     +358 40 836 1815 / +358 (9) 3434 9110
     It?keskuksen Maamerkki
     00930 Helsinki, Finland
     toni@teleware.fi / www.teleware.fi



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?B36C365832C90E47A37F4FFCDDEFC46D8F412D>