Users

The groupdel command

Deletes a group from the system: removes its entries from /etc/group and /etc/gshadow.

Syntax

sudo groupdel [opciones] grupoTry it in the terminal →

Most useful options

-f, --forceDeletes the group even if it is the primary group of a user. Use it only when you really need to
-R, --root <carpeta>Applies the change inside a folder used as root, with its own configuration files
-P, --prefix <carpeta>Applies the change to a directory tree without using chroot. Useful for preparing systems that do not boot yet
-h, --helpShows the help and exits

Copy-ready examples

$ sudo groupadd temporal && sudo groupdel temporalcreates a test group and deletes it. It is the safe rehearsal before touching real groups.
$ getent group temporal || echo 'ya no existe'checks that the group is gone.
$ getent group equipo && sudo groupdel equipolooks at the group before deleting it and only then removes it. Check who is inside as well.
$ sudo groupdel -f equipowarning: forces the deletion even if it is a user's primary group. The manual asks you to remove that user first or change their primary group; do not use it as a shortcut.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
groupdel: group 'equipo' does not existThat group does not exist or the name is misspelled.Check the exact name with getent group.
groupdel: cannot remove the primary group of user 'alumno'It is that account's primary group, and it cannot be deleted while it is.Change the account's primary group with sudo usermod -g otro alumno and run the deletion again.
groupdel: cannot lock /etc/group; try again later.Another process holds a lock on the group file while it edits it.Wait a moment and run the command again.

Typical mistakes

  • A group that is some user's primary group cannot be deleted. Change that user to another primary group first.
  • Files that belonged to the group are not deleted: they keep its number. Check them afterwards with find.
  • There is no undo: check the name with getent group before pressing Enter.

Differences from similar commands

  • groupadd: creates groups. groupdel does the reverse and removes their entries.
  • userdel: deletes a user account, not a group. If a user has the group as primary, that user must be dealt with first.
  • getent: reads the group without changing it. Use it before deleting to confirm the name and the members.

FAQ

Does it also delete its members?

No. Only the group entries are removed. Its members' accounts still exist, although they lose the permissions that group gave them.

What do I do with the files the group owned?

They keep the number of the deleted group. Find them with find / -gid 1001 2>/dev/null, replacing 1001 with that number, and reassign them with chown.

Can I delete the sudo group?

Technically yes, but it removes from its members the permissions that group gave them, for example sudo access if the configuration uses it. Check /etc/sudoers first.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course