w命令用于显示已经登陆系统的用户列表,并显示用户正在执行的指令。执行这个命令可得知目前登入系统的用户有那些人,以及他们正在执行的程序。单独执行w命令会显示所有的用户,您也可指定用户名称,仅显示某位用户的相关信息。
w(选项)(参数)
-h:不打印头信息;
-u:当显示当前进程和cpu时间时忽略用户名;
-s:使用短输出格式;
-f:显示用户从哪登录;
-V:显示版本信息。
用户:仅显示指定用户
详解:
显示当前用户
w //显示当前用户,不显示登录位置
19:50:14 up 9:27, 4 users, load average: 0.31, 0.26, 0.18
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty7 :0 Thu12 31:39m 10:10 0.60s gnome-session
root pts/0 :0.0 17:09 2:18m 15.26s 0.15s bash
root pts/1 192.168.1.17 18:51 1.00s 1.24s 0.14s -bash
root pts/2 192.168.1.17 19:48 60.00s 0.05s 0.05s -bash
//显示当前用户,不显示登录位置
19:50:14 up 9:27, 4 users, load average: 0.31, 0.26, 0.18
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty7 :0 Thu12 31:39m 10:10 0.60s gnome-session
root pts/0 :0.0 17:09 2:18m 15.26s 0.15s bash
root pts/1 192.168.1.17 18:51 1.00s 1.24s 0.14s -bash
root pts/2 192.168.1.17 19:48 60.00s 0.05s 0.05s -bash
不显示登录位置
w -f
19:53:59 up 9:31, 4 users, load average: 0.05, 0.16, 0.15
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
root tty7 Thu12 31:43m 10:10 0.60s gnome-session
root pts/0 17:09 2:21m 15.26s 0.15s bash
root pts/1 18:51 0.00s 1.04s 0.14s -bash
root pts/2 19:48 4:45 0.05s 0.05s -bash
-f
19:53:59 up 9:31, 4 users, load average: 0.05, 0.16, 0.15
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
root tty7 Thu12 31:43m 10:10 0.60s gnome-session
root pts/0 17:09 2:21m 15.26s 0.15s bash
root pts/1 18:51 0.00s 1.04s 0.14s -bash
root pts/2 19:48 4:45 0.05s 0.05s -bash
以精简模式显示
w -s
19:54:37 up 9:31, 4 users, load average: 0.24, 0.19, 0.16
USER TTY FROM IDLE WHAT
root tty7 :0 31:43m gnome-session
root pts/0 :0.0 2:22m bash
root pts/1 192.168.1.17 0.00s -bash
root pts/2 192.168.1.17 5:23 -bash
-s
19:54:37 up 9:31, 4 users, load average: 0.24, 0.19, 0.16
USER TTY FROM IDLE WHAT
root tty7 :0 31:43m gnome-session
root pts/0 :0.0 2:22m bash
root pts/1 192.168.1.17 0.00s -bash
root pts/2 192.168.1.17 5:23 -bash
不显示标题
w -h
root tty7 :0 Thu12 31:44m 10:10 0.60s gnome-session
root pts/0 :0.0 17:09 2:23m 15.26s 0.15s bash
root pts/1 192.168.1.17 18:51 0.00s 1.05s 0.14s -bash
root pts/2 192.168.1.17 19:48 5:54 0.05s 0.05s -bash
-h
root tty7 :0 Thu12 31:44m 10:10 0.60s gnome-session
root pts/0 :0.0 17:09 2:23m 15.26s 0.15s bash
root pts/1 192.168.1.17 18:51 0.00s 1.05s 0.14s -bash
root pts/2 192.168.1.17 19:48 5:54 0.05s 0.05s -bash
yexiang@ubuntu:$ w -u yexiang
14:02:04 up 9 days, 4:40, 3 users, load average: 0.99, 1.25, 0.99
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
yexiang pts/1 10.0.4.198 10:19 3.00s 0.19s 0.00s w -u yexiang