Linux之head文件开头查看命令
head命令用于显示文件开头内容,在默认情况下,显示文件头10行内容。
命令格式
head [option]... [file]...
选项
-c: --bytes=[-]k,显示每个文件的前k字节内容,如果附加-参数,则显示每个文件最后k字节外的所有内容
-n: --lines=[-]k,显示每个文件的前k行内容,如果附加-参数,则显示每个文件最后k行外的所有内容
例子
[root@localhost opt]# ll --展示目录下文件
总用量 36
-rw-r--r--. 1 root root 93 6月 1 05:18 01.txt
-rw-r--r--. 1 root root 5281 6月 2 02:48 the-match-girl.txt
-rw-r--r--. 1 root root 22844 6月 1 05:32 道德经.txt
[root@localhost opt]# head the-match-girl.txt --展示文件开头,不加参数默认展示10行
TTLE MATCH GIRL
IT was terribly cold; it snowed and was already almost dark,
and evening came on the last evening of the year.
In the cold and gloom a poor little girl,
bareheaded and barefoot, was walking through the streets.
When she left her own house she certainly had had slippers on;
but of what use were they? They were very big slippers,
and her mother had used them till then,
so big were they.
The little maid lost them as she slipped across the road,
[root@localhost opt]# head -c60 the-match-girl.txt --展示文件开头前60个字节
TTLE MATCH GIRL
IT was terribly cold; it[root@localhost opt]#
[root@localhost opt]# head -n5 the-match-girl.txt --展示文件开头5行
TTLE MATCH GIRL
IT was terribly cold; it snowed and was already almost dark,
and evening came on the last evening of the year.
In the cold and gloom a poor little girl,
bareheaded and barefoot, was walking through the streets.
[root@localhost opt]# head -n2 the-match-girl.txt 道德经.txt --同时展示两个文件的前两行
==> the-match-girl.txt <==
TTLE MATCH GIRL
IT was terribly cold; it snowed and was already almost dark,
==> 道德经.txt <==
《道德经》原文
[root@localhost opt]#