문제

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?

도움이 되었습니까?

해결책

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.

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

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

다른 팁

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]

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 apple.stackexchange
scroll top