How to Delete Group in Linux Using groupdel and delgroup

Delete Group in Linux

On Linux operating systems user groups are defined in the /etc/group file. This is a simple text file that should not be edited directly. What if you want to delete group details? Well, Linux provides command-line tools that will allow you to do it.

Prerequisites

This guide makes assumptions that you have a complete Ubuntu server set up with users already added to the system.

In this guide, we will show you how to use the groupdel command and delgroup commands to delete all the group information.

How to delete group in Linux where groupname is the name of the group:

  1. Run the following command to delete a group using the groupdel command:

$ sudo groupdel groupname

  1. Run the following command to delete a group using the delgroup command:

$ sudo delgroup groupname

or

$ sudo delgroup --group groupname

You can list the existing groups using the following command:

$ cat /etc/group

How about if you want to find out which groups a particular user belongs to. You can retrieve that information using the following command:

$ groups username

You can restrict deleting groups to if the group is a system group. This protects from accidentally deleting non-system groups.

Read Also  Upgrade Ubuntu 18.04 LTS to Ubuntu 20.04 LTS (Focal Fossa)

$ sudo delgroup --system --group groupname

You can also backup group files before deleting the group using this command:

$ sudo delgroup --backup --group groupname

If you just want to remove a user from a group you can use the following command:

$ sudo deluser username groupname

Conclusion on Delete Group in Linux

The above commands work on all major Linux distros such as Arch Linux, CentOS, Debian, Fedora, RHEL, and Ubuntu among others. Meanwhile, you can follow this guide on how to delete users from Linux found here or this one about how to add a user in Linux systems.