Linux之head文件开头查看命令

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]# 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值