显示文件的头部

head [options] [file-list]

 

参数

file-list 为要head显示的文件的路径名列表。当指定多个文件时,head在显示每个文件的前几行内容之前显示对应的文件名

当不指定文件时,head将从标准输入获得输入

 

选项

-c n                显示文件的前n个字节(字符)

-n n                显示文件的前n行,也可以使用-n来指定显示的n行

-q                   当在命令行上指定多个文件名时,它禁止显示头部

 

注意

默认情况下,head将显示文件的前10行

 

示例

原文件

$ cat demo
line one
line two
line three
line four
line five
line six
line seven
line eight
line nine
line ten
line eleven

 

head

$ head demo
line one
line two
line three
line four
line five
line six
line seven
line eight
line nine
line ten

默认显示10行

 

head -n

$ head -n 4 demo
line one
line two
line three
line four

显示指定的行数

 

head -n 负数

$ head -n -4 demo
line one
line two
line three
line four
line five
line six
line seven

显出除最后4行外的其他行

 

head -3 多个文件

$ head -3 demo dd
==> demo <==
line one
line two
line three

==> dd <==
line one
line two
line three

显示多个文件的前3行

 

head -c

$ head -c 4 demo
line$ 

显示文件的前4个字符,注意此处不换行

 

 

 

相关文章:

  • 2021-11-22
  • 2021-12-14
  • 2022-02-28
  • 2021-07-16
  • 2021-10-19
  • 2021-11-08
  • 2021-08-27
  • 2022-01-14
猜你喜欢
  • 2021-12-19
  • 2021-09-17
  • 2021-05-28
  • 2021-10-04
  • 2022-01-10
  • 2021-06-01
  • 2021-06-11
相关资源
相似解决方案