Linux Basic Commands

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