I am a new Linux and Unix system user. How do I list the groups a user named foo belongs to? How can I display display the groups a user is in on Linux or Unix-like systems?
You need to use the groups command to show the groups a user belongs to on Linux or Unix shell prompt.
|groups command details|
|Description||Find user's group memberships|
|Estimated completion time||1m|
List a user’s group memberships.
The basic syntax is as follows:
To simply show a user’s group memberships for the current user, type:
In this example, twelev groups are output: staff, everyone, localaccounts, _appserverusr, admin, _appserveradm, _lpadmin, _appstore, _lpoperator, _developer, com.apple.access_screensharing, and com.apple.access_ssh. You can easily count total group with the following wc command:
$ groups | wc -w
The groups command has been obsoleted by the id command. You need to use the following command which is equivalent to id -Gn:
$ id -Gn
$ id -Gn root
wheel daemon kmem sys tty operator procview procmod everyone staff certusers localaccounts admin _appstore _lpadmin _lpoperator _developer com.apple.access_screensharing com.apple.access_ssh
- /etc/group file.
- Man pages – id(1),group(5)