Linux系统上与当前登录用户、启动日志及启动故障的相关信息

查看与操作环境、当前登录用户、机器加电的时间、启动故障信息在系统管理工作中很有必要,常用于搜索这些信息的命令有:who、w、users、uptime、last和lastb等。

获取当前登录用户信息

[root@localhost ~]# who
root     pts/0        2013-01-05 09:01 (192.168.1.21)

或者

[root@localhost ~]# w
 11:08:28 up  2:11,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.1.21     09:01    0.00s  0.14s  0.00s w

获取当前登录主机用户列表

[root@localhost ~]# users
root

如果用户打开多个终端使用sortuniq进行过滤:

users | tr ' ' '\n' | sort | uniq
root
sunkai

查看系统已经通电运行的时间:

[root@localhost ~]# uptime
 11:14:15 up  2:17,  1 user,  load average: 0.00, 0.00, 0.00

up之后的数字是系统通电运行的时间,load average输出的是系统平均负载。

获取前一次的启动及用户登录会话信息:

[root@localhost ~]# last
root     pts/0        192.168.1.21     Sat Jan  5 09:01   still logged in   
reboot   system boot  2.6.18-308.24.1. Sat Jan  5 08:57          (02:18)    
root     pts/1        192.168.1.21     Fri Jan  4 15:14 - crash  (17:43)    
root     pts/0        192.168.1.21     Fri Jan  4 10:15 - crash  (22:41)    
root     tty1                          Fri Jan  4 10:14 - crash  (22:42)    
reboot   system boot  2.6.18-308.24.1. Fri Jan  4 10:14         (1+01:01)   
root     pts/1        192.168.1.21     Thu Dec 27 11:17 - 14:49 (2+03:32)   
root     pts/0        192.168.1.21     Wed Dec 26 10:03 - down  (3+04:46)   
root     tty1                          Wed Dec 26 10:02 - down  (3+04:47)   
reboot   system boot  2.6.18-308.24.1. Wed Dec 26 10:01         (3+04:48)   
root     tty1                          Wed Dec 26 09:26 - down   (00:00)    
root     pts/0        192.168.1.21     Thu Dec 13 15:39 - down  (12+17:47)  
reboot   system boot  2.6.18-308.24.1. Thu Dec 13 15:38         (12+17:48)  
root     pts/0        192.168.1.21     Thu Dec 13 14:30 - down   (01:07)    
reboot   system boot  2.6.18-308.24.1. Thu Dec 13 14:29          (01:07)    
root     pts/0        192.168.1.21     Thu Dec 13 21:20 - down   (-6:-51)   
root     tty1                          Thu Dec 13 21:20 - down   (-6:-51)   
reboot   system boot  2.6.18-308.16.1. Thu Dec 13 21:14          (-6:-46)   
root     pts/0        192.168.174.1    Tue Nov  6 20:48 - down   (01:38)    
root     tty1                          Tue Nov  6 20:46 - down   (01:40)    
reboot   system boot  2.6.18-308.el5   Tue Nov  6 20:45          (01:41)    

wtmp begins Tue Nov  6 20:45:53 2012

获取单个用户的登录会话信息:

[root@localhost ~]# last root
root     pts/0        192.168.1.21     Sat Jan  5 09:01   still logged in   
root     pts/1        192.168.1.21     Fri Jan  4 15:14 - crash  (17:43)    
root     pts/0        192.168.1.21     Fri Jan  4 10:15 - crash  (22:41)    
root     tty1                          Fri Jan  4 10:14 - crash  (22:42)    
root     pts/1        192.168.1.21     Thu Dec 27 11:17 - 14:49 (2+03:32)   
root     pts/0        192.168.1.21     Wed Dec 26 10:03 - down  (3+04:46)   
root     tty1                          Wed Dec 26 10:02 - down  (3+04:47)   
root     tty1                          Wed Dec 26 09:26 - down   (00:00)    
root     pts/0        192.168.1.21     Thu Dec 13 15:39 - down  (12+17:47)  
root     pts/0        192.168.1.21     Thu Dec 13 14:30 - down   (01:07)    
root     pts/0        192.168.1.21     Thu Dec 13 21:20 - down   (-6:-51)   
root     tty1                          Thu Dec 13 21:20 - down   (-6:-51)   
root     pts/0        192.168.174.1    Tue Nov  6 20:48 - down   (01:38)    
root     tty1                          Tue Nov  6 20:46 - down   (01:40)    

wtmp begins Tue Nov  6 20:45:53 2012

获取重启会话信息:

[root@localhost ~]# last reboot
reboot   system boot  2.6.18-308.24.1. Sat Jan  5 08:57          (02:24)    
reboot   system boot  2.6.18-308.24.1. Fri Jan  4 10:14         (1+01:07)   
reboot   system boot  2.6.18-308.24.1. Wed Dec 26 10:01         (3+04:48)   
reboot   system boot  2.6.18-308.24.1. Thu Dec 13 15:38         (12+17:48)  
reboot   system boot  2.6.18-308.24.1. Thu Dec 13 14:29          (01:07)    
reboot   system boot  2.6.18-308.16.1. Thu Dec 13 21:14          (-6:-46)   
reboot   system boot  2.6.18-308.el5   Tue Nov  6 20:45          (01:41)    

wtmp begins Tue Nov  6 20:45:53 2012

获取用户登录失败的会话信息:

[root@localhost ~]# lastb
root     tty1                          Sat Jan  5 11:22 - 11:22  (00:00)    

btmp begins Sat Jan  5 11:22:55 2013

lastb命令必须是超级管理员才能运行。

暂无评论

写评论

您必须登录后才可以发表评论。

本人从事电脑网络维护工作多年,对电脑配置较为熟悉,闲暇之余精心搜罗了目前主流电脑配置清单推荐给大家。紧跟市场动态,定期更新电脑硬件配置方案,扫除一切垃圾坑爹配置,提供最具性价比的电脑配置清单!本站涵盖内容包括:电脑组装机配置单、电脑组装机报价、电脑组装机教程等,另外还提供很多技术文章供您学习!