head 與 tail 就像它的名字一樣的淺顯易懂,它是用來顯示開頭或結(jié)尾某個數(shù)量的文字區(qū)塊,head 用來顯示檔案的開頭至標(biāo)準(zhǔn)輸出中,而 tail 想當(dāng)然爾就是看檔案的結(jié)尾。
1.命令格式:
head [參數(shù)]... [文件]...
2.命令功能:
head 用來顯示檔案的開頭至標(biāo)準(zhǔn)輸出中,默認(rèn)head命令打印其相應(yīng)文件的開頭10行。
3.命令參數(shù):
-q 隱藏文件名
-v 顯示文件名
-c字節(jié)> 顯示字節(jié)數(shù)
-n行數(shù)> 顯示的行數(shù)
4.使用實(shí)例:
實(shí)例1:顯示文件的前n行
命令:
輸出:
[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]#
實(shí)例2:顯示文件前n個字節(jié)
命令:
輸出:
[root@localhost test]# head -c 20 log2014.log
2014-01
2014-02
2014
[root@localhost test]#
實(shí)例3:文件的除了最后n個字節(jié)以外的內(nèi)容
命令:
輸出:
[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]#
實(shí)例4:輸出文件除了最后n行的全部內(nèi)容
命令:
輸出:
[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]#
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:- linux find命令之xargs簡單概述
- linux find命令之exec簡單概述
- linux命令之find命令簡單概述
- 每天一個linux命令 chgrp命令
- 詳解Linux文本文件與WIN文本文件換行格式轉(zhuǎn)換命令
- 一個簡單的linux命令 mv
- 一個簡單的linux命令 cp
- 一個簡單的linux命令 touch
- 一個簡單的linux命令 pwd
- 每天一個linux命令 whereis命令