TrumanWong

ID

Print real and valid user and group information

Summary

id [OPTION]... [USER]...

The main purpose

  • When there is no option, print the specified user ID information.

Options

-a compatibility option, has no practical effect.
-Z, --context Print only the security context of the process.
-g, --group Print only valid group IDs.
-G, --groups Print all group IDs.
-u, --user Print only valid user IDs.
-z, --zero Use null characters instead of the default spaces to separate entries.
--help Display help information and exit.
--version Display version information and exit.

The following options are available only when using one or more of the -u -g -G options:

-n, --name Print names instead of numbers.
-r, --real Print real IDs instead of valid IDs.

Parameters

user (optional): It can be one or more, and the default is the current user.

return value

Returning 0 indicates success, returning a non-zero value indicates failure.

example

[root@localhost ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)

Explanation: UID number of user root = 0, GID number = 0. User root is a member of the following groups:

*The root group GID number is: 0 *The bin group GID number is: 1

  • The daemon group GID number is: 2 *The GID number of sys group is: 3 *adm group GID number is: 4
  • The disk group GID number is: 6 *The wheel group GID number is: 10

Print the username, UID and all groups to which the user belongs. To do this we can use the -a option:

[root@localhost ~]# id -a
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)

To output all the different group IDs, valid, real and supplementary, we can use the -G option to achieve this:

[root@localhost ~]# id -G
0 1 2 3 4 6 10

The results will only show the GID number. You can compare it with the /etc/group file. The following is an example content of the /etc/group file:

Output only valid group IDs. Use the -g option to output only valid group IDs:

[root@localhost ~]# id -g
0

To output specific user information, we can output the UID and GID related to specific user information. Just follow the id command with the username:

[root@localhost ~]# id www
uid=500(www) gid=500(www) groups=500(www)

Notice

  1. This command can display the real and effective user ID (UID) and group ID (GID). UID is a unique identifier for a user. The group ID (GID) corresponds to multiple UIDs; some programs may require UID/GID to run. id makes it easier to find out the user's UID and GID without having to search in the /etc/group file.

  2. This command is a command in the GNU coreutils package. For related help information, please see man -s 1 id, info coreutils 'id invocation'.