What is the userdel command in Linux?

The userdel is the command in the Linux operating system. So, It is the command to delete a user account. There is some argument that helps to remove the other user-related information.

How to get help for the userdel command

I always suggest reading the manual page and help. So, It will give you an in-depth introduction to the command.

To get the manual page type the below command,

man userdel

But, to get the only command options, you can type the below command.

userdel --help

Syntax of the userdel command

Now you know how to get help with the userdel command. So, let’s talk about userdel syntax. The syntax of the userdel command is as below,

Syntax: userdel options username

Precondition

  • You must log-in with a root user or a user with sudo privilege to use the userdel command.

Deleting a user account without deleting the home directory

When a user left the company then we have to delete that user in some cases so if you want to delete a user without deleting his/her home directory then you can use the below command.

So, if you want to delete the user without deleting the user files in the home directoryyou can use the below command.

sudo userdel username

For example, if you want to delete a user with the name amit then the command will look like as below.

sudo userdel amit

As a result, you can see in the picture.

userdel command
deleting a user without any argument.

Deleting a user account completely using userdel command with -r argument

So, if you want to delete the user’s home directory and mail spool use the -r flag. This command will delete the user’s complete directories.

sudo userdel -r username

For example, I’m deleting a user whose name is amit using the -r argument. So, You can see the below command.

sudo userdel -r amit 

Deleting a user account forcefully

The user is logged in and you want to delete it somehow then you can use the below command. If you want to delete a user forcefully, then you can use -f

userdel -r -f username

For example, I’m deleting a user whose name is amit forcefully.

sudo userdel -rf amit

Conclusion

In this article, you learned about the userdel command in Linux with essential arguments. But you can see that the implementation is straightforward. So, I hope, you understand. But if you have any questions, you can ask in the comment section.

Also, you can read about

Leave a Reply

Your email address will not be published.