groupdel
Delete a group from the system
TLDR
Delete an existing group
SYNOPSIS
groupdel [OPTION]... group
PARAMETERS
-f, --force
Force deletion even if the group is primary for users or has issues; continues despite errors
-h, --help
Display usage help and exit
-R, --remove
Remove all member users from the group before deletion (fails if primary group)
-V, --version
Output version information and exit
DESCRIPTION
groupdel is a system administration command used to remove a specified group from the system's group database files, primarily /etc/group and /etc/gshadow. It ensures that the group entry is completely deleted, preventing further use of that group ID (GID) for new users or processes.
By default, groupdel refuses to delete a group if it is the primary group for any user or if users are still members of it, to avoid orphaning user accounts or breaking permissions. This safety mechanism protects system integrity.
The command scans and updates relevant files atomically where possible. After deletion, any files owned by the deleted GID may appear with numeric ownership or require manual cleanup using tools like chown or find. It does not automatically reclaim the GID or alter filesystem ownership.
Common use cases include cleaning up after userdel or during system decommissioning. Administrators must run it as root via sudo. Incorrect usage can lead to permission issues or security gaps if system groups are targeted.
CAVEATS
Cannot delete groups with active processes or primary user assignments without -f or -R; never delete essential groups like root (GID 0); orphaned GIDs on files require manual fix; run as root only.
AFFECTED FILES
Updates /etc/group, /etc/gshadow; may flag files with 'deleted' GID if -R used.
EXIT CODES
0: success
2: invalid command syntax
6: group doesn't exist
8: group not empty
10: can't lock files
12: other errors.
HISTORY
Originated in early Unix SVR4; in Linux, part of shadow-utils package since mid-1990s for secure password/group management; evolved to include force/remove options for safer automation.


