Linux shell 归纳之 last

使用方法:

格式1:last -n  

n指定账号数量,最新前n个登陆信息(用户,终端,IP, 日期,时间和持续时间)

格式2:last -n <number of the latest account>

用途:在日常工作中,如果要排查最近年谁正在或者曾经登陆过,获悉信息包括(用户,终端,IP, 日期,时间和持续时间)。

例1:显示最近登陆的前5个账号

> last -5

test     pts/3        xxx.xx.xx.xxx    Mon Oct  6 10:24   still logged in  

test     pts/2        xxx.xx.xx.xxx    Mon Oct  6 10:23   still logged in  

test     pts/2        xxx.xx.xx.xxx    Mon Oct  6 10:21 - 10:22  (00:00)   

test     pts/1        xxx.xx.xx.xxx    Mon Oct  6 10:18   still logged in  

test     pts/1        xxx.xx.xx.xxx    Wed Oct  1 14:59 - 09:49  (18:49) 

 

> last -n 5

test     pts/1        xxx.xx.xx.xxx    Tue Oct  7 13:45   still logged in  

test     pts/2        xxx.xx.xx.xxx    Mon Oct  6 13:35 - 18:14  (04:38)   

test     pts/3        xxx.xx.xx.xxx    Mon Oct  6 10:24 - 11:23  (00:59)   

test     pts/2        xxx.xx.xx.xxx    Mon Oct  6 10:23 - 11:23  (00:59)   

test     pts/2        xxx.xx.xx.xxx    Mon Oct  6 10:21 - 10:22  (00:00)   

 

从上面的结果可以看出,一共显示4列,每列之间的间隔为空格。

  • 第1列:test,表示用户名
  • 第2列: psts/0, 表示伪终端或虚拟终端,具体表现就是你打开一个终端,这个终端就叫pts/0,如果你再打开一个终端,这个新的终端就叫pts /1

例如:打开第一个session window (pst/1),第二个session window (pst/2),然后关闭第二个session window, 然后又打开第二个session (pst/2), 又打开第三个session window (pst/3).如上图:

  • 第一个session window: pst/1
  • 第二个session window: pst/2
  • 第三个session window: pst/3
  • 第3列:用户登陆的机器IP地址
  • 第4列:登陆时间,退出时间和持续时间
    • 如果用户曾经登陆过,但是现在已经退出了:Thu Sep 25 11:23 - 23:34 (2+12:11)
    • 如果当前用户正在登陆,但是没有退出话:Sun Sep 28 09:52   still logged in
原文地址:https://www.cnblogs.com/recognition/p/4684037.html