How to list all users in a Linux group?

后端 未结 20 1275
春和景丽
春和景丽 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

提交回复
热议问题