Linux查看日誌三種命令,linux查看日誌

來源:互聯網
上載者:User

Linux查看日誌三種命令,linux查看日誌

第一種:查看即時變化的日誌(比較吃記憶體)

    最常用的:

    tail -f filename  (預設最後10行,相當於增加參數 -n 10)

    Ctrl+c 是退出tail命令

 

    其他情況:

    tail -n 20 filename  (顯示filename最後20行)

    tail -n +5 filename  (從第5行開始顯示檔案)

 

第二種:搜尋索引鍵附近的日誌

    最常用的:

    cat -n filename |grep "關鍵字"

   

    其他情況:

    cat filename | grep -C 5 '關鍵字'   (顯示日誌裡匹配字串那行以及前後5行)

    cat filename | grep -B 5 '關鍵字'   (顯示匹配字串及前5行)

    cat filename | grep -A 5 '關鍵字'   (顯示匹配字串及後5行)

 

第三種:進入編輯尋找:vi(vim) 

    1、進入vim編輯模式:vim filename

    2、輸入“/關鍵字”,按enter鍵尋找

    3、尋找下一個,按“n”即可

    退出:按ESC鍵後,接著再輸入:號時,vi會在螢幕的最下方等待我們輸入命令

    wq! 儲存退出;

    q! 不儲存退出;

 

    其他情況:

    /關鍵字    註:正向尋找,按n鍵把游標移動到下一個合格地方
    ?關鍵字    註:反向尋找,按shift+n 鍵,把游標移動到下一個合格

聯繫我們

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