head 命令 – 显示文件开头的内容

head 命令的功能是显示文件开头的内容,默认为前10行。

一、语法格式

head [参数] 文件

二、常用参数

-n <数字>定义显示行数
-c <数字>指定显示头部内容的字符数
-v总是显示文件名的头信息
-q不显示文件名的头信息

三、命令实战

3.1 默认显示文件前10行

 [root@linux1 ~]# head /var/log/messages
 Apr 23 11:01:01 linux1 systemd: Started Session 3 of user root.
 Apr 23 12:01:01 linux1 systemd: Started Session 4 of user root.
 Apr 23 13:11:10 linux1 kernel: e1000: ens32 NIC Link is Down
 Apr 23 13:11:10 linux1 systemd: Time has been changed
 Apr 23 13:11:14 linux1 chronyd[803]: Forward time jump detected!
 Apr 23 13:11:14 linux1 chronyd[803]: Can't synchronise: no selectable sources
 Apr 23 13:11:16 linux1 kernel: e1000: ens32 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
 Apr 23 13:11:16 linux1 NetworkManager[783]: <info>  [1682226676.2885] device (ens32): carrier: link connected
 Apr 23 13:14:29 linux1 chronyd[803]: Selected source 119.28.183.184
 Apr 23 13:16:38 linux1 chronyd[803]: Selected source 202.118.1.81

3.2 指定显示文件前5行内容

 [root@linux1 ~]# head -n 5 /var/log/messages
 Apr 23 11:01:01 linux1 systemd: Started Session 3 of user root.
 Apr 23 12:01:01 linux1 systemd: Started Session 4 of user root.
 Apr 23 13:11:10 linux1 kernel: e1000: ens32 NIC Link is Down
 Apr 23 13:11:10 linux1 systemd: Time has been changed
 Apr 23 13:11:14 linux1 chronyd[803]: Forward time jump detected!
 ​

3.3 指定显示文件前200个字符

 [root@linux1 ~]# head -c 200 /var/log/messages
 Apr 23 11:01:01 linux1 systemd: Started Session 3 of user root.
 Apr 23 12:01:01 linux1 systemd: Started Session 4 of user root.
 Apr 23 13:11:10 linux1 kernel: e1000: ens32 NIC Link is Down
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值