Bird
Raised Fist0
Linux CLIscripting~10 mins

whoami and id commands in Linux CLI - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - whoami and id commands
Start
↓
Run 'whoami'
↓
Display current username
↓
Run 'id'
↓
Display user and group info
↓
End
The flow shows running 'whoami' to get the username, then 'id' to get detailed user and group info.
Execution Sample
Linux CLI
whoami
id
This runs 'whoami' to show the current username, then 'id' to show user and group IDs.
Execution Table
StepCommandActionOutput
1whoamiGet current usernamealice
2idGet user and group IDsuid=1001(alice) gid=1001(alice) groups=1001(alice),27(sudo)
💡 Commands finish after displaying user info.
Variable Tracker
VariableStartAfter whoamiAfter idFinal
usernameundefinedalicealicealice
uidundefinedundefined10011001
gidundefinedundefined10011001
groupsundefinedundefined1001(alice),27(sudo)1001(alice),27(sudo)
Key Moments - 2 Insights
Why does 'whoami' only show the username but 'id' shows more details?
'whoami' simply prints the current username (see execution_table step 1), while 'id' shows user ID, group ID, and group memberships (see step 2).
Can 'id' show groups other than the main group?
Yes, 'id' lists all groups the user belongs to, not just the main group, as shown in the groups output in execution_table step 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output of the 'whoami' command?
Aalice
Buid=1001(alice)
C1001
Dsudo
💡 Hint
Check the output column in execution_table row 1 for 'whoami' command.
At which step does the command show the user's group memberships?
AStep 1
BStep 2
CBoth steps
DNeither step
💡 Hint
Look at the 'Action' and 'Output' columns in execution_table for group info.
If the username was 'bob' instead of 'alice', how would the 'whoami' output change?
AIt would still show 'alice'
BIt would show the user ID number
CIt would show 'bob'
DIt would show group names
💡 Hint
Refer to variable_tracker for username changes after 'whoami'.
Concept Snapshot
whoami: shows current username
id: shows user ID, group ID, and groups
Use whoami for simple username
Use id for detailed user info
Both help identify current user context
Full Transcript
This visual execution shows how the 'whoami' command outputs the current username, and the 'id' command outputs detailed user and group information. First, 'whoami' runs and prints 'alice'. Then, 'id' runs and prints user ID, group ID, and group memberships. Variables like username, uid, gid, and groups update accordingly. Beginners often wonder why 'whoami' shows less info than 'id'—it's because 'whoami' only prints the username, while 'id' shows more details. Also, 'id' lists all groups the user belongs to, not just the main group. The quiz checks understanding of outputs and variable changes.

Practice

(1/5)
1. What does the whoami command display when run in a Linux terminal?
easy
A. The current logged-in username
B. The current directory path
C. The list of running processes
D. The system's IP address

Solution

  1. Step 1: Understand the purpose of whoami

    The whoami command is designed to show the username of the current user logged into the shell.
  2. Step 2: Compare with other options

    Options A, B, and C describe other commands or outputs unrelated to whoami.
  3. Final Answer:

    The current logged-in username -> Option A
  4. Quick Check:

    whoami = username [OK]
Hint: Remember: whoami = "Who am I?" shows your username [OK]
Common Mistakes:
  • Confusing whoami with pwd (current directory)
  • Thinking whoami shows system info
  • Mixing up with commands showing processes
2. Which of the following is the correct syntax to display your user ID and group information in Linux?
easy
A. user id
B. id
C. whoami -u
D. showid

Solution

  1. Step 1: Identify the correct command syntax

    The command id without arguments shows user ID, group ID, and group memberships.
  2. Step 2: Check other options for validity

    Options A, B, and D are invalid commands or incorrect syntax for this purpose.
  3. Final Answer:

    id -> Option B
  4. Quick Check:

    id shows user and group info [OK]
Hint: Use simple id to see user and group IDs [OK]
Common Mistakes:
  • Adding wrong flags to whoami
  • Typing commands with spaces like 'user id'
  • Using non-existent commands like showid
3. What will be the output of the command id -u if the current user has user ID 1001?
medium
A. 1001
B. uid=1001(user)
C. user=1001
D. id: invalid option

Solution

  1. Step 1: Understand the -u option of id

    The -u option prints only the numeric user ID (UID) of the current user.
  2. Step 2: Match output format

    The output will be just the number 1001, not a string with 'uid=' or other text.
  3. Final Answer:

    1001 -> Option A
  4. Quick Check:

    id -u = UID number only [OK]
Hint: id -u prints only your numeric user ID [OK]
Common Mistakes:
  • Expecting full id output with -u
  • Confusing uid= prefix with plain number
  • Thinking -u is invalid option
4. You run the command id -u but get an error: "id: invalid option -- 'U'". What is the likely cause?
medium
A. You ran the command as root user
B. Your Linux system does not support the id command
C. You used a space between id and -u
D. You typed a capital U instead of lowercase u

Solution

  1. Step 1: Check the option case sensitivity

    Linux commands are case sensitive. The option -u is lowercase. Using uppercase -U instead of lowercase -u can cause errors.
  2. Step 2: Analyze the error message

    The error "invalid option -- 'U'" suggests the option letter was not recognized, likely due to uppercase letter typed instead of lowercase.
  3. Final Answer:

    You typed a capital U instead of lowercase u -> Option D
  4. Quick Check:

    Linux options are case sensitive [OK]
Hint: Check option letter case carefully; Linux is case sensitive [OK]
Common Mistakes:
  • Typing uppercase instead of lowercase option
  • Assuming id command is missing
  • Adding spaces incorrectly in command
5. 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
A. id -un && id -G
B. whoami -g && id -u
C. echo $(whoami) && id -Gn
D. whoami && id -G

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]
Hint: 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
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard