linux命令大全:head

2019-02-0922:20:24服务器及运维Comments2,365 views字数 1548阅读模式

headtail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示文件的开头至标准输出中,而 tail 想当然尔就是看文件的结尾。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9525.html

1.命令格式

head [参数]... [文件]...
Shell

2.命令功能

head 用来显示档案的开头至标准输出中,默认head命令打印其相应文件的开头10行。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9525.html

3.命令参数

  • -q 隐藏文件名
  • -v 显示文件名
  • -c<字节> 显示字节数
  • -n<行数> 显示的行数

4.使用实例

实例1:显示文件的前n行

命令:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9525.html

head -n 5 log.log
Shell

演示操作及输出:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9525.html

[yiibai@localhost test]$ cat log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.

this is line5.

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.
this is line 15.
this is line 16.
this is line 17.
this is line 18.
this is line 19.
this is line 20.
this is line 21.
this is line 22.

-----------------end
[yiibai@localhost test]$ head -n 5 log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.

[yiibai@localhost test]$
Shell

实例2:显示文件前n个字节

命令:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9525.html

head -c 20 log.log
Shell

演示操作及输出:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9525.html

[yiibai@localhost test]$ head -c 20 log.log
this is line 1.
this[yiibai@localhost test]$
Shell

实例3:文件的除了最后n个字节以外的内容

命令:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9525.html

head -c -32 log.log
Shell

演示操作及输出:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9525.html

[yiibai@localhost test]$ head -c -32 log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.

this is line5.

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.
this is line 15.
this is line 16.
this is line 17.
this is line 18.
this is line 19.
this is line 20.
this is line 21.
[yiibai@localhost test]$
Shell

实例4:输出文件除了最后n行的全部内容

命令:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9525.html

head -n -6 log.log
```shell
演示操作及输出:
```shell
[yiibai@localhost test]$ head -n -6 log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.

this is line5.

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.
this is line 15.
this is line 16.
this is line 17.
this is line 18.
[yiibai@localhost test]$
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9525.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/yunwei/9525.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定