/**/ How to use groupdel command in Linux? - Dextutor

How to use groupdel command in Linux?

Use

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.

Syntax

groupdel [options] GROUP

Example

The snapshot below shows the list of some groups that exist in the system.

Before groupdel command

Next, we use groupdel command to delete the Redhat group. The output shows that the group is deleted from the system.

groupdel command in linux
groupdel command in linux

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.

Options used with groupdel command

1.To display help message

-h: option displays the help message and exits

2. To apply changes in the CHROOT_DIR

-R: option applies changes in the CHROOT_DIR directory.

Files related with groupdel command in Linux

/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

Sample Questions

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?

PPT on groupdel command

Video on groupdel command

Related Commands

groupadd
groupmod
useradd
usermod
userdel

Leave a Comment