Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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).

share|improve this question
up vote 12 down vote accepted

You can copy permissions:

chmod -R g=u /usr/local

This will copy the user permissions to the group permissions.

share|improve this answer
Elegant, Dennis; I did not know that! – MadHatter Feb 28 '11 at 12:32
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.

share|improve this answer
This is what I was just testing before posting. – Iain Feb 28 '11 at 10:22
<grin> sorry, iain! – MadHatter Feb 28 '11 at 10:26
That would be definitely slow for large amount of files since each file would be parsed three times. – TiansHUo Mar 1 '11 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 '11 at 21:14

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.