#Bash 的 who 命令
who [OPTION]... [ FILE | ARG1 ARG2 ]
功能
查看当前登录的用户。
类型
可执行文件(/usr/bin/who),属于 coreutils。
参数
OPTION选项:-a,--all- 相当于-b -d --login -p -r -t -T -u-b,--boot- 打印登录以来的时间-d,--dead- 打印死亡进程-H,--heading- 打印列标题行-l,--login- 打印系统登录进程--lookup- 尝试通过 DNS 规范化主机名-m- 仅查看与标准输入关联的主机名和用户-p,--process- 打印由 init 进程启动的活动进程-q,--count- 打印登录名和登录用户的数量-r,--runlevel- 打印当前的 运行级别-s,--short- 打印短格式(默认)-t,--time- 打印上次系统时钟的变化-T,-w,--mesg- 添加用户消息状态-u,--users- 列出已登录用户--message- 同-T--writable- 同-T--help- 显示帮助--version- 显示版本
#SysV init 运行级别
| 运行级别 | 名称 | 描述 |
|---|---|---|
| 0 | halt | 关机(系统关闭电源) |
| 1 | single-user | 单用户模式(维护模式,无网络,多为 root) |
| 2 | multi-user | 多用户模式,不带网络服务(Debian/Ubuntu 部分配置) |
| 3 | multi-user | 多用户模式,带网络,纯命令行模式(文本模式) |
| 4 | unused | 用户自定义,可自由配置 |
| 5 | multi-user | 多用户模式,带图形界面(GUI) |
| 6 | reboot | 重启系统 |
#示例
$ who
primers pts/6 2025-11-29 08:35 (192.168.1.100)
$ who -a
system boot 2025-11-18 07:14
LOGIN tty1 2025-11-18 07:15 1086 id=tty1
run-level 5 2025-11-18 07:15
pts/0 2025-11-23 15:11 129498 id=ts/0 term=0 exit=0
pts/8 2025-11-18 13:19 8743 id=ts/8 term=0 exit=0
pts/3 2025-11-22 11:57 56288 id=ts/3 term=0 exit=0
pts/4 2025-11-19 14:38 59093 id=ts/4 term=0 exit=0
pts/11 2025-11-26 13:59 210827 id=s/11 term=0 exit=0
pts/9 2025-11-23 15:11 186011 id=ts/9 term=0 exit=0
pts/10 2025-11-26 13:59 210640 id=s/10 term=0 exit=0
pts/12 2025-11-24 15:27 211297 id=s/12 term=0 exit=125
primers + pts/6 2025-11-29 08:35 00:37 283090 (192.168.1.100)
#推荐阅读
#手册
WHO(1) User Commands WHO(1) NAME who - show who is logged on SYNOPSIS who [OPTION]... [ FILE | ARG1 ARG2 ] DESCRIPTION Print information about users who are currently logged in. -a, --all same as -b -d --login -p -r -t -T -u -b, --boot time of last system boot -d, --dead print dead processes -H, --heading print line of column headings -l, --login print system login processes --lookup attempt to canonicalize hostnames via DNS -m only hostname and user associated with stdin -p, --process print active processes spawned by init -q, --count all login names and number of users logged on -r, --runlevel print current runlevel -s, --short print only name, line, and time (default) -t, --time print last system clock change -T, -w, --mesg add user's message status as +, - or ? -u, --users list users logged in --message same as -T --writable same as -T --help display this help and exit --version output version information and exit If FILE is not specified, use /var/run/utmp. /var/log/wtmp as FILE is common. If ARG1 ARG2 given, -m presumed: 'am i' or 'mom likes' are usual. AUTHOR Written by Joseph Arceneaux, David MacKenzie, and Michael Stone. REPORTING BUGS GNU coreutils online help: <https://www.gnu.org/software/coreutils/> Report any translation bugs to <https://translationproject.org/team/> COPYRIGHT Copyright © 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO Full documentation <https://www.gnu.org/software/coreutils/who> or available locally via: info '(coreutils) who invocation' GNU coreutils 9.4 April 2024 WHO(1)