当前位置: 首页 > news >正文

Linux命令(93)之head

linux命令之head

1.head介绍

linux命令head用来查看文件的前N行内容;默认head查看前10行

2.head用法

head [参数] 文件

head常用参数
参数说明
-n从头显示N行,默认显示10行,可以不写
-q隐藏文件名,在查看两个及以上文件名的情况下有效
-v显示文件名
-c从头显示N字节的内容

3.实例

3.1.显示文件的前5行

命令:

head -n 5 a.txt

OR

head -5 a.txt

[root@centos79-3 ~]# head -n 5 a.txt 
1
2
3
4
5
[root@centos79-3 ~]# head -5 a.txt 
1
2
3
4
5
[root@centos79-3 ~]# 

3.2.显示文件的前5个字节的内容

命令:

head -c 5 a.txt

OR

head -c5 a.txt

[root@centos79-3 ~]# head -c 5 a.txt 
1
2
3[root@centos79-3 ~]# head -c5 a.txt 
1
2
3[root@centos79-3 ~]# 

3.3.显示输出内容的文件名

命令:

head -v a.txt

[root@centos79-3 ~]# head a.txt
1
2
3
4
5
6
7
8
9
10
[root@centos79-3 ~]# head -v a.txt
==> a.txt <==
1
2
3
4
5
6
7
8
9
10
[root@centos79-3 ~]# 

3.4.显示除文件后两行的剩余内容

命令:

head -n -2 a.txt

[root@centos79-3 ~]# cat a.txt 
1
2
3
4
5
6
7
8
9
10
11
12
[root@centos79-3 ~]# head -n -2 a.txt
1
2
3
4
5
6
7
8
9
10
[root@centos79-3 ~]# 

3.5.显示除文件后两个字符的剩余内容

命令:

head -c -2 a.txt

[root@centos79-3 ~]# cat a.txt 
1
2
3
4
5
6
7
8
9
10
11
12
[root@centos79-3 ~]# head -c -2 a.txt
1
2
3
4
5
6
7
8
9
10
11
1[root@centos79-3 ~]# 

3.6.显示内容时隐藏文件的名称

命令:

head -n 5 -q a.txt b.txt

[root@centos79-3 ~]# head -n 5 a.txt b.txt 
==> a.txt <==
1
2
3
4
5==> b.txt <==
1
2
3
4
5
[root@centos79-3 ~]# head -n 5 -q a.txt b.txt 
1
2
3
4
5
1
2
3
4
5
[root@centos79-3 ~]# 

http://www.lryc.cn/news/181724.html

相关文章:

  • 使用Visual Studio调试排查Windows系统程序audiodg.exe频繁弹出报错
  • WebSocket实战之六心跳重连机制
  • Webpack 基础入门以及接入 CSS、Typescript、Babel
  • postgresql-自增字段
  • SpringBoot中使用Servlet和Filter
  • Monkey命令
  • 力扣 -- 279. 完全平方数(完全背包问题)
  • 在将对象 => JSON格式时,无法序列化部分属性
  • 用python表格初级尝试
  • 【单片机】16-LCD1602和12864显示器
  • AUTOSAR从入门到精通-基于 CAN 总线的汽车发电机智能调节器(下)
  • Windows下Tensorflow docker python开发环境搭建
  • idea常用快捷键 idea搜索快捷键
  • Redis Cluster Gossip Protocol: MEET
  • TcpConnection的读写操作【深度剖析】
  • k8s面试题
  • OpenCV 4.x 版本的新特性都有哪些?
  • Redisson—分布式集合
  • 93、Redis 之 使用连接池管理Redis6.0以上的连接 及 消息的订阅与发布
  • doris动态分区开启历史分区
  • Linux用户与权限(认知root用户、修改权限控制 - chmod、修改权限控制 - chown)
  • 处理conda安装工具的动态库问题——解决记录 libssl.1.0.0 系统中所有openssl位置全览 whereis openssl
  • 如何在Go中格式化字符串
  • C程序设计内容与例题讲解 -- 第四章--选择结构程序设计第二部分(第五版)谭浩强
  • 接雨水问题
  • 小谈设计模式(9)—工厂方法模式
  • Android etc1tool之png图片转换pkm 和 zipalign简介
  • Spring Boot快速入门:构建简单的Web应用
  • JAVA 泛型、序列化和复制
  • 以太网基础学习(二)——ARP协议