ID

Print real and valid user and group information

Summary

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

The main purpose

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

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