newgrp #
切换用户组(会创建一个子shell,并改变会话中的用户组ID)。
text
log in to a new group
Usage:
newgrp [-] [group]
If the optional - flag is given, the user's environment will be reinitialized as though the user had logged in,
otherwise the current environment, including current working directory, remains unchanged.
Example #
docker #
bash
# 临时登录docker用户组,从而使用docker命令
newgrp docker
# 使用docker命令
docker ps
# 退出newgrp环境
exit
mkdir #
bash
newgrp docker
# 创建目录(因为当前用户组已改变,新建的目录所属用户组也变成了docker)
mkdir foo
# 查看目录
ls -l
# 退出newgrp环境
exit
text
drwxr-xr-x 2 myname docker 4.0K Dec 14 11:39 foo