Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way, on Linux, to cause all new files created in a directory to be owned by the directory's group instead of the creating user's group?

share|improve this question
add comment

2 Answers

up vote 17 down vote accepted

If you chmod g+s directory then all the files created in that directory will be owned by that group.

newgroup is really a holdover from the days when you could only be in one group, and isn't really needed nowadays.

share|improve this answer
add comment

Files created by user are created with his current group ID. To check user ids you can execute id; to change your GID to something from the list of your groups use newgrp <group> or sg <group> <command>: first command will launch shell and the latter will just run a command with GID set to <group> id.

Check this shell 'log':

whitequark@forth:~/test$ id
uid=1000(whitequark) gid=1000(whitequark) groups=4(adm),20(dialout),24(cdrom),
46(plugdev),104(lpadmin),114(admin),118(sambashare),1000(whitequark)
whitequark@forth:~/test$ touch file1
whitequark@forth:~/test$ ls -la
total 8
drwxr-xr-x  2 whitequark whitequark 4096 2010-01-29 19:49 .
drwxr-xr-x 82 whitequark whitequark 4096 2010-01-29 18:02 ..
-rw-r--r--  1 whitequark whitequark    0 2010-01-29 19:49 file1
whitequark@forth:~/test$ newgrp admin
<<< at this point a new shell is started >>>
whitequark@forth:~/test$ touch file2
whitequark@forth:~/test$ ls -la
total 8
drwxr-xr-x  2 whitequark whitequark 4096 2010-01-29 19:49 .
drwxr-xr-x 82 whitequark whitequark 4096 2010-01-29 18:02 ..
-rw-r--r--  1 whitequark whitequark    0 2010-01-29 19:49 file1
-rw-r--r--  1 whitequark admin         0 2010-01-29 19:49 file2
share|improve this answer
add comment

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.