Dav*_*eau 6 command-line users
我正在寻找一种列出所有会话的方法,例如 who 命令,它还可以列出用户列表使用的 shell 类型。
根据您的需要,您可以使用who的 表弟w:
$ w
17:40:49 up 11 days, 22:38, 4 users, load average: 0.14, 0.13, 0.10
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
muru tty7 :0 12Jan17 11days 2:24m 0.37s /sbin/upstart --user
muru pts/24 127.0.0.1:S.0 17:36 0.00s 0.41s 0.00s w
muru pts/26 127.0.0.1:S.2 17:38 2:33 0.19s 0.19s -/bin/zsh
Run Code Online (Sandbox Code Playgroud)
它在登录终端上运行活动命令。您可以使用终端 ID 来查看我最初启动的是哪个 shell:
$ w -h | awk '{print $2}' | xargs -L1 pgrep -oat
1969 /usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
12703 -/bin/zsh
13398 -/bin/zsh
Run Code Online (Sandbox Code Playgroud)
pgrep能:
-t)-o)-a)