Skip to content

id Command: Display User and Group Information

Summary

The id command displays user and group information, including the user ID (UID), group ID (GID), and group memberships.

Introduction

The id command is a fundamental utility in Linux that provides detailed information about a user's identity. It allows you to quickly retrieve the UID, GID, and the list of groups a user belongs to. This information is crucial for understanding user permissions and access control within the system.

Use case and Examples

Displaying Information for the Current User

id
This command displays the UID, GID, and group memberships for the user executing the command.

Displaying Information for a Specific User

id username
Replace username with the actual username. This will display the UID, GID, and group memberships for that specific user. For example:
id john
This will display the information for user "john".

Displaying Only the User ID

id -u
This command displays only the numerical User ID of the current user.

Displaying Only the Group ID

id -g
This command displays only the numerical Group ID of the current user.

Displaying Only the Group Names

id -Gn
This command displays only the names of groups the user belongs to, separated by spaces.

Commonly used flags

Flag Description Example
-u Print only the effective user ID. id -u
-g Print only the effective group ID. id -g
-G Print all group IDs. id -G
-n Print user and group names instead of numbers. Requires -u, -g, or -G. id -Gn
-r Print the real (as opposed to effective) UID/GID. id -ru (real UID)
-z Delimit entries with NUL rather than whitespace, for use with xargs. id -Gz | xargs -0 somecommand


Share on Share on

Comments