[X-Unix] script: setting directory ownership to the name of that directory ?

macosxforme macosxforme at gmail.com
Sun Aug 14 05:17:08 PDT 2005


I am certain that this is easy for most of you, and probably rather basic...

I have a base folder/directory, and within it, will be a long list (800 or
so) of directories.

Each directory will bear the name of a user. So, the user will already exist
on the system (OS X Server, not client)

What I need to do, is read the listing of those folders, and set the owner
of each directory to be the name of the directory itself - ie:
chown admin-name:$dirname $dirname   ... ?

I've been fumbling with this for a couple days...

I can do
ls -l | awk '{print $9}'

(or, could use: basename )
but how do I store that value, and then use the stored value for chown...  ?

grumble... 

getting the name of each directory and for each directory setting owner (ie:
chown admin:directoryname directoryname
and then doing the same on the next directory, etc.

such that

drw-rw-r--    2 admin  usera     68 Aug 13 22:24 usera
drw-rw-r--    2 admin  userb     68 Aug 13 18:04 userb


Any and all input welcome and appreciated, TIA




More information about the X-Unix mailing list