The id command is used to display user ID (UID) and group ID (GID) information. Entering the command with no options displays information about the user who is currently logged in. You can also specify a user name as an option to display ID information about a specific user.
Syntax
The syntax of the id command is:
# id [options] [user name]
Command line Options
Option | Description |
---|---|
-u | Print the effective user ID and exit. |
-g | Print the effective group ID and exit. |
-G | Print the IDs of all other groups to which the user belongs. |
-n | Print names (for users and groups) rather than numeric IDs. Must be combined with -u, -g, or -G. For example, id -Gn produces the same output as the groups command. |
-r | Print login values instead of effective values. Must be combined with -u, -g, or -G. |
If you encounter below error while running the id command:
id: command not found
you may try installing the below package as per your choice of distribution:
Distribution | Command |
---|---|
OS X | brew install coreutils |
Debian | apt-get install coreutils |
Ubuntu | apt-get install coreutils |
Alpine | apk add coreutils |
Arch Linux | pacman -S coreutils |
Kali Linux | apt-get install coreutils |
CentOS | yum install coreutils |
Fedora | dnf install coreutils |
Raspbian | apt-get install coreutils |
id Command Examples
1. To print the current user ID:
# id
2. To ge the all the identification information of the a user:
# id -a # id -a mike
3. To print only the security context of the user:
# id -Z # id --context
4. To print only the effective group ID:
# id -g # id --group
5. To print all the group IDs:
# id -G # id --groups
6. To print the name instead of number:
# id -n # id --name
7. To print the real ID instead of effective ID:
# id -r # id --real
8. To print only the effective ID:
# id -u # id --user
9. To get the help for ID command:
# id --help
10. To get the version of the ID command:
# id --version