rjshaw@ramius.ocf.llnl.gov (Robert Shaw) (08/14/90)
Hi. What are some quick tricks for getting programs like chmod and chown to descend into all subdirectories? Programs without a -R option, that is. ==== My earlier "awk -F" was refering to a Pyramid running OSx. Thanx to those who called OFS to my attention, and my apologies to those of who noted that awk -F on a sun works differently that I claimed in posting. ==== I'm also looking for Korn shell info... =============================================================================== rjshaw@ramius.llnl.gov _____ ____ ____ ______ R o b / / / / / / / / / / / -------- / --/ / / / / / / / / / --------------------------- /-- / / / / / / / / S h a w /____/ /_/_/ /_/_/ /_____/ The Cosby's are precisely what's wrong with television today... ===============================================================================
swfc@ulysses.att.com (Shu-Wie F Chen) (08/15/90)
In article <494@llnl.LLNL.GOV>, rjshaw@ramius.ocf.llnl.gov (Robert Shaw) writes: |>Hi. |> |>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. *swfc
tchrist@convex.COM (Tom Christiansen) (08/15/90)
In article <494@llnl.LLNL.GOV> rjshaw@ramius.llnl.gov 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. Well, here's a quick way to change all files from a set of old uids and gids to new ones. In this example, I want to change group uucp to be 1789, group staff to be 666, user kirk to be 1000, and user bill to be 7777. This code traverses the file system making those changes, omitting NFS decents. This is just a fragment of a larger program that does a lot of other sanity checks and configuration stuff not included here. #!/usr/bin/perl $start = '/'; # do whole tree %nuid = ( 'kirk', 1000, 'bill', 7777 ); %ngid = ( 'staff', 666, 'uucp', 1789 ); open(FIND, "find $start \\( -fstype nfs -prune \\) -o -ls |"); while (<FIND>) { split; $uid = $gid = -1; ($file, $user, $group) = ($_[11], $_[5], $_[6]); if (defined $nuid{$user}) { $uid = $nuid{$user}; } if (defined $ngid{$group}) { $gid = $ngid{$group}; } if (($uid != -1 || $gid != -1) && !chown($uid, $gid, $file)) { warn "$0: couldn't change $file to $uid.$gid: $!\n"; } } --tom -- Tom Christiansen {uunet,uiucdcs,sun}!convex!tchrist Convex Computer Corporation tchrist@convex.COM "EMACS belongs in <sys/errno.h>: Editor too big!"
kaul@icarus.eng.ohio-state.edu (Rich Kaul) (08/15/90)
In article <13595@ulysses.att.com> swfc@ulysses.att.com (Shu-Wie F Chen) writes:
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.
Or if you were smart enough to grab the free, PD version that Gordon
Moffet posted a while ago. I still have a copy sitting around
somewhere so drop me a line if you want it.
-rich
wittig@gmdzi.UUCP (Georg Wittig) (08/15/90)
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 . -exec chmod go-rw {} \; --or-- find . -type f -exec chmod go-rw {} \; -- Georg Wittig GMD-Z1.IT | wittig@gmdzi.gmd.de | "Freedom's just another word P.O. Box 1240 | wittig@zi.gmd.dbp.de | for nothing left to lose" D-5205 St. Augustin 1 | | (Kris Kristofferson) West Germany | (+49) 2241 14-2294 |
micah@sgi.com (micah altman) (08/16/90)
In article <KAUL.90Aug14205729@icarus.eng.ohio-state.edu> kaul@icarus.eng.ohio-state.edu (Rich Kaul) writes: >In article <13595@ulysses.att.com> swfc@ulysses.att.com (Shu-Wie F Chen) writes: > 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. ... > If your version of find supports the -exec option you could recursively step through files and change the owner to "foo" by issueing the command find . -exec chown foo {} \; ( And yes, the "\;" at the end is necessary ) - Micah Altman Computational Juggler
dik@cwi.nl (Dik T. Winter) (08/16/90)
In article <1990Aug15.175322.23868@odin.corp.sgi.com> micah@sgi.com (micah altman) writes: > find . -exec chown foo {} \; > And do this only if user foo is in the local password file, not if foo is known through yellow pages. -- dik t. winter, cwi, amsterdam, nederland dik@cwi.nl
etienne@accsys.ccs.imp.com (Stefan Hauser) (08/18/90)
In article <13595@ulysses.att.com> swfc@ulysses.att.com (Shu-Wie F Chen) writes: >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 how about : find . -exec chown foo {} \; i think that should work on all systems, or not ? stefan -- Stefan Hauser | CH-Sargans | EMAIL : etienne@accsys.ccs.imp.com
jessea@dynasys.UUCP (Jesse W. Asher) (08/18/90)
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: >|>Hi. >|> >|>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.
wcs) (08/22/90)
In article <104905@convex.convex.com> tchrist@convex.COM (Tom Christiansen) writes: ]In article <494@llnl.LLNL.GOV> rjshaw@ramius.llnl.gov 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. Sorry if this is a duplicate; the expire daemon hit while I was on vacation. find $* -depth -exec foo -args {} morestuff \; which is slow (does things one at a time) but flexible, or find $* -depth -print | xargs chown joeuser The find command recursively searches directories; the -depth option tells it to do things depth-first (sometimes important when you're dealing with directory ownership/permission changes), the -exec executes one command per found item, and the xargs takes names from standard input and builds them into command lines. -- Thanks; Bill # Bill Stewart 908-949-0705 erebus.att.com!wcs AT&T Bell Labs 4M-312 Holmdel NJ # There'll be a brand new war coming soon to a theatre near you - promise!
chris@mcc.pyrsyd.oz (Chris Robertson) (08/22/90)
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