I'm doing a bash shell script and I want to change the default group that new files are created as. I know you use umask
to change the permissions. Is there something for the group?
views:
378answers:
2There are a couple ways to do this:
You can change the default group for all files created in a particular directory by setting the setgid flag on the directory (
chmod
g+s
dir). New files in the directory will then be created with the group of the directory (set usingchgrp
group dir). This applies to any programs that create files in the directory.If the setgid flag is not set, then the default group is set from the current group id of the creating process. Although that can be set using the
newgrp
command, that creates a new shell which is difficult to use within a shell script. If you want to execute a particular command (or set of commands) with the changed group, use the commandsg
group command.sg
is not a POSIX standard command but is available on Linux.