是否有命令列出所有Unix组名? [关闭]

本文翻译自:Is there a command to list all Unix group names? [closed]

I know there is the /etc/group file that lists all users groups. 我知道有/etc/group文件列出了所有用户组。

I would like to know if there is a simple command to list all user group names in spite of parsing the world readable /etc/group file. 我想知道是否有一个简单的命令列出所有用户组名称,尽管解析了世界可读的/etc/group文件。 I am willing to create an administrator web page that lists Linux accounts' group names. 我愿意创建一个列出Linux帐户组名的管理员网页。


#1楼

参考:https://stackoom.com/question/wzcq/是否有命令列出所有Unix组名-关闭


#2楼

To list all local groups which have users assigned to them, use this command: 要列出已为其分配用户的所有本地组,请使用以下命令:

cut -d: -f1 /etc/group | sort

For more info- > Unix groups , Cut command , sort command 有关更多信息 - > Unix组剪切命令排序命令


#3楼

If you want all groups known to the system, I would recommend using getent instead of parsing /etc/group . 如果您希望系统知道所有组 ,我建议使用getent而不是解析/etc/group On networked systems, groups may not only read from /etc/group file but also obtained through LDAP or Yellow Pages, ie the list of known groups comes from the local group file plus groups received via LDAP or YP. 在联网系统上,组不仅可以从/etc/group文件读取,还可以通过LDAP或黄页获取,即已知组的列表来自本地组文件以及通过LDAP或YP接收的组。

getent group will give you a list of all groups in the same format the /etc/group file uses. getent group将以/etc/group文件使用的相同格式为您提供所有组的列表。

If you want just the group names, getent group | cut -d: -f1 如果你只想要组名, getent group | cut -d: -f1 getent group | cut -d: -f1 will do the job (same as above). getent group | cut -d: -f1将完成这项工作(与上面相同)。


#4楼

On Linux, macOS and Unix to display the groups to which you belong, use: 在Linux,macOS和Unix上显示您所属的组,使用:

id -Gn

which is equivalent to groups utility which has been obsoleted on Unix (as per Unix manual ). 这相当于在Unix上已经废弃的groups实用程序(根据Unix手册 )。

On macOS and Unix, the command id -p is suggested for normal interactive. 在macOS和Unix上,建议使用命令id -p进行常规交互。

Explanation of the parameters: 参数说明:

-G , --groups - print all group IDs -G , - --groups - 打印所有组ID

-n , --name - print a name instead of a number, for -ugG -n--name -打印名称,而不是一个号码,用于-ugG

-p - Make the output human-readable. -p - 使输出具有人类可读性。

发布了0 篇原创文章 · 获赞 52 · 访问量 35万+

猜你喜欢

转载自blog.csdn.net/CHCH998/article/details/105635477