jdpeek@rodan.acs.syr.edu (Jerry Peek) (03/23/90)
I've been using UNIX for almost ten years, and I never realized that find(1) could do more than one kind of operation as it works through a directory tree. It's in the man page, I guess, but I never figured it out... For instance, if I was setting modes on a bunch of directories and files, I'd do the directories with "find . -type d -exec chmod 700 {} \;" then I'd do the files with "find . -type f -exec chmod 600 {} \;". (Well, actually, I use xargs(1) too, but that's another story.) Tonight I found that this (long command line) does it all in one pass: $ 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. :-) [:-( ?] How about some useful examples of this? Post or e-mail, though posting might help other unenlightened geeks like me. :-) I'd be glad to summarize e-mail I get, if you ask. Thanks... --Jerry Peek; Syracuse University Academic Computing Services; Syracuse, NY jdpeek@rodan.acs.syr.edu, JDPEEK@SUNRISE.BITNET +1 315 443-3995
cpcahil@virtech.uucp (Conor P. Cahill) (03/23/90)
In article <2578@rodan.acs.syr.edu> jdpeek@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