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 ~]#