Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

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

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

Your Answer

 
discard

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.