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
This command displays the UID, GID, and group memberships for the user executing the command.Displaying Information for a Specific User
Replaceusername
with the actual username. This will display the UID, GID, and group memberships for that specific user. For example: This will display the information for user "john". Displaying Only the User ID
This command displays only the numerical User ID of the current user.Displaying Only the Group ID
This command displays only the numerical Group ID of the current user.Displaying Only the Group Names
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 |