The following command will list all of the groups of
someUser (the primary group and the supplementary groups):
But is there a way to only get the primary group?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
See the FreeBSD handbook (information also valid for Linux):
Group ID (GID)
The Group ID (GID) is a number used to uniquely identify the primary group that the user belongs to. Groups are a mechanism for controlling access to resources based on a user's GID rather than their UID. This can significantly reduce the size of some configuration files and allows users to be members of more than one group. It is recommended to use a GID of 65535 or lower as higher GIDs may break some software.
If so, running
id <username> will show
id <username> uid=1000(<username>) gid=1000(<username>) groups=1000(<username>),4(adm),24(cdrom),27(sudo)
If you want the command to return just the primary group name, see
-g, --group print only the effective group ID -G, --groups print all group IDs -n, --name print a name instead of a number, for -ugG
id -gn <username> should give you what you want.