Bash Scripting - How to set up a group with which new files will be created?

I am making a bash shell script and I want to change the default group in which new files are created. I know that you use umask to change permissions. Is there anything for the band?

+63
linux unix bash shell permissions
Aug 24 '09 at 8:40
source share
2 answers

newgrp (1)

+8
Aug 24 '09 at 8:44
source share

There are several ways to do this:

  • You can change the default group for all files created in a specific one by setting the setgid flag in the directory ( chmod g+s _dir_ ). Then new files will be created in the directory with the group directory (set using chgrp <group> <dir> ). This applies to any program that creates files in a directory.

    Note that this is automatically inherited for new subdirectories (starting with Linux 3.10), however, if subdirectories are already present, this change will not apply to them (use the -R flag for this).

  • If the setgid flag is not set, then the default group will be set to the current group identifier of the creation process. Although this can be set using the newgrp command, which creates a new shell that is difficult to use in a shell script. If you want to execute a specific command (or set of commands) with a modified group, use the sg <group> <command> .

    sg not a standard POSIX command, but is available on Linux.

+155
Aug 24 '09 at 14:19
source share



All Articles