Users
The groupdel command
Deletes a group from the system: removes its entries from /etc/group and /etc/gshadow.
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 exitsCopy-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
| Message | Cause | Fix |
|---|---|---|
| groupdel: group 'equipo' does not exist | That 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
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