Blog

03/06/2019

How to delete group in Linux using groupdel command



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

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.

Posted by: SXI ADMIN

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.

14/08/2019

How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...
14/08/2019

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....
12/08/2019

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...