Doing more than one thing at once with find(1)
Conor P. Cahill
cpcahil at virtech.uucp
Sat Mar 24 00:11:31 AEST 1990
In article <2578 at rodan.acs.syr.edu> jdpeek at rodan.acs.syr.edu (Jerry Peek) writes:
> $ find . \( -type f -exec chmod 600 {} \; \) -o \
> \( -type d -exec chmod 700 {} \; \)
>
>Even though I've found this, and it seems to work, I still don't
>completely understand it. It's sort of like trying to program the
>Bourne shell just by reading the sh(1) man page. :-) [:-( ?]
The reson for this working the way it does is that there is an implied AND
between each pair of operators. This AND acts the same was as the && in C (it
is a short circut operator, if the first part is not true, the second part is
not examined/executed).
In older finds you had to do something like:
$ find . \( -type f -a -exec chmod 600 {} \; \) -o \
\( -type d -a -exec chmod 700 {} \; \)
Note the -a for specifying the and.
Now that we are done with find, I guess I'll comment on your mechanism for
changing the mode of your files. A much faster way would be to do the
following:
find . -type f -print | xargs chmod 600
find . -type d -print | xargs chmod 700
Or you could do it all at once with:
find . -type f -print | xargs chmod u+rw,g-rwx,o-rwx
Of course this assumes that
1. you have xargs(1)
2. you already had the search bit on for the user(owner) position of
the directory modes.
--
Conor P. Cahill (703)430-9247 Virtual Technologies, Inc.,
uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160
Sterling, VA 22170
More information about the Comp.unix.questions
mailing list