How to Delete a Group in Linux - groupdel Command With Examples

Linux groupdel command is used to delete a group. This is a very powerful command, so use it carefully. It’s a common Linux command and you can use it in all the Linux distributions such as Ubuntu, CentOS, Debian, Fedora, etc.

Let’s look at some examples of deleting a group in Linux using groupdel command.

Linux Delete Group with No Users

For the example, I have already created few groups and a test user. Let’s look at the simple example to delete a group which has no users.

Deleting a Group with Users

I have created a group test_users and added journaldev user to it. Let’s confirm this using the getent and id commands.

Let’s see what happens when we delete this group.

The group is deleted and removed from the user groups list.

Can we Delete System Group using groupdel command?

Can we remove a system level group using groupdel command?

Let’s try to remove sudo group using the groupdel command and see what happens.

Looks like we were able to remove the “sudo” user group. Let’s see what happens to the superuser privileges of the user.

Looks like sudo privileges are removed too, which is obvious because we removed the “sudo” group itself.


Deleting Primary Group of a User

When we create a new user, a new group with the same name is also created and assigned to it. This is called the primary group of the user.

Let’s see if we can remove the primary group of the user?

Let’s look at the help option to see if there is any way to overcome this error message?

The output clearly states that we can use the -f option to delete the primary group of the user.

We were able to remove the primary group of the user. But, the “gid=1003” is still showing in the user information. So, I don’t understand what is the use case for this feature.

Linux groupdel command exit values

If you are using groupdel command in a shell script, it’s better to know the exit values to check whether command executed fine or got some error.

Exit Value Description
0 success
2 invalid command syntax
6 the group doesn’t exist
8 can’t delete user primary group
10 can’t update group information files


Linux groupdel command is very powerful and it can remove system groups too. If you are using this command to remove a group, please take extra care because it’s irreversible and it can create major issues if the group had many users.


By admin

Leave a Reply