Linux List Groups - Quick Guide

Reading time icon 2 min. read


Readers help support MSpoweruser. We may get a commission if you buy through our links. Tooltip Icon

Read our disclosure page to find out how can you help MSPoweruser sustain the editorial team Read more

linux list groups

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:

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.

listing all groups on linux using the getent 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.

listing all groups on linux using the /etc/group file

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“.

listing all groups of current user on linux with id command

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.

listing all groups of current user on linux with groups command

List All Groups of a Specific User

To list all groups of a specific user with their group IDs, run “id username“.

listing groups of a specific user with their ids on linux

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“.

listing all members of a specific group on linux with getent command

Bonus Tips:

To list only the names of all groups, type “awk -F: ‘{print $1}’ /etc/group“.

listing only names of all groups using awk command

To display the total group count, run the cat /etc/group | grep -c “” command.

getting total groups count on linux with cat and grep commands

To sort group names in ascending order, execute “cut -d: -f1 /etc/group | sort“.

listing all groups in ascending order on linux with cut command

You may also be interested in:

So, now you know how to execute Linux commands to list groups. Feel free to share your feedback in the comments below!

More about the topics: linux