点击访问 Linux 命令大全 >>
有时,我们需要查询某个用户的 UID、GID 和其所属的组。那么,id 命令就有用武之地了,id 命令语法如下:
[myUser3@localhost ~]$ id --help
Usage: id [OPTION]... [USER]
Print user and group information for the specified USER,
or (when USER omitted) for the current user.
-a ignore, for compatibility with other versions
-Z, --context print only the security context of the current user
-g, --group print only the effective group ID
-G, --groups print all group IDs
-n, --name print a name instead of a number, for -ugG
-r, --real print the real ID instead of the effective ID, with -ugG
-u, --user print only the effective user ID
-z, --zero delimit entries with NUL characters, not whitespace;
not permitted in default format
--help 显示此帮助信息并退出
--version 显示版本信息并退出
如果不附带任何选项,程序会显示一些可供识别用户身份的有用信息。
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
请向<https://translationproject.org/team/zh_CN.html> 报告id 的翻译错误
要获取完整文档,请运行:info coreutils 'id invocation'上面命令,以用户名作为参数。
例1:显示 myUser3 用户的 UID、GID和所属组信息,如下:
[myUser3@localhost ~]$ id myUser3
uid=1003(myUser3) gid=1000(snow) 组=1000(snow)例2:显示当前登录用户的 UID、GID和所属组信息,如下:
[myUser3@localhost ~]$ id
uid=1003(myUser3) gid=1003(myGroup) 组=1003(myGroup) 环境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023例3:使用 -u 选项只显示 myUser3 用户的 UID,如下:
[myUser3@localhost ~]$ id -u myUser3
1003