7

Some one messed up /usr/local/ permissions, so that nobody else can access it. Now I would like to duplicate user permissions to group permissions, since chmod g+rx -R /usr/local is unsafe. How should this be done?

Using linux (ubuntu 10.04).

3 Answers 3

15

You can copy permissions:

chmod -R g=u /usr/local

This will copy the user permissions to the group permissions.

1
  • Elegant, Dennis; I did not know that!
    – MadHatter
    Feb 28, 2011 at 12:32
2
cd /usr/local
chmod -R g-rwx .
find . -perm -u+r -exec chmod g+r {} \;
find . -perm -u+w -exec chmod g+w {} \;
find . -perm -u+x -exec chmod g+x {} \;

This first clears the group permissions from all files. Then it should search down, examining each file for each of the three user permission bits in turn (r, w, x). For each permission, when it finds a file that has that bit set (disregarding their other user permission bits), it sets the equivalent group bit on for that file.

I strongly advise you to test this on a random subdirectory first, preferably with some corner-case files in it that you make yourself. But it works in my comparable tests.

4
  • This is what I was just testing before posting.
    – user9517
    Feb 28, 2011 at 10:22
  • <grin> sorry, iain!
    – MadHatter
    Feb 28, 2011 at 10:26
  • That would be definitely slow for large amount of files since each file would be parsed three times.
    – TiansHUo
    Mar 1, 2011 at 5:31
  • I completely agree. Dennis' solution is way superior; but if it hadn't been known, or existed, mine was still faster than doing it by hand!
    – MadHatter
    Mar 1, 2011 at 21:14
0

i did find this perl based solution on the net also.

find . | perl -ne 'chomp; $a = (stat $_)[2] & 07777; $a = ($a & 07707) | (($a >> 3) & 070); chmod($a, $_)'

but the

    chmod g=u

mentioned elsewhere is better i think

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .