Defcon-1-Logo

           [Home]    [FBSD Articles]    [Scripts Corner]    [Contribute]    [Search]    [FBSD Links]    [Files]

About Us

FreeBSD Articles
  *Hardware
  *Networking
  *Security
  *Software
  *X Windows


Files / Scripts
Newbies Corner
Tech. Talk
Tips and Tricks


FreeBSD Links

Articles in other
Languages :
  *French Articles
  *Spanish Articles

Want to Help ?
 
   Click Here

Email Users5

Search:
 

 


FreeBSD Search:


 

 

Powered-By-Apache-Logo

Changing User Dir Ownership

 One nite while working on something late, i screwed up and accidently changed the ownership of all the user home dirs on the machine to being owned by me. Instead of berating myself all nite, i wrote 2 small scripts to change them back to the proper ownership.

Bascially what i want to do is change the ownership of each dir in /usr/home to the name of the dir. In other words, I want the dir /usr/home/ed owned by ed. First I need to list all the dirs in /usr/home. BTW: both scripts for this resided in /usr/home for this. Modify to suit your needs. The first script was like this:

#!/bin/sh

/bin/ls | /usr/bin/xargs -n1 /usr/home/script2.sh

 

Now the script2.sh consisted of this:

#!/bin/sh

NAME=$1

/usr/sbin/chown -R $NAME $NAME

 

 The first script did an ls but then fed each single dir name to script2.sh one at a time. The second script took took the output from the first script and used it as teh arguments for the chown. Thus together the scripts read each dir/file name in /usr/home and then chown the dir to the username that is the same as the dir name. I have actually used this about 5 times now to save me from quite a bit of boring work fixing typos/mistakes.

 I was working on a way to do it all in one file, but couldn't get it to properly feed the dir name twice to the chown command. I might play with this more later and try to get that done, but for now it works and functions just fine for my uses.

 

technoid@defcon1.org

Email Us

ghostrdr@defcon1.org

This site cannot be duplicated without permission

© 1998 - 2010 Defcon1, www.defcon1.org. Copyrights for all materials on this web site are held by the individual authors, artists, photographers or creators. Materials may not be reproduced or otherwise distributed without permission of www.defcon1.org and the content's original author.