[K12OSN] chown script help needed (word of caution)

Michael C Wescott wescott at sc.rr.com
Wed Sep 14 04:04:28 UTC 2005


On Tue, 2005-09-13 at 09:00 -0700, Quentin Hartman wrote:
> A little one-liner I've used in the past to fix permissions only on
> "real" user directories and leave other stuff I tend to keep in /home
> alone is:
> 
> for i in `cat /etc/passwd | awk -F: '$3 > 500 {print $1}'`; do chown -R
> $i:$i $i; done

Gratuitous cat abuse :-)

version 0.2:

for i in `awk -F: '$3 > 500 {print $1}' /etc/passwd`; do chown -R $i:$i
$i; done

version 0.3:

awk -F: '$3>500 {print $3, $4, $6}' /etc/passwd | while read u g h
do 
   chown -R $u:$g "$h"
done

This last one avoids the assumption that the primary group name is
the same as the username (though that will almost always be true). It
uses the name of the home directory directly from the password file
rather than trying to constructing it on the fly (it also works with
home dirs with spaces in the name).

I also suggest running pwck first to check the consistency of the
password file.




More information about the K12OSN mailing list