Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Renaming multiple files
- X-seq: zsh-users 2883
- From: Thomas Köhler <jean-luc@xxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxxxxxx
- Subject: Re: Renaming multiple files
- Date: Sun, 16 Jan 2000 16:31:12 +0100
- In-reply-to: <20000116041103.A1818@xxxxxxxxxxxxxxxxx>; from andrep-ml@xxxxxxxxxxx on Sat, Jan 15, 2000 at 06:07:47PM +0100
- Mailing-list: contact zsh-users-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <20000115105248.E868@xxxxxxxx> <20000116041103.A1818@xxxxxxxxxxxxxxxxx>
On Sat, Jan 15, 2000 at 06:07:47PM +0100,
Andre Pang <andrep-ml@xxxxxxxxxxx> wrote:
>
> On Sat, Jan 15, 2000 at 10:52:48AM -0600, Andrei Zmievski wrote:
>
> > How can I rename all files with one extension to another? For example,
> > all *.phtml files to *.php.
>
> My (fairly dumb) solution:
>
> 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.)
>
> 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)
( 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
--
Thomas Köhler Email: jean-luc@xxxxxxxxxxxxxxxxx | 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author