开发者

How does one list users belonging to a group in OSX?

开发者 https://www.devze.com 2023-03-12 04:27 出处:网络
I have been googling this problem to no avail. I want to list just the users belonging to a particular group without extraneous data in osx terminal, I thought the dscl utility would be capable of doi

I have been googling this problem to no avail. I want to list just the users belonging to a particular group without extraneous data in osx terminal, I thought the dscl utility would be capable of doing this but so far I have been unable to craft out the right command if indeed it is capable of such an ac开发者_开发百科t.


To query a local group:

$ dscl . -read /groups/<groupname> | grep GroupMembership


dscacheutil -q group -a name staff

or

dscacheutil -q group -a name admin 

etc... get it?


Use this shell function, which calls dsmemberutil checkmembership for every user. For example: members everyone. (Source: https://superuser.com/questions/279891/list-all-members-of-a-group-mac-os-x )

members () { dscl . -list /Users | while read user; do printf "$user "; dsmemberutil checkmembership -U "$user" -G "$*"; done | grep "is a member" | cut -d " " -f 1; }; 

members <group>

Other methods using dscl . -read and dscacheutil are incomplete. For example:

dscl . -read /groups/everyone | grep GroupMembership
dscacheutil -q group -a name everyone

do not list any users, whereas the shell function does.

0

精彩评论

暂无评论...
验证码 换一张
取 消