歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux管理 >> Linux維護 >> Linux系統中head命令實例詳解

Linux系統中head命令實例詳解

日期:2017/3/2 10:36:22   编辑:Linux維護

當我們需要查看文件的頭部的時候,就要用到head命令,head命令主要用來查看文件前幾行或多少字節的內容,下面隨小編一起來了解下Linux下head命令的用法吧。

1.命令格式:

head [參數]。。. [文件]。。.

2.命令功能:

head 用來顯示檔案的開頭至標准輸出中,默認head命令打印其相應文件的開頭10行。

3.命令參數:

-q 隱藏文件名

-v 顯示文件名

-c《字節》 顯示字節數

-n《行數》 顯示的行數

4.使用實例:

實例1:顯示文件的前n行

命令:

head -n 5 log2014.log

輸出:

[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

輸出:

[root@localhost test]# head -c 20 log2014.log

2014-01

2014-02

2014

[root@localhost test]#

實例3:文件的除了最後n個字節以外的內容

命令:

head -c -32 log2014.log

輸出:

[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:輸出文件除了最後n行的全部內容

命令:

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]#

上面就是Linux下head命令的用法介紹了,head命令只可用於查看前一部分的內容,不能用於查看所有行的內容,你學會了嗎?

Copyright © Linux教程網 All Rights Reserved