每天一個linux命令(14):head 命令
head 與 tail 就(jiu)像(xiang)它(ta)的(de)名字一樣的(de)淺顯易懂(dong),它(ta)是(shi)用(yong)來(lai)顯示開頭或結尾某(mou)個數(shu)量的(de)文字區塊(kuai),head 用(yong)來(lai)顯示檔案的(de)開頭至標準輸出中,而(er) tail 想當(dang)然(ran)爾(er)就(jiu)是(shi)看(kan)檔案的(de)結尾。
1.命令(ling)格(ge)式:
head [參數]... [文(wen)件]...
2.命令功能(neng):
head 用來顯示檔案(an)的開頭(tou)至標準(zhun)輸出中(zhong),默認(ren)head命(ming)令(ling)打印其相(xiang)應文件的開頭10行。
3.命令參數:
-q 隱藏文(wen)件名
-v 顯示文件名
-c<字(zi)節> 顯示(shi)字(zi)節數
-n<行數> 顯(xian)示的行數
4.使用實例:
實例(li)1:顯示(shi)文件的前n行
命令:
head -n 5 log2014.log
輸出(chu):
[root@localhost test]# cat log2014.log
2014-01
2014-02
2014-03
2014-04
2014-05
2014-06
2014-07
2014-08
2014-09
2014-10
2014-11
2014-12
==============================
[root@localhost test]# head -n 5 log2014.log
2014-01
2014-02
2014-03
2014-04
2014-05[root@localhost test]#
實例2:顯示文件前n個字節
命令:
head -c 20 log2014.log
輸(shu)出(chu):
[root@localhost test]# head -c 20 log2014.log
2014-01
2014-02
2014
[root@localhost test]#
實例(li)3:文件的除(chu)了最后n個字節以外的內容
命令:
head -c -32 log2014.log
輸(shu)出:
[root@localhost test]# head -c -32 log2014.log
2014-01
2014-02
2014-03
2014-04
2014-05
2014-06
2014-07
2014-08
2014-09
2014-10
2014-11
2014-12[root@localhost test]#
實例4:輸出文(wen)件除(chu)了最后n行(xing)的(de)全部內容
命令:
head -n -6 log2014.log
輸出:
[root@localhost test]# head -n -6 log2014.log
2014-01
2014-02
2014-03
2014-04
2014-05
2014-06
2014-07[root@localhost test]#
關注 熵減黑客 ,一起學習成長
