The userdel
command is used in Linux to delete a user account from the system. When a user is deleted, their home directory and mail spool can also be removed, depending on the options used.
The basic syntax of the userdel
command is as follows:
userdel [options] [username]
-r
: Remove the user’s home directory and mail spool along with the user account.-f
: Force the removal of the user account, even if the user is currently logged in.-Z
: Remove any SELinux user mapping for the user account.userdel john
userdel -r john
userdel -f john
userdel -Z john
-r
option with caution, as it will permanently delete the user’s home directory and all its contents.-f
option intentionally.