Linux command
sg 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Start a shell
sg [group]
Execute a specific command
sg [group] -c "[command]"
Run a command as the
sg www-data -c "touch [/var/www/html/file.txt]"
Start a login shell
sg - [group]
说明
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.
参数
- -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.
FAQ
What is the sg command used for?
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.
How do I run a basic sg example?
Run `sg [group]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -c _command_ do in sg?
Execute the specified command with the new group ID rather than starting an interactive shell.