Skip to content

delgroup

Deletes a group on Debian and Ubuntu, or removes a user from a group.

delgroup output

Syntax

delgroup [OPTION]... GROUP
delgroup USER GROUP

Options

Option Description
--only-if-empty Only delete the group if it has no members
--system Only delete the group if it is a system group
--verbose Show every step

Examples

Delete a group:

sudo delgroup --verbose developers
info: Removing group `developers' ...

Only delete a group if nobody is in it:

sudo delgroup --only-if-empty developers
fatal: The group `developers' is not empty!

The group still has members and stays.

Remove a user from a group:

sudo delgroup alice developers
getent group developers
developers:x:1005:bob,nox

Check that the group is gone:

getent group developers
echo $?
2

When do I need it?

  • To clean up team or project groups that are no longer needed
  • To remove groups of uninstalled services
  • To remove a user from a group with the Debian and Ubuntu tools

Use --only-if-empty for cleanups

In cleanup scripts, --only-if-empty prevents you from deleting a group that is still in use.

Files keep the GID

Files that belonged to the deleted group keep its GID. ls -l then shows a number instead of a name. Find them before deleting with sudo find / -xdev -group developers.

Distribution differences

Debian Ubuntu RHEL Arch
delgroup installed installed not available not available
Alternative groupdel developers, gpasswd -d alice developers groupdel developers, gpasswd -d alice developers

addgroup ยท gpasswd