You can list all groups a user belongs to in a Linux (or Unix) shell in the following ways:
id command, when used without any flags, displays the user and its group information by default. However, to get only the groups (without additional user information), you can use the command with
id -Gn [user]
Where the "
[user]" is the (optional) username of the user you want to check group information for. When the username is omitted, it defaults to the logged-in user. For example, the following will output the names of the groups the logged-in user is a member of:
Similarly, to only see the groups for a specific user, you can specify the username as an argument to the
id command, for example, like so:
id -Gn your_username
To list all groups a user is a member of, you can use the
groups command. It has the following syntax:
[user]" can be the username of the user you wish to output the groups for. For example:
If you omit the username, then it will display the groups for the logged-in user.
man groups command suggests that the
groups utility has been obsoleted by the
id(1) utility, and is equivalent to the "
Hope you found this post useful. It was published . Please show your love and support by sharing this post.