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

Quentin Hartman qhartman at lane.k12.or.us
Tue Sep 13 16:00:21 UTC 2005


On Sun, 2005-09-04 at 12:49 -0500, Les Mikesell wrote:
> This will simply fail if one of the names contains spaces.
> If you really don't want to do this to all the directories
> under /home, you can generate the list some other way.
> For example you could copy the /etc/passwd file, delete
> the range you don't want, then (in vi) :%s/:.*// to
> leave only the names.  If you save that in a file you
> can change the 'for i in *' line above to
> for i in `cat file`
> to iterate over the list you want.

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

So maybe it's a one-and-half liner, but it eliminates the need (on my
systems at least) to do manual file manipulations, and therefor also
eliminates fat-finger syndrome. Let's hear it for stupid Unix tricks!

-- 
-Regards-

-Quentin Hartman-
Technology Coordinator
South Lane School District
Cottage Grove, OR




More information about the K12OSN mailing list