Recursion without -R
Chris Robertson
chris at mcc.pyrsyd.oz
Wed Aug 22 14:26:09 AEST 1990
In article <316 at dynasys.UUCP> jessea at dynasys.UUCP () writes:
>In article <13595 at ulysses.att.com>, swfc at ulysses.att.com (Shu-Wie F Chen) wrote the following:
>>In article <494 at llnl.LLNL.GOV>, rjshaw at ramius.ocf.llnl.gov (Robert Shaw)
>>writes:
>>|>What are some quick tricks for getting programs like chmod and chown to
>>|>descend into all subdirectories? Programs without a -R option, that is.
>>find . -print | xargs chown foo
>>Of course, this only works if you have xargs, which is from System V and
>>is also available on SunOS in their System V software installation option.
>
>Why not just use "find . -exec chown foo {} \;"
>Or if you have to do many different commands, use:
>
>for x in `find . -print`
>do
> chown foo $x
> chgrp foobar $x
> chmod 644 $x
>done
>
>This can be done from the command line and saves some time.
Using "xargs" is generally faster than using "-exec" with "find",
since "xargs" will stuff as many arguments as possible into a
single invocation of the program. Thus you might have several
hundred separate invocations of "chown" and "chmod" with a "-exec",
as opposed to 10 or 15 with "xargs". Since "find" is doing a
fork-and-exec for each "-exec" invocation, the time difference
can be noticeable on a big directory tree.
Incidentally, the "for" loop above could fail on a big directory tree,
as the length of the argument list could be too much for the shell
to handle. If the loop is put into a script, however, and run as
"find . -print | xargs myscript", the problem goes away.
--
"Down in the dumps? I TOLD you you'd | Chris Robertson
need two sets..." | chris at mcc.oz
More information about the Comp.unix.questions
mailing list