groupdel command in Linux used to delete all entries related to a group in the system. The named group must exist. But, this command can be user by superuser only.
groupdel [options] GROUP
The snapshot below shows the list of some groups that exist in the system.
Next, we use groupdel command to delete the Redhat group. The output shows that the group is deleted from the system.
Remember, you can not delete a primary group of a user until to remove the user. Also, as an admin you have to manually check that al files related to the groups are deleted.
-h: option displays the help message and exits
-R: option applies changes in the CHROOT_DIR directory.
/etc/group – contains the information about the groups in the system.
/etc/gshadow – contains the secure information about the groups in the system
The exit values related with groupdel are:
0 – which means success
2 – invalid command syntax
6 – specified group doesn’t exist
8 – can’t remove user’s primary group
10 – unable to update group file
Q1. Can you delete two groups G1 and G2 simultaneously using groupdel command as below?
#userdel G1 G2
Q2. As an admin you want to delete the group G1. Smith is a member of group G1. How can you delete G1?