Apps Artificial Intelligence CSS DevOps Go JavaScript Laravel Linux MongoDB MySQL PHP Python Rust Svelte Vue

List All Group Names on Linux

1 min read .
List All Group Names on Linux

Linux groups are used to organize users and assign shared permissions. There are several ways to list them, and the best command depends on whether your system uses only local files or also directory services such as LDAP.

Use getent

getent group

getent queries the system’s configured name-service databases, so it can include groups from /etc/group as well as network identity sources.

Print only group names:

getent group | cut -d: -f1

For administration and auditing, this is usually more complete than reading /etc/group directly.

Read Local Groups from /etc/group

cut -d: -f1 /etc/group

Or with awk:

awk -F: '{print $1}' /etc/group

These commands show only entries stored in the local group file.

Use Bash compgen

In Bash:

compgen -g

This is convenient for interactive use.

Filter the Result

getent group | grep '^docker:'

For an exact group lookup, avoid a broad grep and ask getent directly:

getent group docker

Check a User’s Groups

To see group memberships for a particular user:

id username
groups username

Conclusion

Use getent group when you want the groups visible through the system’s configured identity sources, and /etc/group when you specifically want local group-file entries. id and groups are the right tools for checking membership for an individual user.

Related Posts

chevron-up