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.log
1 2018-03-02 12:39:06:698 YZXBB
2 2018-03-03 12:40:16:700 VGLHY
3 2018-03-04 12:41:17:701 XANRN
4[root@peipei3514 usr]#
2、从开始一直到倒数第6500个复制,进行输出
[root@peipei3514 usr]# head -c -6500 test.log
1 2018-03-02 12:39:06:698 YZXBB
2 2018-03-03 12:40:16:700 VGLHY
3 2018-03-04 12:41:17:701 XANRN
4 2018-03-05 12:42:22:701 RXNYJ
5 2018-03-06 12:43:14:701 BBUEM
6 2018-03-07 12:44:14:701 FKYDL
7 2018-03-08 12:45:08:701 KAHMA
8 2018-03-09 12:46:14:702 GZZXG
9 2018-03-10 12:47:16:702 OEVDO
10 2018-03-11 12:48:06:702 ALXQQ
11 2018-03-12 12:49:10:702 HOCSQ
12 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 YZXBB
2 2018-03-03 12:40:16:700 VGLHY
3 2018-03-04 12:41:17:701 XANRN
4 2018-03-05 12:42:22:701 RXNYJ
5 2018-03-06 12:43:14:701 BBUEM
6 2018-03-07 12:44:14:701 FKYDL
7 2018-03-08 12:45:08:701 KAHMA
8 2018-03-09 12:46:14:702 GZZXG
9 2018-03-10 12:47:16:702 OEVDO
10 2018-03-11 12:48:06:702 ALXQQ
==> test2.log <==
201 2018-09-18 18:50:25:778 ZHWKD
202 2018-09-19 18:51:26:778 VQGRP
203 2018-09-20 18:52:37:779 UZDCE
204 2018-09-21 18:53:40:779 NCISH
205 2018-09-22 18:54:34:779 ZCJUY
206 2018-09-23 18:55:38:779 SEJKZ
207 2018-09-24 18:56:27:779 CNGMW
208 2018-09-25 18:57:31:779 GLILU
209 2018-09-26 18:58:24:779 VWUSO
210 2018-09-27 18:59:39:779 HDRAT