id command in Linux is used to display user and group identity information. It provides detailed information about the current user or specified user, such as user ID (UID), group ID (GID), and group memberships.
The basic syntax of the
id command is as follows:
id [options] [username]
Here’s an explanation of the components:
id: The command itself.
[options]: Optional flags that modify the behavior of the command.
[username]: Optional username to retrieve information for. If not specified, it displays information for the current user.
Here are some commonly used options with the
--user: Display only the user ID (UID).
--group: Display only the group ID (GID).
--groups: Display the group IDs (GIDs) and group names that the user is a member of.
--name: Display the user or group name instead of the ID.
--real: Display the real user ID instead of the effective user ID.
- Display user and group IDs for the current user:
uid=1000(john) gid=1000(john) groups=1000(john),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),116(lpadmin),126(sambashare)
- Display only the user ID (UID):
- Display the group IDs (GIDs) and group names for the specified user:
id -Gn alice
alice : alice adm cdrom sudo dip plugdev lpadmin sambashare
id command provides useful information about user and group identities, which is helpful for system administration, user management, and troubleshooting purposes in Linux.