LFCS User and Group Management Practice Question
Which command will display all groups a specific user belongs to, including both primary and supplementary groups?
⚠ Common exam trap
Test-takers frequently confuse 'id -g' (which shows only the primary group ID) with listing all groups, or they assume grepping /etc/group is sufficient, overlooking that the primary group is defined in /etc/passwd and supplementary groups may come from external sources.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
groups username
The 'groups' command is the standard utility to list all group memberships for a given user, showing both the primary group (from /etc/passwd) and any supplementary groups (from /etc/group). It queries the system's group database directly, making it the correct and simplest choice for this task.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
cat /etc/passwd | grep username
Why it's wrong here
/etc/passwd stores each user's primary GID only, never supplementary group memberships, so grepping it cannot list all groups. It tempts because it is a quick text lookup, and it would be correct for confirming a user's UID, home directory or login shell.
- ✓
groups username
Why this is correct
The groups command queries both the primary group from /etc/passwd and supplementary memberships from /etc/group for the named user, printing them in a single line. This satisfies the requirement to show primary and supplementary groups together, unlike id -G which lists GIDs only.
- ✗
id -g username
Why it's wrong here
Shows only primary group ID.
- ✗
grep username /etc/group
Why it's wrong here
grep only matches lines in /etc/group, which lists supplementary members; it cannot reveal a user's primary group, which is stored as the GID field in /etc/passwd. It is tempting because /etc/group is the natural place to search for group membership, and grep would work for supplementary groups alone.
Go deeper
Related to this question
About these practice questions
This LFCS question is part of Courseiva's 406-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This LFCS practice question is part of Courseiva's free Linux Foundation certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the LFCS exam.