From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5055 invoked from network); 16 Jan 2000 15:38:32 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 16 Jan 2000 15:38:32 -0000 Received: (qmail 2709 invoked by alias); 16 Jan 2000 15:38:05 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 2883 Received: (qmail 2700 invoked from network); 16 Jan 2000 15:38:01 -0000 Date: Sun, 16 Jan 2000 16:31:12 +0100 From: =?iso-8859-1?Q?Thomas_K=F6hler?= To: zsh-users@sunsite.auc.dk Subject: Re: Renaming multiple files Message-ID: <20000116163112.A29827@picard.franken.de> References: <20000115105248.E868@ispi.net> <20000116041103.A1818@bozar.ihug.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable User-Agent: Mutt/1.1i In-Reply-To: <20000116041103.A1818@bozar.ihug.com.au>; from andrep-ml@vjolnir.org on Sat, Jan 15, 2000 at 06:07:47PM +0100 X-Operating-System: Linux picard 2.2.14 X-Editor: VIM - Vi IMproved 5.6a BETA http://www.vim.org/ X-IRC: tirc-1.2; Nick: jeanluc X-URL: http://home.pages.de/~jeanluc/ On Sat, Jan 15, 2000 at 06:07:47PM +0100, Andre Pang wrote: >=20 > On Sat, Jan 15, 2000 at 10:52:48AM -0600, Andrei Zmievski wrote: >=20 > > How can I rename all files with one extension to another? For example, > > all *.phtml files to *.php. >=20 > My (fairly dumb) solution: >=20 > for i in *.phtml; do mv $i $(basename $i .phtml).php; done > > It does have the advantage of being fairly easy to remember and it'll work > on any shell. (Well, if you change $(...) to `...`, anyway.) >=20 > I'm sure somebody here can come up with an answer that'll win some > obsfucated "How to rename all files with one extension to another" zsh > content :). for i in *.phtml ; do mv $i ${i:r}.php ; done Well, works with zsh - and is of course shorter, doesn't need basename etc... :-) jean-luc@picard (ttypts/5) ~> which basename /bin/basename -> No extra process, this starts to get really funny if you rename a few thousand files at once :-) Here's a test: jean-luc@picard (ttypts/5) ~/test/zsh> for i in {1..1000} ; do touch $i.phtml ; done jean-luc@picard (ttypts/5) ~/test/zsh> time (for i in *.phtml; do mv $i $(basename $i .phtml).php; done) ( for i in *.phtml; do; mv $i $(basename $i .phtml).php; done ) 7,16s user 9,94s system 98% cpu 17,380 total jean-luc@picard (ttypts/5) ~/test/zsh> time (for i in *.php; do mv $i ${i:r}.phtml; done) =20 ( for i in *.php; do; mv $i ${i:r}.phtml; done ) 3,22s user 5,04s system 99% cpu 8,328 total Hey, that's more than twice as fast ;-) CU, Thomas --=20 Thomas K=F6hler Email: jean-luc@picard.franken.de | LCARS - Linux for <>< WWW: http://home.pages.de/~jeanluc/ | Computers on All IRC: jeanluc | Real Starships PGP public key: http://www.mayn.de/users/jean-luc/PGP-Public.asc