I want to know the groups of some user.

$dscl . list /groups filterByUSer theFindUser

Is this possible (even if I have to enumerate all the groups and then filter by user) in a straightforward manner?

2 Answers 2


Try the command given below.

id -Gn [user]

On my Mac, the output from id -Gn davidanderson is given below.

staff everyone localaccounts _appserverusr admin _appserveradm _lpadmin _appstore _lpoperator _developer _analyticsusers com.apple.access_ftp com.apple.access_screensharing com.apple.access_ssh 2 1

The delimiter could be changed from a space to a comma by entering the following.

groups="$(id -Gn davidanderson)"
groups="${groups// /,}"
echo "$groups"

Here, the output would be as follows.


I am using High Sierra, macOs 10.13.4 and a bash shell.

  • Is there a way to add a delimiter between the groups?
    – Ryan Gates
    Commented Dec 30, 2019 at 21:23
  • You mean other than a space? Like a comma maybe? Commented Dec 30, 2019 at 22:55
  • Thank you for your response. I ended up using id on its own. It printed the group id, the name in parentheses and used a comma as a separator. This would only work for looking up the current user. That solved my problem though.
    – Ryan Gates
    Commented Dec 31, 2019 at 15:40
  • Any idea which API in which Framework of MacOS provides this information? I need this, but from my Cocoa code - and I can't find an answer... Commented Dec 30, 2020 at 13:08
  • Could you not just Execute a terminal command from a Cocoa app? Commented Dec 30, 2020 at 18:11

To list all the groups to which a user belongs, type:

id [username]

[username] argument is optional. By default, the logged in user is assumed. The output will include the numeric user id uid, and the list of all the groups along with their group id gid, of which the user is member of. The first group in the output is the user's primary group.

To list just the group names type:

id -Gn [username]

To list just the group numbers type:

id -G [username]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .