前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >一天一个 Linux 命令(14):head 命令

一天一个 Linux 命令(14):head 命令

作者头像
joshua317
发布2021-09-26 11:08:57
4130
发布2021-09-26 11:08:57
举报
文章被收录于专栏:技术博文

本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/136

一、简介

head 就像它的名字一样的浅显易懂,它是用来查看文件的开头部分的内容

二、格式说明

代码语言:javascript
复制
head [OPTION]... [FILE]...
head [参数]... [文件]...

Usage: head [OPTION]... [FILE]...
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

三、选项说明

代码语言:javascript
复制
-q 隐藏文件名
-v 显示文件名
-c<数目> 显示的字节数。
-n<行数> 显示的行数。

四、命令功能

head 用来查看文件的开头部分的内容,默认head命令打印其相应文件的开头10行。

五、常见用法

1.显示 test.log 文件的开头 10 行
代码语言:javascript
复制
head test.log
2.显示 test.log 文件的开头 5 行
代码语言:javascript
复制
head -n 5 test.log
3.显示test.log 文件前 50 个字节
代码语言:javascript
复制
head -c 50 test.log
4.文件的除了最后 50 个字节以外的内容
代码语言:javascript
复制
head -c -50 test.log
5.输出文件除了最后 10 行的全部内容
代码语言:javascript
复制
head -n -10 test.log

本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/136

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-09-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、简介
  • 二、格式说明
  • 三、选项说明
  • 四、命令功能
  • 五、常见用法
    • 1.显示 test.log 文件的开头 10 行
      • 2.显示 test.log 文件的开头 5 行
        • 3.显示test.log 文件前 50 个字节
          • 4.文件的除了最后 50 个字节以外的内容
            • 5.输出文件除了最后 10 行的全部内容
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档