How to make files created in a directory owned by directory group?

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.


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