* Renaming multiple files
@ 2000-01-15 16:52 Andrei Zmievski
2000-01-15 17:11 ` Andre Pang
0 siblings, 1 reply; 11+ messages in thread
From: Andrei Zmievski @ 2000-01-15 16:52 UTC (permalink / raw)
To: zsh-users
How can I rename all files with one extension to another? For example,
all *.phtml files to *.php.
-Andrei
Some people try to achieve immortality through their work, others
through their children. I hope to achieve immortality by not dying.
-- Woody Allen
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Renaming multiple files
2000-01-15 16:52 Renaming multiple files Andrei Zmievski
@ 2000-01-15 17:11 ` Andre Pang
2000-01-15 17:11 ` Andrei Zmievski
2000-01-16 15:31 ` Thomas Köhler
0 siblings, 2 replies; 11+ messages in thread
From: Andre Pang @ 2000-01-15 17:11 UTC (permalink / raw)
To: zsh-users
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 :).
--
: Andre Pang <andrep@vjolnir.org> - Purruna Pty Ltd - ph# 0411.882299 :
: #ozone - http://www.vjolnir.org/ozone/ :
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Renaming multiple files
2000-01-15 17:11 ` Andre Pang
@ 2000-01-15 17:11 ` Andrei Zmievski
2000-01-16 15:31 ` Thomas Köhler
1 sibling, 0 replies; 11+ messages in thread
From: Andrei Zmievski @ 2000-01-15 17:11 UTC (permalink / raw)
To: zsh-users
On Sun, 16 Jan 2000, Andre Pang wrote:
> 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 :).
That's what I needed. :)
-Andrei
The Heineken Uncertainty Principle:
You can never be sure how many beers you had last night.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Renaming multiple files
2000-01-15 17:11 ` Andre Pang
2000-01-15 17:11 ` Andrei Zmievski
@ 2000-01-16 15:31 ` Thomas Köhler
2000-01-18 15:40 ` Andy Spiegl
1 sibling, 1 reply; 11+ messages in thread
From: Thomas Köhler @ 2000-01-16 15:31 UTC (permalink / raw)
To: zsh-users
On Sat, Jan 15, 2000 at 06:07:47PM +0100,
Andre Pang <andrep-ml@vjolnir.org> 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@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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Renaming multiple files
2000-01-16 15:31 ` Thomas Köhler
@ 2000-01-18 15:40 ` Andy Spiegl
2000-01-18 15:41 ` Andrei Zmievski
2000-01-18 16:41 ` Renaming multiple files Thomas Köhler
0 siblings, 2 replies; 11+ messages in thread
From: Andy Spiegl @ 2000-01-18 15:40 UTC (permalink / raw)
To: zsh-users
> for i in *.phtml ; do mv $i ${i:r}.php ; done
Nifty. But do you guys know mmv?
It's as easy as this:
mmv '*.phtml' '#1.php'
> Well, works with zsh - and is of course shorter, doesn't need basename
> etc... :-)
dito. :-)
> 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
eule:~/tmp>time mmv '*.phtml' '#1.php'
0,03s user 0,46s system 100% cpu 0,487 total
What is 3,22 divided by 0,03? :-)
Bye,
Andy.
--
E-Mail: Andy@spiegl.de URL: http://andy.spiegl.de
PGP/GPG: see headers
o _ _ _
--------- __o __o /\_ _ \\o (_)\__/o (_)
------- _`\<,_ _`\<,_ _>(_) (_)/<_ \_| \ _|/' \/
------ (_)/ (_) (_)/ (_) (_) (_) (_) (_)' _\o_
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Harrisberger's Fourth Law of the Lab:
Experience is directly proportional to
the amount of equipment ruined.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Renaming multiple files
2000-01-18 15:40 ` Andy Spiegl
@ 2000-01-18 15:41 ` Andrei Zmievski
2000-01-18 16:39 ` Renaming multiple files (OT) Andy Spiegl
2000-01-18 16:41 ` Renaming multiple files Thomas Köhler
1 sibling, 1 reply; 11+ messages in thread
From: Andrei Zmievski @ 2000-01-18 15:41 UTC (permalink / raw)
To: zsh-users
On Tue, 18 Jan 2000, Andy Spiegl wrote:
> > for i in *.phtml ; do mv $i ${i:r}.php ; done
> Nifty. But do you guys know mmv?
> It's as easy as this:
> mmv '*.phtml' '#1.php'
What is mmv?
-Andrei
Any sufficiently advanced bug is
indistinguishable from a feature.
-- Rich Kulawiec
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Renaming multiple files (OT)
2000-01-18 15:41 ` Andrei Zmievski
@ 2000-01-18 16:39 ` Andy Spiegl
0 siblings, 0 replies; 11+ messages in thread
From: Andy Spiegl @ 2000-01-18 16:39 UTC (permalink / raw)
To: zsh-users
[Sorry, a little off topic]
> What is mmv?
It's a free tool from Usenet and can be called as
mmv, mcp, mad or mln
I installed it as a Debian Package. You can get it (and the source) from
here: http://www.debian.org/Packages/unstable/utils/mmv.html
And here's the README, or better Copyright:
This is the Debian GNU/Linux prepackaged version of mmv.
This package was put together by Michael Meskes <meskes@debian.org>,
from sources obtained from USENET.
Copyright (c) 1989 Vladimir Lanin
Mmv is freeware. That means that the entire package of software and
documentation is copyrighted, and may not be distributed with any
modifications or for any charge (without the author's explicit written
permission). Other than that, it may be used and distributed freely.
Vladimir Lanin
330 Wadsworth Ave, Apt 6F
New York, NY 10040
lanin@csd2.nyu.edu
...!cmcl2!csd2!lanin
However, Vladimir told me:
Michael,
This message is to serve as an announcement that I am changing the
copyright of mmv to GPL.
If this message is in any way insufficient to do so, please tell me what
I have to do. Please keep in mind that I do not have in hand either the
full GPL text or the source code of the last mmv release (oops).
If there is any other way that I can help out, please tell me.
Thanks,
Vladimir Lanin
vlad@brm.com
Thanks to Joost for getting into touch with him.
-------------
Hope that helps,
Andy.
--
E-Mail: Andy@spiegl.de URL: http://andy.spiegl.de
PGP/GPG: see headers
o _ _ _
--------- __o __o /\_ _ \\o (_)\__/o (_)
------- _`\<,_ _`\<,_ _>(_) (_)/<_ \_| \ _|/' \/
------ (_)/ (_) (_)/ (_) (_) (_) (_) (_)' _\o_
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I've learned....
that the less time I have to work with, the more things I get done.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Renaming multiple files
2000-01-18 15:40 ` Andy Spiegl
2000-01-18 15:41 ` Andrei Zmievski
@ 2000-01-18 16:41 ` Thomas Köhler
2000-01-18 17:18 ` Andy Spiegl
2000-01-18 20:00 ` Peter Stephenson
1 sibling, 2 replies; 11+ messages in thread
From: Thomas Köhler @ 2000-01-18 16:41 UTC (permalink / raw)
To: zsh-users
On Tue, Jan 18, 2000 at 04:41:10PM +0100,
Andy Spiegl <zsh.Andy@spiegl.de> wrote:
>
> > for i in *.phtml ; do mv $i ${i:r}.php ; done
> Nifty. But do you guys know mmv?
> It's as easy as this:
> mmv '*.phtml' '#1.php'
And, well, doesn't let zsh globbing work. Bad :-}
How do you do
for i in **/*.php(I) ; do mv $i ${i:r}.phtml ; done
with mmv?
[Of course mmv is faster as it only spawns one process instead of many]
[Let's try again with other means...
553 jean-luc@picard (ttypts/12) ~/test/zsh> zmodload files
554 jean-luc@picard (ttypts/12) ~/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 )
0,09s user 0,61s system 94% cpu 0,739 total
We're in business again :-)]
> Bye,
> Andy.
CU,
Thomas
--
Thomas Köhler 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Renaming multiple files
2000-01-18 16:41 ` Renaming multiple files Thomas Köhler
@ 2000-01-18 17:18 ` Andy Spiegl
2000-01-18 17:38 ` Zefram
2000-01-18 20:00 ` Peter Stephenson
1 sibling, 1 reply; 11+ messages in thread
From: Andy Spiegl @ 2000-01-18 17:18 UTC (permalink / raw)
To: zsh-users
> How do you do
> for i in **/*.php(I) ; do mv $i ${i:r}.phtml ; done
> with mmv?
I'm not sure (haven't looked at the man page for a long time), but I
suppose you can't do it. Anyway: zsh is always better. :-)
> 553 jean-luc@picard (ttypts/12) ~/test/zsh> zmodload files
What does that command mean?
> 554 jean-luc@picard (ttypts/12) ~/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 )
> 0,09s user 0,61s system 94% cpu 0,739 total
Wow, this one command really speeds it up that much.
Bye,
Andy.
--
E-Mail: Andy@spiegl.de URL: http://andy.spiegl.de
PGP/GPG: see headers
o _ _ _
--------- __o __o /\_ _ \\o (_)\__/o (_)
------- _`\<,_ _`\<,_ _>(_) (_)/<_ \_| \ _|/' \/
------ (_)/ (_) (_)/ (_) (_) (_) (_) (_)' _\o_
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
USER, n.: The word computer professionals use when they mean "idiot."
-- Dave Barry, "Claw Your Way to the Top"
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Renaming multiple files
2000-01-18 17:18 ` Andy Spiegl
@ 2000-01-18 17:38 ` Zefram
0 siblings, 0 replies; 11+ messages in thread
From: Zefram @ 2000-01-18 17:38 UTC (permalink / raw)
To: Andy Spiegl; +Cc: zsh-users
Andy Spiegl wrote:
>> 553 jean-luc@picard (ttypts/12) ~/test/zsh> zmodload files
>What does that command mean?
It loads the `files' module. Modules generally add new capabilities to
zsh; this module provides some new builtin commands, among them `mv'.
The result is that, in the loop, the zsh process actually calls rename(),
rather than forking off a new process to exec /bin/mv.
-zefram
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Renaming multiple files
2000-01-18 16:41 ` Renaming multiple files Thomas Köhler
2000-01-18 17:18 ` Andy Spiegl
@ 2000-01-18 20:00 ` Peter Stephenson
1 sibling, 0 replies; 11+ messages in thread
From: Peter Stephenson @ 2000-01-18 20:00 UTC (permalink / raw)
To: zsh-users
Thomas K hler wrote:
> On Tue, Jan 18, 2000 at 04:41:10PM +0100,
> Andy Spiegl <zsh.Andy@spiegl.de> wrote:
> >
> > > for i in *.phtml ; do mv $i ${i:r}.php ; done
> > Nifty. But do you guys know mmv?
> > It's as easy as this:
> > mmv '*.phtml' '#1.php'
>
> And, well, doesn't let zsh globbing work. Bad :-}
I wrote a function zmv that does; it would work like this:
zmv '(*).phtml' '$1.php'
(positional parameters match parentheses). The bad news is it only works
with the latest development version, not 3.1.6. However, I'll add it to
Functions/Misc from now on (it was posted to zsh-workers a few of months
ago), and it'll appear in future versions.
> How do you do
> for i in **/*.php(I) ; do mv $i ${i:r}.phtml ; done
> with mmv?
Actually, further bad news is that you can't do **/... with zmv yet, but
I expect that can be fixed. I'll have a look sometime.
--
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2000-01-18 19:58 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-15 16:52 Renaming multiple files Andrei Zmievski
2000-01-15 17:11 ` Andre Pang
2000-01-15 17:11 ` Andrei Zmievski
2000-01-16 15:31 ` Thomas Köhler
2000-01-18 15:40 ` Andy Spiegl
2000-01-18 15:41 ` Andrei Zmievski
2000-01-18 16:39 ` Renaming multiple files (OT) Andy Spiegl
2000-01-18 16:41 ` Renaming multiple files Thomas Köhler
2000-01-18 17:18 ` Andy Spiegl
2000-01-18 17:38 ` Zefram
2000-01-18 20:00 ` Peter Stephenson
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).