8. userdel

userdel Command in Linux

The userdel command is used to delete a user account from the system.

⚠️ Requires root privileges, so use it with sudo.

🔹 Basic Syntax:

userdel [username]

🔹 Example:

userdel ashwin

👉 This command deletes the user account named ashwin.

🔸 Note: By default, this does not delete the user's home directory.

🔹 Delete user and their home directory:

userdel -r ashwin

👉 This removes:

  • The user account ashwin

  • Their home folder: /home/ashwin

  • Their mail spool and personal files


🔹 How to confirm user is deleted:

cat /etc/passwd | grep ashwin

👉 If no output, the user is deleted.


🔹 Warning:

Don’t delete users while they are logged in.
It can cause
system issues. First, check:

who
Try with Linux Practice