Get Group ID (GID) in Linux

In Linux system, each group is identified by unique identifier known as group ID or GID. It is used to determine which system resources users of that group can access. This tutorial shows how to get group ID (GID) in Linux.

In order to get GID by group name, use getent command to get information about specific group and cut command to extract the GID:

getent group syslog | cut -d: -f3

Output example:

110

To find out GID of primary group for current user, use id command with -g option:

id -g

Provide username as argument to get GID of primary group for specific user:

id -g james

To get GID of all groups associated with a current user, run id command with -G option:

id -G

Output example:

1000 4 24 27 30 46 116

The first GID identifies primary group. Other GIDs identifies secondary groups.

Provide username as argument to get GID of all groups for specific user:

id -G james

Leave a Comment

Your email address will not be published.