I've tried Googling but not getting anywhere. How can I list all the members of a group called mygroup from the command-line in OS X?
$dscl . list /groups will get me all the groups...but how can i see each group's members?
|
I've tried Googling but not getting anywhere. How can I list all the members of a group called $
| |||
|
feedback
|
|
Note: this answer (written by me) still gives an incomplete result. (For example, it finds no members of the everyone group!) After realizing this, I wrote a better answer, which includes a script that lists all members of a group in OS X. –Arne The dscl command given by William can be simplified (you don't need to use grep to get the specific property):
But the result of this most often is an incomplete list of the group's members. What it misses are the users who are members of the group only by having it as their primary group ID. A common case being standard OS X user accounts, which have staff (group 20) as their primary group, but they are not listed in the /Groups/staff GroupMembership entry of the Directory Service, as shown by Those users can be be found like this example for the staff group (gid 20):
| ||||
|
feedback
|
|
There's no standard command that lists all members of a group in OS X, so here's a shell function which does that:
Copy the above command-line to the Terminal, and then type Some explanation for those who are interested: There are five different ways (that I know of) that a user can be member of a group in OS X. The command So rather than trying to keep track of all those, it seems like a better idea to simply check the membership of every user on the system (using dsmemberutil), and that's what the shell function and the script below do. This members script is equivalent to the shell function, but has nicer handling of invalid input:
Supplementary info: The five ways of being a group member are:
These can be explored with commands like Example of 4: Membership of the Print Operator group _lpoperator is inherited by members of the Print Administrator group _lpadmin, and membership of that group is inherited by the members of the admin group. Example of 5:
SEE ALSO | ||||
feedback
|
| |||
|
feedback
|