Xref: utzoo comp.unix.questions:24666 alt.sources:2164 Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.questions,alt.sources Subject: Re: Recursion without -R Keywords: recursion Message-ID: <104905@convex.convex.com> Date: 14 Aug 90 20:33:55 GMT References: <494@llnl.LLNL.GOV> Sender: news@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Followup-To: comp.unix.questions Organization: CONVEX Software Development, Richardson, TX Lines: 42 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 () { 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 : Editor too big!"