Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!umich!samsung!munnari.oz.au!mel.dit.csiro.au!yarra!pta!mcc!chris From: chris@mcc.pyrsyd.oz (Chris Robertson) Newsgroups: comp.unix.questions Subject: Re: Recursion without -R Keywords: recursion Message-ID: <1990Aug22.042609.2006@mcc.pyrsyd.oz> Date: 22 Aug 90 04:26:09 GMT References: <494@llnl.LLNL.GOV> <13595@ulysses.att.com> <316@dynasys.UUCP> Reply-To: chris@mcc.UUCP (Chris Robertson) Organization: MCC Software Group Lines: 38 In article <316@dynasys.UUCP> jessea@dynasys.UUCP () writes: >In article <13595@ulysses.att.com>, swfc@ulysses.att.com (Shu-Wie F Chen) wrote the following: >>In article <494@llnl.LLNL.GOV>, rjshaw@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@mcc.oz