
How to Use the id Command in Linux?
Understanding the id
Command in Linux
The id
command is a fundamental utility in Linux that provides valuable information about the current user’s identity as well as group memberships. This command can be particularly useful for system administrators and users who need to know their permissions and roles within the system.
Basic Usage
At its core, the id
command displays the current user’s ID (UID), the primary group ID (GID), and any additional groups to which the user belongs. The simplest way to use the command is:
id
This will output information that might look something like this:
uid=1001(johndoe) gid=1001(johndoe) groups=1001(johndoe),27(sudo),30(dip)
Options for id
Here are some useful options you can use with the id
command:
-
Display the Current User’s Identity:
- To show the current user’s name, you can use:
id -un
- Alternatively, the following command achieves the same result:
id --user --name
- To show the current user’s name, you can use:
-
Display the Current User Identity as a Number:
- To get the UID as a number, use:
id -u
- This command is useful when you need a numeric value for scripting or other purposes.
- To get the UID as a number, use:
-
Display the Current Primary Group Identity:
- If you want to see the name of the current primary group, use:
id -gn
- And to display the primary group ID as a number:
id -g
- If you want to see the name of the current primary group, use:
-
Display Information for an Arbitrary User:
- To retrieve the UID, GID, and groups for a specific user, simply run:
id username
- Replace
username
with the actual user’s name.
- To retrieve the UID, GID, and groups for a specific user, simply run:
Conclusion
The id
command is a simple yet powerful tool that enhances your ability to manage user identities and permissions in Linux. By understanding how to utilize its various options, you can efficiently retrieve important information about user and group identities.
For further details, you can explore the official GNU documentation here.