Linux基础命令---last

last

      显示以前登录过的用户信息,last指令会搜索/var/log/wtmp文件(或者是经过-f选项指定的文件),然后列出文件中所有的用户信息。如果执行last指令时提示“last /var/log/wtmp∶ NO such file or directory”,则需要使用指令touch /var/log/wtmp手工创建此文件 

     lastb指令用来显示登录失败的用户信息,其用法和last一样,对应的日志文件是/var/log/btmp

     此命令的适用范围:RedHat、RHEL、Ubuntu、CentOS、SUSE、openSUSE、Fedora。

1、语法

     last  [-R]  [-num] [ -n num ]  [-adFiowx]  [ -f file ]  [ -t YYYYMMDDHHMMSS ]  [name...]  [tty...]

     lastb [-R]  [-num]  [ -n num ] [ -f file ]  [-adFiowx]  [name...] [tty...]

 

2、选项列表

选项

说明

-f 文件名

指定登录的日志文件(默认是/var/log/wtmp)

-num

指定last显示多少行信息

-n num

和“-num”一样

-R 

不显示主机名字

-a

在最后一列显示主机名

-d

将非本地登录的用户ip转换成主机名

-F

显示所有的登录和注销时间和日期

-o

读取旧的日志文件

-w

显示用户名和域名

-x

显示系统关机信息和运行级别的变化信息

-t [YYYYMMDDHHMMSS]

显示指定时间的登录信息

[name]

显示指定用户的登录信息

[tty]

显示指定终端的登录信息,last tty1 = last 1

 

3、实例

1)显示最近登录的5条信息

[root@localhost ~]# last -5    //也可以使用last n 5

//登录用户  登录终端   主机名            登录时间             注销时间  持续时间

root     pts/0        :0.0             Tue Sep  4 13:10   still logged in   

root     pts/0        :0.0             Wed Aug 22 15:07 - 13:09 (12+22:02)  

root     pts/1        :0.0             Wed Aug 22 07:46 - 13:10 (13+05:23)  

root     pts/0        :0.0             Wed Aug 22 07:43 - 11:02  (03:18)   

root     tty1         :0               Wed Aug 22 07:20   still logged in   

 

wtmp begins Wed Aug  8 18:02:52 2018

2)显示用户weijie和root在8月9号的登录信息

[root@localhost ~]# last -t 20180809090000 weijie  //可以看到用户weijie8.9之前没有登录

wtmp begins Wed Aug  8 18:02:52 2018

 

[root@localhost ~]# last -t 20180809090000 root  //用户root8.9之前登录过几次

root     pts/0        :0.0             Wed Aug  8 20:19 - down   (00:05)   

root     tty1         :0               Wed Aug  8 20:19 - down   (00:06)   

root     pts/1        :0.0             Wed Aug  8 18:16 - 20:16  (01:59)   

root     pts/0        :0.0             Wed Aug  8 18:08 - 20:15  (02:06)   

root     tty1         :0               Wed Aug  8 18:04 - 20:16  (02:11)   

wtmp begins Wed Aug  8 18:02:52 2018

3)显示终端tty1的登录信息

[root@localhost ~]# last 1    //等同于last tty1

root     tty1         :0               Wed Aug 22 07:20   still logged in   

root     tty1         :0               Tue Aug 21 17:34 - down   (02:24)   

  

wtmp begins Wed Aug  8 18:02:52 2018

posted @ 2018-10-22 10:59  一生有你llx  阅读(616)  评论(0编辑  收藏  举报