linux之tail和head的使用


tail

基本介紹

  用於顯示文件的結尾的內容。在默認情況下,tail命令顯示文件的后10行內容

表達式

  tail [options] [filenames]

常用參數

  • -c:輸出最后N個字節
  • -f:當文件增長時,輸出后續添加的數據,當文件不存在時,會立即結束
  • -F:和-f用法基本一致,但是在文件不存在時會繼續重試
  • -n:
  • -q:
  • -s:
  • -v:

基本使用

  • 默認顯示最后十行

   命令:tail test.txt

  • 指定顯示最后多少行

  命令:

  tail -n5 test1.txt  或
  tail -n 5 test1.txt 或
  tail -5 test1.txt 或
  tail -n -5 test1.txt
  • 從第幾行開始顯示后面的內容
  命令:tail -n +5 test1.txt 或 tail +5 test1.txt
  • 循環輸出新增的內容
  命令:tail -f test1.txt 或tailf test1.txt
  • 循環輸出最后多少行
  命令:tail -2f test1.txt
  說明:循環輸出最后2行
  • 從第幾個字節開始往后輸出
  命令:
  tail +5c test1.txt 或
  tail -c +5 test1.txt

head

基本介紹

   head 命令可以將一段文本的開頭一部分輸出到標准輸出。默認輸出前十行。可以同時操作多個文件

表達式

head [-n -k ]... [FILE]...

常用參數

  • -c:輸出多少個字節
  • -n:輸出多少行
  • -q:
  • -v:

基本使用

  •  輸出前多少行

  命令:  

  head -n3 test1.txt 或
  head -n 3 test1.txt 或
  head -n +3 test1.txt 或
  head -3 test1.txt
  • 輸出除去后面多少行外的內容

  命令:head -n -3 test1.txt

  • 輸出前幾個字節

  命令:head -c5 test1.txt

 


免責聲明!

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



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