userdel Command in Linux with Examples

This tutorial explains Linux “userdel” command, options and its usage with examples.

userdel – Delete a user account and related files

Description :

The userdel command modifies the system account files, deleting all entries that refer to login. The named user must exist.

Usage :

userdel [options] username

advertisement
advertisement

Options :

-r
Files in the user’s home directory will be removed along with the home directory itself and the user’s mail spool. Files located in other file systems will have to be searched for and deleted manually.
-h, –help
Display a help message, and exit.
-f, –force
This option forces the removal of the user account, even if the user is still logged in. It also forces userdel to remove the user’s home directory and mail spool, even if another user uses the same home directory or if the mail spool is not owned by the specified user.

Exit Values

The userdel command exits with the following values:

0  success
1  can't update password file
2  invalid command syntax
6  specified user doesn't exist
8  user currently logged in
10 can't update group file
12 can't remove home directory

Examples :

1. To remove the user abc account from the local system / server / workstation, enter:

# userdel vivek

2. To remove the user’s home directory pass the -r option to userdel, enter:

advertisement
# userdel -r abc

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

advertisement
If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.