Linux List Groups - Quick Guide
2 min. read
Published on
Read our disclosure page to find out how can you help MSPoweruser sustain the editorial team Read more
Wondering how to use Linux commands to list groups? As an administrator, you may need to understand how they work and how specific users are linked with them.
In this guide, I’ll show you the easiest methods to list groups on Linux. So, let’s go!
List All Groups on Linux
To list all groups on Linux, you can use:
- getent Command
- /etc/group file
1. Using the getent Command
In Linux-based systems, the getent command is used to display entries from databases. In addition, you can use it to fetch the content of the group database to list all groups on your terminal.
To do so, I’ll run the “getent group” command.
2. Using the /etc/group File
The /etc/group comprises all of your local groups. Thus, you can list all groups using this file with the “cat /etc/group” command.
List All Groups of the Current User
To list all groups of the current user, you can use:
1. Using the id Command
The id command prints the user information on the terminal. Additionally, to list all groups of the current user, you can run “id -Gn“.
In the above id command, the combination of -Gn options prints the group names instead of group IDs.
2. Using the groups Command
Executing groups command without any option lists all groups of the current user.
List All Groups of a Specific User
To list all groups of a specific user with their group IDs, run “id username“.
As a result, the output displays the information related to user ID as uid, user primary groups as gid, and user secondary groups.
List All Members of a Specific Group
To list all members of a particular group, execute “getent group username“.
Bonus Tips:
To list only the names of all groups, type “awk -F: ‘{print $1}’ /etc/group“.
To display the total group count, run the cat /etc/group | grep -c “” command.
To sort group names in ascending order, execute “cut -d: -f1 /etc/group | sort“.
You may also be interested in:
- Linux Remove User From Group
- FL Studio Linux
- Truncate File Linux
- How To Delete User in Linux
- Move Directory Linux
So, now you know how to execute Linux commands to list groups. Feel free to share your feedback in the comments below!
User forum
0 messages