The groups are created in Linux to add the users so that these users can be granted the same privileges of either editing or executing the files. There are different commands to manage these groups, one of them is the groupdel command. These groups can be deleted when there is no need for them to use the groupdel command.
We can delete all types of user groups using the groupdel command, in this article, we have explained in detail the usage of the groupdel command.
How to use the groupdel command to delete groups in Linux
The groupdel command is used to delete the user groups and is always used either by the root user or the system user with the help of the sudo command. The general syntax of using the groupdel command:
$ groupdel [options] [groupname]
The different options can be used with the groupdel command, but before using any options, we will use the groupdel command for deleting the groups. The group’s information is saved in the file, /etc/group, so we will display the last ten lines of the file using the tail command:
$ tail /etc/group
These are the groups displayed in the output, let say, we want to delete the group, myLinuxFossGroup, using the groupdel command:
$ sudo groupdel myLinuxFossGroup
To confirm the deletion of the group, myLinuxFossGroup, again display the /etc/group file using the tail command:
$ tail /etc/group
The group has been deleted successfully, if there is any group that does not delete then we can use the “-f” flag which forcibly deleted the group. To delete the group mygroup3 using the “-f” flag, use the command:
$ sudo groupdel -f mygroup3
We can also use the grep command to confirm that the “mygroup3” has been deleted successfully.
$ grep '^mygroup3' /etc/group
Nothing has been displayed in the output, which implies the group, mygroup3, does not exist in the file, /etc/group. To get more help about the groupdel command, use the “-h” flag with the groupdel command:
$ sudo groupdel -h
The groupdel command is used to delete the user group when is no more need of the group and also remove it from the file /etc/group. This command doesn’t delete the configuration files related to the group but deletes all the entries and account files related to that group. In this article, we have discussed the usage of the groupdel command in Linux to delete the groups with the help of examples.
The Best Linux Tutorials Website