每天一个linux命令:head(15)

时间:2019-11-03
本文章向大家介绍每天一个linux命令:head(15),主要包括每天一个linux命令:head(15)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

head

head命令用于显示文件的开头的内容。在默认情况下,head命令显示文件的头10行内容。

格式

head [参数] [文件]

参数选项

参数 备注
-q 不显示文件名的头信息
-v 总是显示文件名的头信息
-c <字节> 显示字节数
-n <行数> 显示的行数

实例

  • 显示文件的前n行

    命令: head -n 5 myFile

[root@VM_0_9_centos ~]# cat myFile
this is line 1;
this is line 2;
this is line 3;
tihs is line 4;
this is line 5;
this is line 6;
this is line 7;
this is line 8;
this is line 9;
this is line 10;
this is line 11;
this is line 12;
this is line 13;
this is line 14;
[root@VM_0_9_centos ~]# head -n 5 myFile
this is line 1;
this is line 2;
this is line 3;
tihs is line 4;
this is line 5;
  • 显示文件前n个字节

    命令: head -c 10 myFile

[root@VM_0_9_centos ~]# head -c 10 myFile
this is li
[root@VM_0_9_centos ~]# 
  • 文件的除了最后n个字节以外的内容

命令: head -c -10 myFile

root@VM_0_9_centos ~]# head -c 10 myFile
this is li[root@VM_0_9_centos ~]# head -c -10 myFile
this is line 1;
this is line 2;
this is line 3;
tihs is line 4;
this is line 5;
this is line 6;
this is line 7;
this is line 8;
this is line 9;
this is line 10;
this is line 11;
this is line 12;
this is line 13;
this is
[root@VM_0_9_centos ~]# 
  • 输出文件除了最后n行的全部内容

    命令: head -n -6 myFile

[root@VM_0_9_centos ~]# head -n -10 myFile
this is line 1;
this is line 2;
this is line 3;
tihs is line 4;
[root@VM_0_9_centos ~]# 

参考

原文地址:https://www.cnblogs.com/DiDi516/p/11789132.html