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.
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:
- Run the following command to delete a group using the groupdel command:
$ sudo groupdel groupname
- Run the following command to delete a group using the delgroup command:
$ sudo delgroup groupname
$ 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.
$ 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.