groupdel's Examples

remove the given group

groupdel myfriends

if the group is not there the output will be dispalyed the group is not there

$ getent group | grep mygroup

Deletes the group developers from the system.

sudo groupdel developers

Output (if group exists):

developers:x:1001:

(If no output, the group does not exist.)

getent group developers

Lists all groups in the system.

cat /etc/group
or
getent group

Explanation:

  • Removes username from groupname.
  • Then deletes groupname.

sudo gpasswd -d username groupname
sudo groupdel groupname

Explanation:

  • Moves username to anothergroup before deleting oldgroup.

sudo usermod -g anothergroup username
sudo groupdel oldgroup

Explanation:

  • Removes username from groupname before deletion.

sudo deluser username groupname
sudo groupdel groupname

Explanation:
Deletes a system group (groups with GID < 1000).

sudo groupdel -r sysadmins

Explanation:

  • Deletes the testers group.
  • Removes its home directory (if applicable).

sudo groupdel testers && sudo rm -rf /home/testers

Explanation:
Forces deletion of testers, even if users are still members.

sudo groupdel -f testers

Explanation:
If there’s no output, the group has been deleted.

getent group groupname

Deletes a user group.

sudo groupdel developers

DevOpsSchool
Typically replies within an hour

DevOpsSchool
Hi there 👋

How can I help you?
×
Chat with Us