Bird
0
0

You want to write a script that prints your username and all group names you belong to. Which combination of commands will achieve this?

hard📝 Application Q15 of 15
Linux CLI - Users and Groups
You want to write a script that prints your username and all group names you belong to. Which combination of commands will achieve this?
A<code>id -un && id -G</code>
B<code>whoami -g && id -u</code>
C<code>echo $(whoami) && id -Gn</code>
D<code>whoami && id -G</code>
Step-by-Step Solution
Solution:
  1. Step 1: Identify command to print username

    whoami prints the current username. Using echo $(whoami) prints it clearly.
  2. Step 2: Identify command to print group names

    id -Gn prints all group names the user belongs to, separated by spaces.
  3. Step 3: Evaluate options

    echo $(whoami) && id -Gn correctly combines username and group names. whoami -g && id -u uses invalid whoami -g. id -un && id -G uses id -un (which prints username) and id -G (which prints numeric group IDs, not names). whoami && id -G prints username and numeric group IDs, not names.
  4. Final Answer:

    echo $(whoami) && id -Gn -> Option C
  5. Quick Check:

    Use whoami + id -Gn for username and group names [OK]
Quick Trick: Use whoami for username and id -Gn for group names [OK]
Common Mistakes:
  • Using invalid flags with whoami
  • Confusing numeric IDs with names
  • Not combining commands properly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes