sg
execute a command with a different group ID
TLDR
SYNOPSIS
sg [-] [group] [[-c] command]
DESCRIPTION
sg executes a command or starts a shell with a different group ID. It is functionally similar to newgrp but allows running a single command rather than starting a new shell session.When called without a command, sg starts a new shell with the specified group as the effective group ID. When called with -c, it executes the given command with the new group and returns.The user must be a member of the target group, or the group must have a password set (via gpasswd) which the user can provide. The root user can switch to any group without restrictions.
PARAMETERS
group
The group name to switch to. The user must be a member of this group (or know its password).-c command
Execute the specified command with the new group ID rather than starting an interactive shell.-
Start the shell as a login shell, reinitializing the environment.
CAVEATS
The sg command is part of the shadow-utils package. If the user is not a member of the specified group and no group password is set, access will be denied. Environment variables may be reset depending on how the shell is invoked. On some systems, the sg name may conflict with the ast-grep tool alias; use the full path /usr/bin/sg if needed.
