原文:http://www.CUOXin.com/peida/archive/2012/11/06/2756278.html
head與tail就像它的名字一樣的淺顯易懂,它是用來顯示開頭或結尾某個數量的文字區塊,head用來顯示檔案的開頭至標準輸出中,而tail想當然爾就是看檔案的結尾。
1.命令格式:
head[參數]...[文件]...
2.命令功能:
head用來顯示檔案的開頭至標準輸出中,默認head命令打印其相應文件的開頭10行。
3.命令參數:
-q隱藏文件名
-v顯示文件名
-c<字節>顯示字節數
-n<行數>顯示的行數
4.使用實例:
實例1:顯示文件的前n行
命令:
head-n5log2014.log
輸出:
[root@localhosttest]#catlog2014.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@localhosttest]#head-n5log2014.log
2014-01
2014-02
2014-03
2014-04
2014-05[root@localhosttest]#
實例2:顯示文件前n個字節
命令:
head-c20log2014.log
輸出:
[root@localhosttest]#head-c20log2014.log
2014-01
2014-02
2014
[root@localhosttest]#
實例3:文件的除了最后n個字節以外的內容
命令:
head-c-32log2014.log
輸出:
[root@localhosttest]#head-c-32log2014.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@localhosttest]#
實例4:輸出文件除了最后n行的全部內容
命令:
head-n-6log2014.log
輸出:
[root@localhosttest]#head-n-6log2014.log
2014-01
2014-02
2014-03
2014-04
2014-05
2014-06
2014-07[root@localhosttest]#
新聞熱點
疑難解答