How to delete a group in Linux?


A group in Linux is a list of users, the permissions defined for a group apply to all the users of that group. It helps in organizing the user accounts on a system. In Linux /etc/group file defines the groups, this file can be modified using commands such as groupadd, groupdel, etc.

In this article, we will see how to delete a group in Linux using the groupdel command.

Display the list of all the groups in Linux

There are various ways by which you can see the list of groups in a Linux system. One way is to display the content of /etc/group file by using less, more, or cat commands –

less /etc/group

It will display groups as given in the image below.

list group

Each line is consist of four fields each of them are separated by a colon –

  • Group name
  • Encrypted password
  • Group id
  • List of comma-separated users who are the member of that group

Alternatively, you can use the groups command to display the list of groups in a system –

groups

Delete or remove a group from Linux

Look at the list that is displayed using the previous commands and identify the group that you want to delete from your system. Now use the groupdel command which is used to remove a group from the system as given below –

sudo groupdel group_name

Removing or deleting a group requires root privileges so do not forget to use the sudo before the command.

How to delete a group by its group id ( gid )?

Suppose you have the group ids such as 1001, 2000, etc and you want to delete them then first you need to find the group name associated with a gid. Once you have the group name you can simply use the groupdel command in your terminal to delete it.

Use the following command to find group name from gid –

getent group GID | cut -d: -f1

Example –

getent group 1001 | cut -d: -f1

Now once you find the group name use the following command to delete it –

sudo groupdel group_name

How to create a group in Linux?

After deleting a group if you want to create a new group in your system then you can use the groupadd command in your terminal –

sudo groupadd group_name

Conclusion

That is how you can delete a group in Linux. Now if you have any queries then do not forget to write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Exit mobile version