用 dscl 查询本机用户和用户组
直接读取 macOS 目录服务:列出账户、查看用户记录、检查组成员关系。
运行 `dscl . -list /Users UniqueID` 列出本地账户及 UID,用 `dscl . -read /Users/<用户名> RealName` 查看单个用户信息。
01命令
命令
$ dscl . -list /Users UniqueID02作用说明
dscl 是目录服务的命令行接口,用 '.' 作为数据源即可访问本地节点:/Users、/Groups 和 /SharePoints。UID 大于 500 的通常是人类账户,更小的是系统账户——审计谁能登录时非常有用。组成员存储在 GroupMembership 键中,例如 `dscl . -read /Groups/admin GroupMembership` 可查看管理员组成员。
03风险
!注意: dscl 也能写入(create/delete/append),路径打错可能损坏本地账户记录。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- DSCL Command: Directory Service command line utility in macOS依据: Documents dscl . -list /Users, -read, -search and group membership queries against the local directory.
最后验证: 2026-09-17 · 分类: 系统与设置