The groups
command is a Unix and Linux utility that displays the group membership of a user.
Here is the basic syntax for using the groups
command:
groups [user]
The user
argument is optional. If you do not specify a user, groups
will display the group membership of the current user. If you specify a user, groups
will display the group membership of that user.
For example, to display the group membership of the current user, you can use the following command:
groups
This will display a list of the groups that the current user is a member of.
For example, if the current user is a member of the users
and admins
groups, the command will output:
users admins
To display the group membership of a different user, you can specify the username as an argument.
For example, to display the group membership of the user john
, you can use the following command:
groups john
This will display a list of the groups that the user john
is a member of.
You can use the -n
option to display the group names instead of the group IDs.
For example:
groups -n john
This will display the group names instead of the group IDs for the user john
.