Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 19 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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .