Someone (sorry, deleted message) pointed out that perl's chown() call
probably follows symlinks, and that is indeed the case. However, there is
a very simple workaround for that:
find dir ! -type l -print | mychown.c
Also, as someone pointed out, if you use chown -R you also want to use
-h (if your unix flavor supports that option) to change the owner of the
symlink itself rather than what the symlink points to.
>
> If you run a separate chown process for each file, yes, that will be
> very slow. However, if these files are all in a small number of directory
> trees, then just use the recursive option of chown.
>
> chown -R newuser:newgrp dir
>
> This chowns the entire tree and I can't think of anything on the client
> side that would be faster. I don't think ONTAP has anything on the
> server side to do this operation.
>
> Of course this assumes that you want the entire directory tree chown-ed
> to the same user and group. If you need to pick and choose based on
> the existing uid (probably what you want) then I suggest doing something
> like this:
>
> find dir -print | mychown.pl
>
> And write a mychown.pl perl script like this:
>
> ===========
>
> %uidmap = ( # in %uidmap each line is olduid => newuid
> 120 => 507,
> 153 => 515,
> ...
> );
> $defaultuid = 507; # for when the old uid is not in %uidmap
>
> %gidmap = ( # in %gidmap each line is oldgid => newgid
> 200 => 217,
> 201 => 234,
> ...
> );
> $defaultgid = 212; # for when the old gid is not in %gidmap
>
> while(<>) {
> chop;
> @stat = stat($_);
> next if @stat == 0; # stat call failed, move on
> $olduid = $stat[4];
> $oldgid = $stat[5];
> $newuid = exists($uidmap{$olduid}) ? $uidmap{$olduid} : $defaultuid;
> $newgid = exists($gidmap{$oldgid}) ? $gidmap{$oldgid} : $defaultgid;
> chown($newuid, $newgid, $_);
> }
> ===========
Steve Losen scl(a)virginia.edu phone: 804-924-0640
University of Virginia ITC Unix Support