Linux查看文件指定行數內容


1、tail date.log               輸出文件末尾的內容,默認10行

     tail -20  date.log        輸出最后20行的內容

     tail -n -20  date.log    輸出倒數第20行到文件末尾的內容

     tail -n +20  date.log   輸出第20行到文件末尾的內容

     tail -f date.log            實時監控文件內容增加,默認10行。

2、head date.log           輸出文件開頭的內容,默認10行

     head -15  date.log     輸出開頭15行的內容

     head -n +15 date.log 輸出開頭到第15行的內容

     head -n -15 date.log  輸出開頭到倒數第15行的內容

3、sed -n "開始行,結束行p" 文件名    

      sed -n '70,75p' date.log             輸出第70行到第75行的內容

      sed -n '6p;260,400p; ' 文件名    輸出第6行 和 260到400行

      sed -n 5p 文件名                       輸出第5行

tail 和 head 加上 -n參數后 都代表輸出到指定行數,tail 是指定行數到結尾,head是開頭到指定行數

+數字 代表整數第幾行, -數字代表倒數第幾行


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM