The easiest way to delete a group in Linux is using the groupdel command.
The basic syntax is:
groupdel group_name
For example, the groupdel projects command deletes the project group.
A group can also be deleted by editing the /etc/group or /etc/gshadow files if the latter is present by removing the line corresponding to that group. It is recommended to use the groupdel command because it checks if the group we want to delete is the primary group of a user. If it is, groupdel refuses its deletion. In this case, you must change the primary user group or delete the user account before deleting the group.
Command groupdel can leave behind files that no longer belong to the group (it is deleted), but which have a GID number. We can locate these files using the find command. For example, if we have deleted the project group that has GID 1001, we can find all the files that have this GID using the command below:
find / -id 1001
Once we’ve found all the files that belong to the deleted group, we can decide what to do with them. The best choice is to delete or assign them to another existing group using the chown or chgrp commands.