From owner-freebsd-questions@FreeBSD.ORG Tue Mar 23 05:38:37 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 436FF16A4CE for ; Tue, 23 Mar 2004 05:38:37 -0800 (PST) Received: from hkisrv08.tw.fi (host76-46.teleware.fi [193.65.76.46]) by mx1.FreeBSD.org (Postfix) with ESMTP id 99C2343D2F for ; Tue, 23 Mar 2004 05:38:36 -0800 (PST) (envelope-from Toni.Heinonen@teleware.fi) X-MIMEOLE: Produced By Microsoft Exchange V6.0.5762.3 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Date: Tue, 23 Mar 2004 15:39:34 +0200 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: fast way to rename files? Thread-Index: AcQQ2xcc/zteeD9nSPa8h0+r+9WKQAAADXSw From: "Toni Heinonen" To: , cc: *IPGroup Subject: RE: fast way to rename files? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Mar 2004 13:38:37 -0000 > 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