>_cmd.script

groupdel

Delete an existing group

Groupsintermediategroupsusersadministration
groupdel [OPTIONS] GROUP_NAME
Try it

By CMD Script Team · 3 min read · Last updated

On this page
SYNTAX
groupdel [OPTIONS] GROUP_NAME
[X]
Optional — the command works without it
X...
Repeatable — you can pass more than one
ALLCAPS
A placeholder — replace it with your own value

Options

Command options and flags
FlagDescription
-f, --forceDelete the group even when it is still a user's primary group; use with extreme care
-R, --root CHROOT_DIRApply changes inside the specified chroot directory
-P, --prefix PREFIX_DIRApply changes under a directory prefix without chrooting

Distribution compatibility

  • Ubuntu
  • Debian
  • Fedora
  • Arch
  • macOS (not available; use dscl for local groups)

What it does

groupdel removes an existing group's account-database entry. It does not delete user accounts, delete files, or rewrite file ownership. Files retain their numeric GID, which may display as a number after the group name no longer resolves.

Before deletion, reassign any user whose primary group is the target. The --force option's behavior and availability can vary across implementations, so it is not a substitute for a planned migration.

Beginner examples

  • getent group developers — inspect the group through NSS before changing it.
  • sudo groupdel developers — remove the group entry.
  • getent group developers — confirm that the name no longer resolves afterward.
  • On macOS, use Directory Service tooling such as dscl; groupdel is not available.
getent group developers
sudo groupdel developers

Advanced examples

Record the numeric GID, audit name-based ownership, delete the group, and then audit by the saved number:

old_gid=$(getent group developers | cut -d: -f3)
find / -group developers -ls 2>/dev/null
sudo groupdel developers
find / -gid "$old_gid" -ls 2>/dev/null
  • Use sudo groupdel -R /mnt/rescue developers to modify an account database inside a chroot tree when your implementation supports it.
  • Use -P only after checking the local manual; prefix mode changes files below a path without performing a chroot.

Try it yourself

A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.

Common mistakes

  • Deleting a group before reassigning users who have it as their primary group.
  • Assuming deletion removes or reassigns group-owned files. Their old numeric GID stays on disk.
  • Using --force without checking the platform's documented behavior and availability.
  • Searching only /etc/group even though NSS may resolve the group elsewhere.
  • Reusing the deleted GID before all old file ownership has been found and migrated.

Tips

  • Use getent group GROUP instead of reading only /etc/group when NSS is configured.
  • Check primary groups with account tools such as getent passwd before deletion.
  • Save the GID in change records so post-deletion files can still be identified.
  • Limit filesystem searches to relevant mounts when a full find / would be costly.

Best practices

  • Record the group's numeric GID before deletion.
  • Reassign every affected user's primary group and verify the result first.
  • Migrate files owned by the group intentionally; do not assume account deletion changes their ownership.
  • Audit again by numeric GID after deletion, before allowing that number to be reused.
  • Back up the relevant account databases or use managed identity tooling with rollback.

Real-world use cases

  • Retiring a project group after its shared files have moved to a successor group.
  • Removing a local group that was replaced by a centrally managed directory group.
  • Cleaning a chroot's account database during image maintenance.
  • Decommissioning a service group while preserving and explicitly migrating its data.

Common interview questions

  • Does groupdel delete group-owned files? No. Files keep their numeric GID.
  • Why record the GID first? After deletion, the name may no longer resolve, but the number still lets you find orphaned ownership.
  • Can a primary group be deleted safely? Reassign it for every affected user first; forcing deletion is implementation-dependent and risky.
  • What is the macOS equivalent? Local groups are managed with Directory Service tools such as dscl, not groupdel.

Frequently Asked Questions

Does groupdel delete users or files?

No. It removes the group account entry but does not delete user accounts, files, or directories.

What happens to files owned by the deleted group?

Their numeric GID remains on disk and may appear without a group name until ownership is migrated or that GID is assigned again.

Can I delete a user's primary group?

Reassign the user's primary group first. Force behavior and availability vary by implementation and can leave an unsafe configuration.

Is groupdel available on macOS?

No. macOS manages local groups with Directory Service tools such as dscl.

Cheat sheet

Download a quick-reference cheat sheet for groupdel.

groupdel Command in Linux – Syntax, Examples, Options & Tutorial | CMD Script