Linux基础命令[16]-head

1. head 命令说明

head:用来显示文件开头,默认10行,基本信息如下:

DESCRIPTION
       Print  the  first 10 lines of each FILE to standard output.  With more than one FILE, precede each with a header giving the file name.
       With no FILE, or when FILE is -, read standard input.

       head [OPTION]... [FILE]...

DESCRIPTION
       Print  the  first 10 lines of each FILE to standard output.  With more than one FILE, precede each with a header giving the file name.
       With no FILE, or when FILE is -, read standard input.

       Mandatory arguments to long options are mandatory for short options too.

       -c, --bytes=[-]K
              print the first K bytes of each file; with the leading ‘-’, print all but the last K bytes of each file

       -n, --lines=[-]K
              print the first K lines instead of the first 10; with the leading ‘-’, print all but the last K lines of each file

       -q, --quiet, --silent
              never print headers giving file names

       -v, --verbose
              always print headers giving file names

       --help display this help and exit

       --version
              output version information and exit

参数如下:

选项作用
-c显示文件前几个字节内容
-n显示文件前几行内容
-q不显示文件名
-v显示文件名

2. head 命令语法

head [选项] fileName

3. head 命令示例

3.1 不加参数

head fileName

在这里插入图片描述

3.2 -c(按照字节显示)

-c 后面跟数值,表示要显示的字节数,utf-8 字符集时,一个中文三个字节,空格、换行符算一个字节。

head -c num fileName

在这里插入图片描述

如果 -c 后面是 -num,则是显示除了最后 num 个字节外的内容。

举例:显示除了最后5个字节的内容

head -c -5 fileName

在这里插入图片描述

3.3 -n(按照行数显示)

类似 -c ,-n 后面也是数值,代表需要显示的行数,若为负数,则是显示除了后面行数的内容。

另外,head 后面直接加 -num 也可以达到显示前 num 行内容的效果。

head -n num fileName

在这里插入图片描述

3.4 -v(显示文件名)

-q:不显示文件名,-v:显示文件名,在 head 多个文件时有用。

head -v fileName1 fileName2

在这里插入图片描述

4. 总结

head 可显示文件开头内容。

  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值