How to delete group in Linux using groupdel command

last updated in Categories , , , , ,

I am a new Linux system user and sysadmin too. How can I delete a group in Linux operating system using the command line option? How do I remove a group from Linux?

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

  1. Delete a group named sales that exist on Linux, run: sudo groupdel sales
  2. Another option to remove a group called ftpuser in Linux, sudo delgroup ftpusers
  3. To view all group names on Linux, run: cat /etc/group
  4. 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
Linux display group names
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

Delete group in Linux using delgroup command

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.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at www.nixcraft.com

Historical Comment Archive

1 comment

    Still, have a question? Get help on our forum!