9

With umask, I can determine the permissions for newly created files. But if I am a member of multiple groups, how do I set the default group for newly created files?

This question seems relevant, but its answers relate how the system administrator can change the default group for a particular user. I am not system administrator, but just a mere user, and have no permission to do usermod -g even on myself. So how would I proceed to set the default group for newly created files?

1 Answer 1

6

To change your default group on the fly, use newgrp:

newgrp some_group

After running that command, you will be in a new shell with your group set to some_group and files that you create will be in group some_group. newgrp may or may not ask for a password depending on how permissions are set.

Related: To find out which groups you belong to, run groups.

3
  • 1
    Just tested this, groups (at least on Arch) sorts them by numerical value, the primary group is not the first listed. Use id to get these details. Commented Mar 4, 2014 at 19:30
  • @orion I checked the documentation and found nothing to support the claim about the primary group. Answer updated. Commented Mar 4, 2014 at 19:48
  • 2
    It's important to note that newgrp launches a new shell. I don't think there's any way to change the default group for an existing process. Commented Mar 4, 2014 at 20:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.