查看檔案及內容處理-tail命令,查看處理-tail命令

來源:互聯網
上載者:User

查看檔案及內容處理-tail命令,查看處理-tail命令
1、命令說明:

tail命令其功能是顯示檔案內容的尾部。預設情況下,tail 也是只顯示檔案的最後 10 行內容。

2、文法:

tail [選項]... [檔案清單]...

3、執行個體:

tail -n 5 /var/log/messages? ? 顯示檔案最後5行內容。其中 -n 選項用於指定顯示的行數。

[root@CentOS opt]# tail -n 5 /var/log/messages????# 顯示最後5行內容Feb 23 14:10:16 CentOS dbus[629]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'Feb 23 14:10:16 CentOS dbus-daemon: dbus[629]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'Feb 23 14:10:16 CentOS systemd: Started Network Manager Script Dispatcher Service.Feb 23 14:10:16 CentOS nm-dispatcher: req:1 'dhcp4-change' [ens33]: new request (4 scripts)Feb 23 14:10:16 CentOS nm-dispatcher: req:1 'dhcp4-change' [ens33]: start running ordered scripts...[root@CentOS opt]# 

但是 tail 命令還有個非常實用的功能,就是可以動態地查看檔案尾。這對查看一些不斷改變的檔案來說非常有用。比如說,系統中會有很多記錄檔,這些檔案是會隨時變化的,要動態地查看這些檔案,實用 -f 參數就可以做到。舉個例子,/var/log/message 檔案是預設的系統記錄檔,系統在運行中將會有大量的日誌寫入這個檔案中,可以使用如下命令,一旦有新的日誌內容寫入,該命令會立即將新內容顯示出來。

root@CentOS opt]# tail -f /var/log/messages????# -f 選項可以即時顯示檔案尾部內容

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.