Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I have a folder hierarchy that I want to change the group ownership including any subsequent file/folder additions. I was going to use chmod g+s but I'm not sure if it applies to already created folders and how I run that with the group name.

share|improve this question
What do you want: change the group ownership or set SGID bit for this folder and all subdirectories, or both? Could you please explain your situation a little more? – quanta Sep 1 '11 at 3:01

The (very slightly) expand on the existing answers, you'll probably want to both recursively set the ownership on any existing files and directories and the setgid bit on any existing directories. That is, if your hierarchy already has existing files and directories. If it doesn't, you don't need to worry about the recursive part.

Something like this:

find /path/to/hierarchy -type d | xargs chmod g+s
chgrp -R groupname /path/to/hierarchy

and you're set. Now if you want to ensure certain rwx permissions on files/dirs copied or moved into the hierarchy, that's a bit trickier. You'll likely need to use default ACLs but the Linux ACL implementation (based on a dead POSIX proposal, I believe) doesn't always work as one might expect.

share|improve this answer

Using rthomson's answer/command:

find /path/to/hierarchy -type d | xargs chmod g+s

It gave me problems when there are spaces in any of the sub-directories: Instead, I find just using the find -exec options much easier, i.e.:

find /path/to/hierarchy -type d -exec chmod g+s {} \;

share|improve this answer
Are you attempting to clarify your question? If so, please Edit the question. If this is an attempt to "Answer", it's not abundantly clear that the find...-exec method solves the problem... – Signal15 Dec 20 '14 at 3:02
I have updated my answer to clarify why use find ... -exec instead. – lsiu Feb 7 '15 at 3:25

you can use

chgrp -R folder

That will change the group owner recusively in folder , and sub-folders, and their respective files

share|improve this answer

g+s adds the "setgid" bit which basically only affects the default behavior of creating new files. (in short... any new files/directories created will have the group set to the group of the parent folder)

you could simply

chgrp group-name some_directory/* -R

to change the group of the files under "some_directory" to "group-name" recursively (-R)

share|improve this answer
If he actually is wanting change the permissions and not ownership then he should add a -R to the chmod g+s – Zoredache Aug 31 '11 at 20:05
He said in his post he wants to change group ownership. Not the permissions. – TheCompWiz Aug 31 '11 at 20:08
I know what he said, but sometimes people don't say what they mean, or they are not quite sure what they mean. Given that he was looking at chmod, I am tempted to believe that he might actually be talking about permissions. – Zoredache Aug 31 '11 at 20:48

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.