Change group ownership of Folders with chmod g+s

Solution 1:

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 {} \;

Solution 2:

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.

Solution 3:

you can use

chgrp -R folder

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

Solution 4:

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)