How to list all users in a Linux group?

后端 未结 20 1168
春和景丽
春和景丽 2020-12-07 06:51

How do I list all members of a group in Linux (and possibly other unices)?

相关标签:
20条回答
  • 2020-12-07 07:49
    getent group groupname | awk -F: '{print $4}' | tr , '\n'
    

    This has 3 parts:

    1 - getent group groupname shows the line of the group in "/etc/group" file. Alternative to cat /etc/group | grep groupname.

    2 - awk print's only the members in a single line separeted with ',' .

    3 - tr replace's ',' with a new line and print each user in a row.

    4 - Optional: You can also use another pipe with sort, if the users are too many.

    Regards

    0 讨论(0)
  • 2020-12-07 07:50

    There is a handy Debian and Ubuntu package called 'members' that provides this functionality:

    Description: Shows the members of a group; by default, all members members is the complement of groups: whereas groups shows the groups a specified user belongs to, members shows users belonging to a specified group.

    ... You can ask for primary members, secondary members, both on one line, each on separate lines.

    0 讨论(0)
提交回复
热议问题