当我在 Ubuntu Server 14.04 上使用该w
命令时,我得到如下输出:
18:44:24 up 4 days, 3:10, 1 user, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
kd pts/0 2001:db8:1334:2c 12:54 0.00s 0.06s 0.00s w
如您所见,IP 地址已被截断。有什么方法可以w
显示完整的 IP 地址而不进行截断?
答案1
根据man
页面内容w.procps
:
trusty (1) w.procps.1.gz
Provided by: procps_3.3.9-1ubuntu2_i386 bug
NAME
w - Show who is logged on and what they are doing.
...
ENVIRONMENT
PROCPS_USERLEN
Override the default width of the username column. Defaults to
8.
PROCPS_FROMLEN
Override the default width of the from column. Defaults to 16.
例如,
w3@aardvark:~(0)$ w
13:30:24 up 6 days, 20:32, 3 users, load average: 4.08, 3.43, 3.12
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
w3 tty1 19Nov16 25:51m 0.40s 0.38s -bash
w3 tty7 :0 19Nov16 6days 11:37m 2.41s /sbin/upstart --user
w3 pts/16 192.168.100.254 13:20 9:34 0.25s 0.25s -bash
w3@aardvark:~(0)$ env PROCPS_FROMLEN=48 w
13:30:36 up 6 days, 20:32, 3 users, load average: 3.68, 3.36, 3.10
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
w3 tty1 19Nov16 25:51m 0.40s 0.38s -bash
w3 tty7 :0 19Nov16 6days 11:37m 2.41s /sbin/upstart --user
w3 pts/16 192.168.100.254 13:20 9:46 0.25s 0.25s -bash
答案2
我相信您的解决方案是使用last -w
不会截断主机名的。
要过滤结果以查看当前谁登录,只需简单grep
操作即可。
last -w | grep "logged in"