Question

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 act.

Was it helpful?

Solution

To query a local group:

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top