[NTLUG:Discuss] rm doesn't recurse

Steve Baker sjbaker1 at airmail.net
Fri May 7 13:15:43 CDT 2004


Kenneth Loafman wrote:

> The method to avoid spawning thousands of rm's is to use find as:
> 
> find . -type d -exec rm *.zip \;
> 
> with the appropriate quoting, which I can never remember.

That *STILL* doesn't work - and it's really important that
you grok the reason why it doesn't.

Chant this mantra thrice daily:

   UNDER UNIX/LINUX, WILDCARDS ARE EXPANDED BY THE SHELL
   BEFORE THE UNDERLYING COMMAND IS RUN.

So - the '*.zip' is expanded by the shell BEFORE find is
even loaded into memory.   The shell has no idea that
this argument is going to be used when find is down in
some sub-directory.   So it'll expand ONLY those zip files
that happen to be in the current directory.

This is *SUCH* an important thing to understand.

Failure to understand that will cause you endless grief
in the future when commands either fail or wipe out
your system!

---------------------------- Steve Baker -------------------------
HomeEmail: <sjbaker1 at airmail.net>    WorkEmail: <sjbaker at link.com>
HomePage : http://www.sjbaker.org
Projects : http://plib.sf.net    http://tuxaqfh.sf.net
            http://tuxkart.sf.net http://prettypoly.sf.net
-----BEGIN GEEK CODE BLOCK-----
GCS d-- s:+ a+ C++++$ UL+++$ P--- L++++$ E--- W+++ N o+ K? w--- !O M-
V-- PS++ PE- Y-- PGP-- t+ 5 X R+++ tv b++ DI++ D G+ e++ h--(-) r+++ y++++
-----END GEEK CODE BLOCK-----



More information about the Discuss mailing list