一 指令介紹
1.1 功能
head:頭部,顯示檔案開頭部分,預設前10行。
1.2 用途
- 在未指定行數時預設顯示前10行。
- 處理多個檔案時會在各個檔案之前附加含有檔案名的行。
- 當沒有檔案或檔案為-時,讀取标準輸入。
1.3 文法
head [選項] [參數]
常用選項
- -n:顯示行數,一般直接-行數
- -q:不列印檔案名行
- -v:總是列印檔案名行
- --help:顯示幫助資訊
- --version:顯示版本資訊
參數
- 檔案:要處理的檔案,可以是一個或多個
二 使用場景
2.1 案例1
檢視檔案前6行内容
cd /web/test/
head -n test.txt
2.2 案例2
檢視檔案前10行内容
cd /web/test/
head test.txt
cd /web/test/
head -n 10 test.txt
cd /web/test
head -10 test.txt
2.3 案例3
檢視多個檔案
cd /web/test/
head -n 2 test.txt test1.txt
至此,head指令梳理完成。