last 命令的功能是用于显示用户历史登录情况,通过查看系统记录的日志文件内容,进而使管理员可以获知谁曾经或者试图连接过服务器。 通过读取系统登陆历史日志文件(/var/log/wtmp)并按照用户名、登录终端、来源终端、时间等信息进行划分,让用户对系统历史登录情况一目了然。
目录
3.4 仅显示最近3条历史登录情况,并将来源终端信息显示到最后
一、语法格式
last [选项]
二、常用参数
-n | 显示行数 |
-a | 将来源终端信息项放置放到最后 |
-R | 省略来源终端 |
-f | 指定记录文件 |
三、命令实战
3.1 显示近期用户或终端的历史登录情况
[root@linux1 ~]# last
root pts/2 192.168.100.1 Tue Mar 28 16:43 still logged in
keven pts/2 192.168.100.1 Tue Mar 28 16:41 - 16:43 (00:01)
root pts/1 192.168.100.1 Tue Mar 28 16:39 still logged in
root pts/0 192.168.100.1 Tue Mar 28 16:34 still logged in
root pts/0 192.168.100.1 Tue Mar 28 16:28 - 16:34 (00:06)
3.2 仅显示最近3条历史登录情况
[root@linux1 ~]# last -n 6
root pts/2 192.168.100.1 Tue Mar 28 16:43 still logged in
keven pts/2 192.168.100.1 Tue Mar 28 16:41 - 16:43 (00:01)
root pts/1 192.168.100.1 Tue Mar 28 16:39 still logged in
3.3 仅显示最近3条历史登录情况,并不显示来源终端信息
[root@linux1 ~]# last -n 3 -R
root pts/2 Tue Mar 28 16:43 still logged in
keven pts/2 Tue Mar 28 16:41 - 16:43 (00:01)
root pts/1 Tue Mar 28 16:39 still logged in
3.4 仅显示最近3条历史登录情况,并将来源终端信息显示到最后
[root@linux1 ~]# last -n 3 -a
root pts/2 Tue Mar 28 16:43 still logged in 192.168.100.1
keven pts/2 Tue Mar 28 16:41 - 16:43 (00:01) 192.168.100.1
root pts/1 Tue Mar 28 16:39 still logged in 192.168.100.1
3.5 指定查询文件,原本默认的是 wtmp
[root@linux1 ~]# last -f /var/log/btmp
keven ssh:notty 192.168.100.1 Tue Mar 28 16:39 gone - no logout
keven ssh:notty 192.168.100.1 Tue Mar 28 16:39 - 16:39 (00:00)
keven ssh:notty 192.168.100.1 Tue Mar 28 16:37 - 16:39 (00:01)
******** ssh:notty 192.168.100.1 Mon Mar 27 15:40 - 16:37 (1+00:57)
******** ssh:notty 192.168.100.1 Mon Mar 27 15:39 - 15:40 (00:01)
版权声明:本文为weixin_69217438原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。