• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

userdel Command Examples in Linux

by admin

The userdel command is used to delete user accounts. By default, it does not delete the user’s home directory unless you use the -r option. Deleting the user account removes all references to it. You would have to recreate the account and re-add it to groups in order to resemble the original identity. Use caution before deleting a user account.

Syntax

The syntax of the userdel command is:

$ userdel [options] {user names}
  • userdel [username]: This removes the user entry from the /etc/passwd file, but leaves the user’s home directory and mail intact. This way of deleting a user account is not recommended.
  • userdel -r [username]: This removes the user and the user’s home directory, along with the user’s mail box. This will remove the files owned by the user along with the user’s account from his home directory.

userdel Command Examples

1. Remove a user:

# userdel username

2. Remove a user in other root directory:

# userdel --root path/to/other/root username

3. Remove a user along with the home directory and mail spool:

# userdel --remove username

Conclusion

To remove a user from your system, use the userdel command. Note that the user must be logged out of the system before you can remove him. If you use the userdel command without the -r, the user will be removed from the system but his or her files will be left behind. Use the -r to remove all traces of the user. See the man page for userdel of a list of all the command-line options.

Filed Under: Linux

Some more articles you might also be interested in …

  1. Determining disk usage in Linux using “du” command
  2. free: command not found
  3. “lsb_release: command not found” – Fix in CentOS/RHEL
  4. chfn: command not found
  5. dpkg-deb Command Examples in Linux
  6. How to monitor /etc/shadow and /etc/passwd file for changes with Auditd?
  7. kdialog: command not found
  8. Apache HTTP server – most commonly used containers (special configuration directives)
  9. How systemd-tmpfiles cleans up /tmp/ or /var/tmp (replacement of tmpwatch) in CentOS / RHEL 7
  10. extrace: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright