Linux基础命令[19]-id

文章目录

    • [1. id 命令说明](#1. id 命令说明)
    • [2. id 命令语法](#2. id 命令语法)
    • [3. id 命令示例](#3. id 命令示例)
      • [3.1 不加参数](#3.1 不加参数)
      • [3.2 -u/-g/-G(用户、组、所属组)](#3.2 -u/-g/-G(用户、组、所属组))
      • [3.3 -gr/-Gr/-ur(有效ID)](#3.3 -gr/-Gr/-ur(有效ID))
    • [4. 总结](#4. 总结)

1. id 命令说明

id:显示真实有效的用户ID(UID)和组ID(GID),十分方便,不用再查找 /etc/groop(里面有全部用户的信息)。基本信息如下:

复制代码
Usage: id [OPTION]... [USERNAME]
Print user and group information for the specified USERNAME,
or (when USERNAME 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
      --help     display this help and exit
      --version  output version information and exit

Without any OPTION, print some useful set of identified information.

Report id bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'id invocation'

参数如下:

选项 作用
-a 忽略该命令,仅为了与其他版本兼容
-Z 仅显示当前用户的安全内容
-g 显示用户所属群组的ID
-G 显示用户所属所有群组,包括附加群组的ID
-n 显示用户,所属群组或附加群组的名称
-r 显示实际的ID
-u 显示当前用户ID

2. id 命令语法

shell 复制代码
id [OPTION]... [USERNAME]

3. id 命令示例

3.1 不加参数

不加用户名时,显示当前用户的信息,包括 uid gid groups

shell 复制代码
id

加用户名时,显示的是该用户的 uid gid groups

shell 复制代码
id admin

3.2 -u/-g/-G(用户、组、所属组)

这三个参数配合 -n 使用时,会显示名称,也可以指定用户

shell 复制代码
id -u
shell 复制代码
id -un
shell 复制代码
id -un admin

3.3 -gr/-Gr/-ur(有效ID)

复制代码
[root ~]$ id -gr
1101
[root ~]$ id -Gr
1101
[root ~]$ id -ur
1101
[root ~]$ id -ur admin
200
[root ~]$ id -Gr admin
200 10
[root ~]$ id -gr admin
200

4. 总结

id:用于显示当前或指定用户的 UID GID。

相关推荐
minji...13 分钟前
Linux高级IO(五)epoll 的两种工作模式(LT/ET),多路转接之epoll版本的TCP服务器,对比 select/poll/epoll
linux·运维·服务器·epoll·epoll的工作模式·selectpollepoll·水平触发边缘触发
JP-Destiny14 分钟前
docker报错-无法解析 registry-1.docker.io
运维·docker·容器
想你依然心痛27 分钟前
HarmonyOS 6(API 23)智能体驱动的沉浸式AR城市地下管网运维中心
运维·ar·harmonyos·智能体
xiaoye-duck28 分钟前
《Linux系统编程》Linux 命名管道 FIFO 详解:突破亲缘限制的跨进程通信实现
linux
文青小兵29 分钟前
Linux云计算——docker镜像(三)
linux·docker·云计算
逸Y 仙X29 分钟前
文章六:ElasticSearch 集群通信安全权限
java·大数据·服务器·elasticsearch·搜索引擎·全文检索
爱和冰阔落32 分钟前
【Linux系统编程】环境变量深度解析——从 fork 继承到 export 内建命令,两张表打通进程上下文
linux·c++·环境变量·系统调用
feng145633 分钟前
OpenSREClaw - 一切始于风险洞察报告
运维
零壹AI实验室41 分钟前
AI发现潜伏18年的NGINX高危漏洞:CVE-2026-42945完整技术分析
运维·人工智能·nginx
Dlrb121144 分钟前
数据结构-内核链表
linux·数据结构·链表·内核链表·inline·容器宏