up vote 4 down vote favorite
share [g+] share [fb]

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?

link|improve this question

62% accept rate
feedback

2 Answers

up vote 5 down vote accepted

If you 'chmod g+s directory' then all 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.

link|improve this answer
feedback

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
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.