Introduction – The /etc/group file is a text file that defines the groups on the Linux system. There is one entry per line. Do not edit this file manually. You must use either use the groupdel command or delgroup command that modifies the Linux system account files, deleting all entries that refer to GROUP from the /etc/group file. This page shows how to remove a group in Linux.
How to delete group in Linux
- Delete a group named sales that exist on Linux, run: sudo groupdel sales
- Another option to remove a group called ftpuser in Linux, sudo delgroup ftpusers
- To view all group names on Linux, run: cat /etc/group
- Print the groups a user say vivek is in: groups vivek
Let us see some examples in details.
How to remove group in Linux using groupdel command
The syntax for the groupdel command is:
sudo groupdel {group-name-here}
To delete a group named staff, enter:
sudo groupdel staff
One can view a list of groups on Linux using either cat command or grep command/egrep command:
cat /etc/group
grep '^sales' /etc/group
egrep '^(users|root|sales)' /etc/group
Use the wc command to count number of groups in your Linux server:
wc -l /etc/group
To delete a group called ftpusers, enter:
sudo groupdel ftpusers
Deleting a group in Linux using delgroup command
In this example, you are going to delete a group named sales using delgroup. The syntax is:
sudo delgroup {group}
sudo delgroup sales
grep '^sales' /etc/group
How to remove the user from a group
The syntax is as follows to delete the user named tom from a group called cartoons:
sudo deluser {user} {group}
sudo deluser tom cartoons
Conclusion
This page explained the groupdel/delgroup commands that modifies the system account files /etc/group and others to remove the group. Please note that the given group must exist when you execute groupdel command.
The page has been updated to fix typos and images.