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 groupgetent 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: -f1For administration and auditing, this is usually more complete than reading /etc/group directly.
Read Local Groups from /etc/group
cut -d: -f1 /etc/groupOr with awk:
awk -F: '{print $1}' /etc/groupThese commands show only entries stored in the local group file.
Use Bash compgen
In Bash:
compgen -gThis 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 dockerCheck a User’s Groups
To see group memberships for a particular user:
id username
groups usernameConclusion
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.