head 與 tail 就像它的名字一樣的淺顯易懂,它是用來顯示開頭或結尾某個數量的文字區塊,head
用來顯示檔案的開頭至標準輸出中,而 tail
想當然爾就是看檔案的結尾。
head [引數]... [檔案]...
head
用來顯示檔案的開頭至標準輸出中,預設head
命令列印其相應檔案的開頭10
行。
-q
隱藏檔案名-v
顯示檔案名-c
<位元組> 顯示位元組數-n
<行數> 顯示的行數命令:
head -n 5 log.log
演示操作及輸出:
[yiibai@localhost test]$ cat log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.
this is line5.
this is line 6.
this is line 7.
this is line 8.
this is line 9.
this is line 10.
this is line 11.
this is line 12.
this is line 13.
this is line 14.
this is line 15.
this is line 16.
this is line 17.
this is line 18.
this is line 19.
this is line 20.
this is line 21.
this is line 22.
-----------------end
[yiibai@localhost test]$ head -n 5 log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.
[yiibai@localhost test]$
命令:
head -c 20 log.log
演示操作及輸出:
[yiibai@localhost test]$ head -c 20 log.log
this is line 1.
this[yiibai@localhost test]$
命令:
head -c -32 log.log
演示操作及輸出:
[yiibai@localhost test]$ head -c -32 log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.
this is line5.
this is line 6.
this is line 7.
this is line 8.
this is line 9.
this is line 10.
this is line 11.
this is line 12.
this is line 13.
this is line 14.
this is line 15.
this is line 16.
this is line 17.
this is line 18.
this is line 19.
this is line 20.
this is line 21.
[yiibai@localhost test]$
命令:
head -n -6 log.log
```shell
演示操作及輸出:
```shell
[yiibai@localhost test]$ head -n -6 log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.
this is line5.
this is line 6.
this is line 7.
this is line 8.
this is line 9.
this is line 10.
this is line 11.
this is line 12.
this is line 13.
this is line 14.
this is line 15.
this is line 16.
this is line 17.
this is line 18.
[yiibai@localhost test]$