fast way to rename files?

Toni Heinonen Toni.Heinonen at teleware.fi
Tue Mar 23 05:38:37 PST 2004


> 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 at teleware.fi / www.teleware.fi


More information about the freebsd-questions mailing list