Linux -- last (轉)

來源:互聯網
上載者:User

標籤:blog   http   os   ar   檔案   art   sp   log   on   

 

linux last 命令介紹 

  功能說明:列出目前與過去登入系統的使用者相關資訊。 

  語  法:last [-adRx][-f <記錄檔案>][-n <顯示列數>][帳號名稱...][終端機編號...] 

  補充說明:單獨執行last指令,它會讀取位於/var/log目錄下,名稱為wtmp的檔案,並把該給檔案的內容記錄的登入系統的使用者名稱單全部顯示出來。 

  參  數:

  -a  把從何處登入系統的主機名稱或IP地址,顯示在最後一行。

  -d  將IP地址轉換成主機名稱。

  -f <記錄檔案>  指定記錄檔案。

  -n <顯示列數>或-<顯示列數>  設定列出名單的顯示列數。

  -R  不顯示登入系統的主機名稱或IP地址。

  -x  顯示系統關機,重新開機,以及執行等級的改變等資訊。 

last 命令:

功能說明:列出目前與過去登入系統的使用者相關資訊。 

========測試環境: Fedora Core 6.0;核心:2.6.18========

#last用了顯示使用者登入情況。以下是直接顯示固定行數的記錄。kkk是建立的使用者。

[[email protected] ~]$ last -6

kkk     pts/2        :0.0             Thu Jul 26 20:48   still logged in   

kkk     pts/2        :0.0             Thu Jul 26 20:21 - 20:21 (00:00)    

kkk     :0                            Thu Jul 26 20:21   still logged in   

reboot   system boot 2.6.18-1.2798.fc Thu Jul 26 20:20          (00:41)    

kkk     pts/2        :0.0             Thu Jul 26 11:16 - 11:46 (00:30)    

kkk     pts/2        :0.0             Thu Jul 26 10:18 - 10:18 (00:00)    

 

wtmp begins Sun Jul 1 15:17:08 2007

 

#預設是顯示wtmp的記錄,btmp能顯示的更詳細,可以顯示遠程登入,例如ssh登入。

[[email protected] ~]# last -n 15 -f /var/log/btmp

kkk     :0                            Thu Jul 26 20:21   still logged in   

klot     tty1                          Fri Jul 20 22:27    gone - no logout 

np962e76 tty1                          Fri Jul 20 22:26 - 22:27 (00:00)    

klot     tty1                          Fri Jul 20 22:26 - 22:26 (00:00)    

root     :0                            Fri Jul 20 22:22 - 20:21 (5+21:58)   

klot     :0                            Fri Jul 20 22:22 - 22:22 (00:00)    

root     tty1                          Fri Jul 20 20:58 - 22:26 (01:28)    

klot     tty1                          Fri Jul 20 20:58 - 20:58 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:58 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:57 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:57 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:57 (00:00)    

reboot   tty1                          Fri Jul 20 20:55 - 20:57 (00:02)    

root     tty1                          Fri Jul 20 20:54 - 20:55 (00:00)    

root     tty1                          Fri Jul 20 20:54 - 20:54 (00:00) 

btmp begins Mon Apr 30 22:05:54 2007

#顯示特定tty口的登入,1是tty1的登入情況,看的很清楚的。 np962e76 和 lkdjflkj 和klot其實都沒有登

#錄成功,我是把密碼忘記了。前面兩個使用者,是根本不存在的,但是也有記錄。

[[email protected] ~]# last -n 15 -f /var/log/btmp 1

klot     tty1                          Fri Jul 20 22:27    gone - no logout 

np962e76 tty1                          Fri Jul 20 22:26 - 22:27 (00:00)    

klot     tty1                          Fri Jul 20 22:26 - 22:26 (00:00)    

root     tty1                          Fri Jul 20 20:58 - 22:26 (01:28)    

klot     tty1                          Fri Jul 20 20:58 - 20:58 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:58 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:57 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:57 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:57 (00:00)    

reboot   tty1                          Fri Jul 20 20:55 - 20:57 (00:02)    

root     tty1                          Fri Jul 20 20:54 - 20:55 (00:00)    

root     tty1                          Fri Jul 20 20:54 - 20:54 (00:00)    

root     tty1                          Fri Jul 20 20:54 - 20:54 (00:00)    

lkdjflkj tty1                          Fri Jul 20 20:54 - 20:54 (00:00)    

klot     tty1                          Fri Jul 20 20:53 - 20:54 (00:00)    

 

btmp begins Mon Apr 30 22:05:54 2007

#顯示特定使用者的登入情況。

[[email protected] ~]# last -n 15 -f /var/log/btmp klot

klot     tty1                          Fri Jul 20 22:27    gone - no logout 

klot     tty1                          Fri Jul 20 22:26 - 22:26 (00:00)    

klot     :0                            Fri Jul 20 22:22 - 22:22 (00:00)    

klot     tty1                          Fri Jul 20 20:58 - 20:58 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:58 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:57 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:57 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:57 (00:00)    

klot     tty1                          Fri Jul 20 20:53 - 20:54 (00:00)    

klot     tty1                          Fri Jul 20 20:53 - 20:53 (00:00)    

klot     tty1                          Fri Jul 20 20:53 - 20:53 (00:00)    

klot     tty1                          Fri Jul 20 20:53 - 20:53 (00:00)    

klot     tty1                          Fri Jul 20 20:52 - 20:53 (00:00)    

klot     tty1                          Fri Jul 20 20:52 - 20:52 (00:00)    

klot     tty1                          Fri Jul 20 20:52 - 20:52 (00:00)    

 

btmp begins Mon Apr 30 22:05:54 2007

#顯示登入登出的記錄,-x。

[[email protected] ~]# last -n 15 -f /var/log/btmp klot -x

klot     tty1                          Fri Jul 20 22:27    gone - no logout 

klot     tty1                          Fri Jul 20 22:26 - 22:26 (00:00)    

klot     :0                            Fri Jul 20 22:22 - 22:22 (00:00)    

klot     tty1                          Fri Jul 20 20:58 - 20:58 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:58 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:57 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:57 (00:00)    

klot     tty1                          Fri Jul 20 20:57 - 20:57 (00:00)    

klot     tty1                          Fri Jul 20 20:53 - 20:54 (00:00)    

klot     tty1                          Fri Jul 20 20:53 - 20:53 (00:00)    

klot     tty1                          Fri Jul 20 20:53 - 20:53 (00:00)    

klot     tty1                          Fri Jul 20 20:53 - 20:53 (00:00)    

klot     tty1                          Fri Jul 20 20:52 - 20:53 (00:00)    

klot     tty1                          Fri Jul 20 20:52 - 20:52 (00:00)    

klot     tty1                          Fri Jul 20 20:52 - 20:52 (00:00)    

 

btmp begins Mon Apr 30 22:05:54 2007

#-i顯示特定ip登入的情況。跟蹤用。

[[email protected] ~]# last -n 15 -i 127.0.0.1 -f /var/log/btmp klot

klot     tty1         0.0.0.0          Fri Jul 20 22:27    gone - no logout 

klot     tty1         0.0.0.0          Fri Jul 20 22:26 - 22:26 (00:00)    

klot     :0           0.0.0.0          Fri Jul 20 22:22 - 22:22 (00:00)    

klot     tty1         0.0.0.0          Fri Jul 20 20:58 - 20:58 (00:00)    

klot     tty1         0.0.0.0          Fri Jul 20 20:57 - 20:58 (00:00)    

klot     tty1         0.0.0.0          Fri Jul 20 20:57 - 20:57 (00:00)    

klot     tty1         0.0.0.0          Fri Jul 20 20:57 - 20:57 (00:00)    

klot     tty1         0.0.0.0          Fri Jul 20 20:57 - 20:57 (00:00)    

klot     tty1         0.0.0.0          Fri Jul 20 20:53 - 20:54 (00:00)    

klot     tty1         0.0.0.0          Fri Jul 20 20:53 - 20:53 (00:00)    

klot     tty1         0.0.0.0          Fri Jul 20 20:53 - 20:53 (00:00)    

klot     tty1         0.0.0.0          Fri Jul 20 20:53 - 20:53 (00:00)    

klot     tty1         0.0.0.0          Fri Jul 20 20:52 - 20:53 (00:00)    

klot     tty1         0.0.0.0          Fri Jul 20 20:52 - 20:52 (00:00)    

klot     tty1         0.0.0.0          Fri Jul 20 20:52 - 20:52 (00:00)    

 

1、清除登陸系統成功的記錄,也就是last命令看到的記錄

[[email protected] ~]echo > /var/log/wtmp 此檔案預設開啟時亂碼的,裡面可以看到ip等等資訊

 

驗證過程

[[email protected] ~]#last

root     pts/0        10.5.10.51       Thu Sep  2 00:59   still logged in   

root     pts/2        10.5.10.60       Wed Sep  1 16:11 - 17:47  (01:35)    

root     pts/2        10.5.10.60       Wed Sep  1 16:08 - 16:10  (00:02)    

root     pts/0        10.5.10.61       Wed Sep  1 14:16 - 23:02  (08:46)    

root     pts/3        10.5.10.59       Wed Sep  1 11:28 - 19:38  (08:10)    

root     pts/2        10.5.10.60       Wed Sep  1 11:18 - 16:07  (04:49)    

root     pts/1        10.5.10.191      Wed Sep  1 11:17 - 19:12  (07:55)    

。。。。。。。。。。。。。。。。。。。。。。。

 

[[email protected] ~]#echo >/var/log/wtmp 

[[email protected] ~]#last

 

wtmp begins Thu Sep  2 01:04:34 2010

[[email protected] ~]#

 

此時即看不到使用者登入資訊 

2、清除登陸系統失敗的記錄,也就是lastb命令看到的記錄

[[email protected] ~]echo > /var/log/btmp 此檔案預設開啟時亂碼的

 

驗證方法

在執行命令前執行lastb如下

[[email protected] ~]#lastb

root     ssh:notty    10.5.10.60       Wed Sep  1 16:11 - 16:11  (00:00)    

         tty6                          Mon Aug 30 22:53 - 22:53  (00:00)    

         tty6                          Mon Aug 30 18:52 - 18:52  (00:00)    

         tty6                          Mon Aug 30 18:52 - 18:52  (00:00)    

  ++++++ tty6                          Mon Aug 30 18:52 - 18:52  (00:00)    

linuxzgf    ssh:notty    10.5.10.60       Mon Aug 30 11:21 - 11:21  (00:00)    

linuxzgf    ssh:notty    10.5.10.60       Mon Aug 30 09:37 - 09:37  (00:00)    

。。。。。。。。。

 

然後執行

[[email protected] ~]#echo > /var/log/btmp 

[[email protected] ~]#lastb

 btmp begins Thu Sep  2 01:01:06 2010 

3、清除曆史執行命令 

[[email protected] ~]history -c  

轉自:

http://blog.csdn.net/a007zheng/article/details/6985521

Linux -- last (轉)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.