Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Nov 2001 10:19:29 +0200
From:      "Patrick O'Reilly" <patrick@mip.co.za>
To:        <jessie@power-jessie.net>, <freebsd-questions@FreeBSD.ORG>
Subject:   RE: help on system accounts
Message-ID:  <NDBBIMKICMDGDMNOOCAIGEKDDOAA.patrick@mip.co.za>
In-Reply-To: <9t2g7m%2Bmj09@eGroups.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> From:  jessie@power-jessie.net
> <snip>
> 2. i've accidentally chowned some user files to root and
> i want to put them back to their respective user's ownership.
> how can i easily change the ownership/group of files/dirs?
>
> i.e
>
> drwx--x---   2 root    wheel      512 Oct 10 23:16 gates
> drwxr-xr-x   7 root    wheel     1536 Nov 13 11:36 jessie
> .
> .
> drwx--x---   2 root    wheel      512 Oct 10 23:16 zeus
>
> i want it to be like this:
>
> drwx--x---   2 gates   gates       512 Oct 10 23:16 gates
> drwxr-xr-x   7 jessie  jessie     1536 Nov 13 11:36 jessie
> .
> .
> drwx--x---   2 zeus    zeus        512 Oct 10 23:16 zeus
>

try something along these lines:

# cd /home
# for dir in `ls`          # list all the directories ...
> do                       # and for each directory ...
> echo $dir                # display the directory name ...
> chown -R $dir:$dir $dir  # and set the owner:group ...
> done                     # until they are all done.
#

Note 1:  If you have 13,000 directories that need fixing, then this process
is likely to take some time.  That's why I included the "echo $dir" line, so
that you will be able to see how the script is progressing.

Note 2: I've written this to work in the bash (and similar) shells.  I think
'csh' syntax will be different.

Note 3: It looks like you might be wanting to clean up the permission
settings too?  'gates' and 'jessie' have 710 and 755 respectively.  Is that
by design or by accident?

Patrick.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?NDBBIMKICMDGDMNOOCAIGEKDDOAA.patrick>