linux groups command tutorial: groups syntax and groups examples

In Linux, a group is a collection of users. The main purpose of a group is to manage users and grant relevant permissions, such as read, write, and execute permissions. Users within a group share group permissions.

This article will share how to use the linux groups command and its examples.

linux groups command – print the groups a user is in.

syntax

groups [USERNAME]...

Print group memberships for each USERNAME or, if no USERNAME is specified, for the current process.

examples

View the groups to which the currently logged in user belongs

➜  ~ groups
ylspirit adm cdrom sudo dip plugdev lpadmin sambashare

The above display mode is not convenient to view. You can use the awk command to format it for us to read.

➜  ~ groups | awk -F' ' '{for(i=1;i<=NF;i++) {print $i}}'
ylspirit
adm
cdrom
sudo
dip
plugdev
lpadmin
sambashare
➜  ~

View the group to which the specified user belongs

➜  ~ groups ylspirit
ylspirit : ylspirit adm cdrom sudo dip plugdev lpadmin sambashare
➜  ~ groups
ylspirit adm cdrom sudo dip plugdev lpadmin sambashare
➜  ~

More ways to view the groups to which a given user belongs: How to check which group the specify user belongs to?

Recommended Posts:

Linux common commands tutorial and use examples
GNU sed syntax and sed examples

Add a Comment

Your email address will not be published. Required fields are marked *