Preface
Introduction
Practice Setup
Linux Architecture
Basic Commands
Basic file management or operations on file
User administration
Networking
Linux Interview Questions

 

 

Userdel

Basically this command is used to delete the user. Observe the following examples to get more knowledge on userdel command.

 

Example-1:

Deleting the user account:

[root@sys2 ~]# userdel steve
[root@sys2 ~]# useradd steve

 

useradd: warning: the home directory already exists.

Not copying any file from skel directory into it.

Creating mailbox file: File exists

In the above few lines. We remove the user steve and again tried to add the user steve. But the user cannot be created because the home directory exists.

 

Note: 

using userdel command alone we can delete the user but not the home directories of the user.

 

Example-2:

Deleting the user account along its home directory:

Using ‘-r’ option with userdel command we can delete the user account along with its home directory.

[root@sys2 ~]# userdel -r steve

 

Check the appropriate directories weather they are deleted or not.

 

Note: 

Make sure that you have a backup of users data before using this option.

 

Example-3:

Deleting the user forcefully:

Sometimes when we rare trying to remove the user they can’t delete because they are already logged in or any process belongs to the particular user is running in the background.

 

For example the user steve is logged in but, I am trying to delete the user steve as shown delow.

[root@sys2 ~]# userdel -r steve
userdel: user steve is currently logged in

 

To delete the user forcefully we use “-f ‘ option with userdel command .

[root@sys2 ~]# userdel -f steve
[root@sys2 ~]# grep steve /etc/passwd

 

Note: 

Kill all the process of user before deleting the particular user.

 

 

Topic review through questions: