How to list all users in a Linux group?

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

    You can do it in a single command line:

    cut -d: -f1,4 /etc/passwd | grep $(getent group  | cut -d: -f3) | cut -d: -f1
    

    Above command lists all the users having groupname as their primary group

    If you also want to list the users having groupname as their secondary group, use following command

    getent group  | cut -d: -f4 |  tr ',' '\n'
    

提交回复
热议问题