0
0
Linux CLIscripting~10 mins

useradd and userdel in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - useradd and userdel
Start
Run useradd command
System creates user entry
User added successfully?
NoShow error
Yes
User exists
Run userdel command
System removes user entry
User deleted successfully?
NoShow error
Yes
End
The flow shows adding a user with useradd, then deleting with userdel, including success checks.
Execution Sample
Linux CLI
sudo useradd alice
id alice
sudo userdel alice
id alice
Add user 'alice', check user info, delete 'alice', then check user info again.
Execution Table
StepCommandActionResultOutput
1sudo useradd aliceCreate user 'alice'Success
2id aliceCheck user 'alice' infoFounduid=1001(alice) gid=1001(alice) groups=1001(alice)
3sudo userdel aliceDelete user 'alice'Success
4id aliceCheck user 'alice' infoNot foundid: 'alice': no such user
💡
Variable Tracker
VariableStartAfter Step 1After Step 3Final
User 'alice' existenceNoYesNoNo
Key Moments - 2 Insights
Why does the 'id alice' command fail after userdel?
Because userdel removes the user entry, so 'id' cannot find 'alice' anymore, as shown in step 4 of the execution_table.
Does useradd show output when successful?
No, useradd usually does not print output on success, just returns to prompt, as seen in step 1.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output of 'id alice' after useradd?
Auid=1001(alice) gid=1001(alice) groups=1001(alice)
Bid: 'alice': no such user
Cuseradd: user 'alice' already exists
DNo output
💡 Hint
Check step 2 output in the execution_table.
At which step does the user 'alice' get deleted?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the command and action columns in the execution_table.
If you run 'userdel' on a user that does not exist, what would happen?
AUser is deleted successfully
BError message shown
CNew user is created
DNothing happens silently
💡 Hint
Based on key_moments and typical command behavior, userdel errors if user missing.
Concept Snapshot
useradd username  # Adds a new user
userdel username  # Deletes an existing user
useradd shows no output on success
userdel removes user entry
'id username' checks if user exists
Full Transcript
This visual execution shows how the Linux commands useradd and userdel work step-by-step. First, 'sudo useradd alice' creates a new user named alice. The command usually does not print output but succeeds silently. Next, 'id alice' confirms the user exists by showing user id and group info. Then, 'sudo userdel alice' deletes the user alice, again with no output on success. Finally, 'id alice' fails because the user no longer exists, showing an error message. The variable tracker confirms the user existence changes from No to Yes after useradd, then back to No after userdel. Key moments clarify why 'id' fails after deletion and that useradd does not print output on success. The quiz tests understanding of outputs and command effects at each step.