Linux :: 【基础指令篇 :: 文件内容操作:(4)】:: head / tail 指令 :: 查看前后 n 行内容 | 指定查看文件的部分内容

前言:本篇是 Linux 基本操作篇章的内容!
笔者使用的环境是基于腾讯云服务器:CentOS 7.6 64bit。


学习集:


注:本文涉及文件内容查看或编辑,故有预先准备的测试示例,若读者无测试示例,可参照 第 0 点 目录进行操作生成!


目录索引:
0. 测试使用用例命令
1. 基本语法及功能
2. head / tail 无可选参数使用示例及说明
3. head / tail [-x]:指定 x 行显示示例
4. 中间局部内容指定输出
5. 相关文章或系列推荐


0. 测试使用用例命令

count=0; while [ $count -le 100 ]; do echo "hello ${count}"; let count++; done > file.txt
  • 以上命令用于生成 hello x {x:1~100}生成100行数据并写入文件!【注:不要修改命令格式!写法以后会说明!】

1. 基本语法及功能

基本语法:

  • head / tail [option] [file]:【即:指令 + [可选项] + 操作对象】

功能:

  • 指定显示文件部分内容!
  • head:显示文件前 x 行内容!
  • tail:显示文件后 x 行内容!

2. head / tail 无可选参数使用示例及说明

两个命令在无参情况下:默认显示 10 行内容!

/* 注意已有前置文件!笔记查看者无操作文件请回到文章抬头看说明! */

[Mortal@VM-12-16-centos test_txtfile]$ head file.txt 
hello 0
hello 1
hello 2
hello 3
hello 4
hello 5
hello 6
hello 7
hello 8
hello 9
[Mortal@VM-12-16-centos test_txtfile]$ tail file.txt 
hello 91
hello 92
hello 93
hello 94
hello 95
hello 96
hello 97
hello 98
hello 99
hello 100

3. head / tail [-x]:指定 x 行显示示例

/* 注意已有前置文件!笔记查看者无操作文件请回到文章抬头看说明! */

[Mortal@VM-12-16-centos test_txtfile]$ head -5 file.txt 
hello 0
hello 1
hello 2
hello 3
hello 4
[Mortal@VM-12-16-centos test_txtfile]$ tail -15 file.txt 
hello 86
hello 87
hello 88
hello 89
hello 90
hello 91
hello 92
hello 93
hello 94
hello 95
hello 96
hello 97
hello 98
hello 99
hello 100

5. 相关文章或系列推荐

1. Linux 学习目录合集


2. Linux :: 【基础指令篇 :: 文件内容操作:(1)】:: nano 指令 :: 使用自带文件编辑器及简单演示Linux下gcc编译执行可执行程序(仅作了解:会用来创建文件即可)【基本不会用到】
3. Linux :: 【基础指令篇 :: 文件内容操作:(2)】:: cat / tac 指令 :: 正序 / 逆序 查看目标文件的全部内容 及 cat 的补充用法:从标准输入读取内容并输出
4.Linux :: 【基础指令篇 :: 文件内容操作:(3)】:: more / less 指令 :: 查看目标文件的部分或全部内容 | 指定查看前 n 行内容【二者相比推荐使用 less 】


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NPC的白话文谈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值