userdel

Used to delete a given user and files related to the user

Supplementary instructions

userdel command is used to delete a given user and user-related files. If no option is added, only the user account will be deleted, but the related files will not be deleted.

grammar

userdel(option)(parameter)

Options

-f: Forcefully delete the user, even if the user is currently logged in;
-r: When deleting the user, delete all files related to the user.

Parameters

Username: The username to be deleted.

Example

The userdel command is very simple. For example, we now have a user linuxde whose home directory is located in the /var directory. Now let’s delete this user:

userdel linuxde #Delete user linuxde, but do not delete its home directory and files;
userdel -r linuxde # Delete user linuxde, and delete its home directory and files together;

Please do not use the -r option lightly; it will delete the user and all the user's files and directories. Remember that if there are important files in the user directory, please back them up before deleting them.

In fact, there is the simplest way, but this method is a bit unsafe, that is, directly delete the record of the user you want to delete in /etc/passwd; but it is best not to do this, /etc/passwd is extremely dangerous. Important files may be mishandled by you accidentally.