如何在 Linux 上查找指定用户所属的组?
linuxoperating systemopen source更新于 2026/2/15 0:22:17
我们知道,借助 Linux 实用程序命令 compgen,我们可以打印 Linux 上的所有用户。
compgen 命令是一个 Linux 实用程序命令,用于列出 Linux 终端中可以执行的所有命令。当与 -u 参数一起使用时,我们可以打印 Linux 上的所有用户。
请参考下面的命令 −
compgen -u
输出
root daemon bin sys sync games man lp mail news uucp proxy www-data backup . . .
现在,如果我们想打印 Linux 操作系统上存在的组总数,我们可以使用 groups 命令。
groups 命令用于打印 Linux 内核上存在的所有组。
语法
groups [options]
通常,上述命令中的选项会被替换为特定用户,我们需要检查该用户有多少个组。
让我们来看几个 group 命令的示例。
命令
groups
输出
sh-3.2# groups wheel daemon kmem sys tty operator procview procmod everyone staff certusers localaccounts admin com.apple.sharepoint.group.1 _appstore _lpadmin _lpoperator _developer _analyticsusers com.apple.access_ftp com.apple.access_screensharing com.apple.access_ssh com.apple.access_remote_ae
如果您想检查特定用户的群组,请运行以下命令。
命令
groups immukul
输出
sh-3.2# groups immukul staff everyone localaccounts _appserverusr admin _appserveradm _lpadmin com.apple.sharepoint.group.1 _appstore _lpoperator _developer _analyticsusers com.apple.access_ftp com.apple.access_screensharing com.apple.access_ssh com.apple.access_remote_ae
相关文章
有用资源
linux 参考教程 - 该教程包含有关 linux 的更多信息:https://www.cainiaomax.com/linux/

