Linux日誌查看之head命令使用介紹,linux日誌head命令

來源:互聯網
上載者:User

Linux日誌查看之head命令使用介紹,linux日誌head命令

head命令用於顯示檔案的開頭的內容。在預設情況下,head命令顯示檔案的頭10行內容。

NAME(名稱)       head - output the first part of files              輸出檔案開始的部分SYNOPSIS(概要,大綱)       head [OPTION]... [FILE]...DESCRIPTION(描述)       Print the first 10 lines of each FILE to standard output.         With more than one FILE, precede each with a header giving the file name.         With no FILE, or when FILE is -, read standard input.       將每個檔案的開始10行列印到標準輸出。       如果指定了多於一個檔案,在每一段輸出前會給出檔案名稱作為檔案頭。       如果沒有指定檔案,或者檔案為-,那麼就從標準輸入上讀取。       Mandatory arguments to long options are mandatory for short options too.       長選項必須用的參數在使用短選項時也是必須的。       -c, --bytes=[-]K              print the first K bytes of each file;               with the leading '-', print all but the last K bytes of each file              輸出開始的K個位元組;              或者使用 -c -K,從每個檔案的開始一直到倒數K個位元組       -n, --lines=[-]K              print the first K lines instead of the first 10;               with the leading '-', print all but the last K lines of each file              輸出開始的K行,而不是開始的10行;              或者使用 -n -K,從每個檔案的開始一直到倒數K行       -q, --quiet, --silent              never print headers giving file names              當有多個檔案參數時,不輸出各個檔案名稱;       -v, --verbose              always print headers giving file names              當有多個檔案參數時,總是輸出各個檔案名稱;       --help display this help and exit              顯示此協助資訊並退出       --version              output version information and exit              顯示版本資訊並退出

1、輸出開始的100個字元

[root@peipei3514 usr]# head -c 100 test.log1 2018-03-02 12:39:06:698 YZXBB2 2018-03-03 12:40:16:700 VGLHY3 2018-03-04 12:41:17:701 XANRN4[root@peipei3514 usr]#

2、從開始一直到倒數第6500個複製,進行輸出

[root@peipei3514 usr]# head -c -6500 test.log1 2018-03-02 12:39:06:698 YZXBB2 2018-03-03 12:40:16:700 VGLHY3 2018-03-04 12:41:17:701 XANRN4 2018-03-05 12:42:22:701 RXNYJ5 2018-03-06 12:43:14:701 BBUEM6 2018-03-07 12:44:14:701 FKYDL7 2018-03-08 12:45:08:701 KAHMA8 2018-03-09 12:46:14:702 GZZXG9 2018-03-10 12:47:16:702 OEVDO10 2018-03-11 12:48:06:702 ALXQQ11 2018-03-12 12:49:10:702 HOCSQ12 2018-03-13 12:50:10:702 [root@peipei3514 usr]#

+或空,從頭計數

-,從尾計數

3、指定多個檔案並輸出檔案名

[root@peipei3514 usr]# head -v test.log test2.log==> test.log <==1 2018-03-02 12:39:06:698 YZXBB2 2018-03-03 12:40:16:700 VGLHY3 2018-03-04 12:41:17:701 XANRN4 2018-03-05 12:42:22:701 RXNYJ5 2018-03-06 12:43:14:701 BBUEM6 2018-03-07 12:44:14:701 FKYDL7 2018-03-08 12:45:08:701 KAHMA8 2018-03-09 12:46:14:702 GZZXG9 2018-03-10 12:47:16:702 OEVDO10 2018-03-11 12:48:06:702 ALXQQ==> test2.log <==201 2018-09-18 18:50:25:778 ZHWKD202 2018-09-19 18:51:26:778 VQGRP203 2018-09-20 18:52:37:779 UZDCE204 2018-09-21 18:53:40:779 NCISH205 2018-09-22 18:54:34:779 ZCJUY206 2018-09-23 18:55:38:779 SEJKZ207 2018-09-24 18:56:27:779 CNGMW208 2018-09-25 18:57:31:779 GLILU209 2018-09-26 18:58:24:779 VWUSO210 2018-09-27 18:59:39:779 HDRAT

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.