linux基本指令和用法 linux常用命令详解( 七 )



[kingVM-12-11-centos ~]$ less cat.txt

linux基本指令和用法 linux常用命令详解

文章插图
我们输入 /3向上搜索字符3 , less就会帮我们标记字符3的内容
linux基本指令和用法 linux常用命令详解

文章插图
还有其它选项大家可以直接尝试 , 这里就不在演示了 , 我们q退出less界面
head 指令
功能:显示文件内容的开头到标准输出 , 也就是屏幕上 , head不加参数默认显示前10行
选项:
-n<行数>
[kingVM-12-11-centos ~]$ head cat.txt#默认输出前10行
hello 0
hello 1
hello 2
hello 3
hello 4
hello 5
hello 6
hello 7
hello 8
hello 9
[kingVM-12-11-centos ~]$ head -n5 cat.txt#指定输出前5行
hello 0
hello 1
hello 2
hello 3
hello 4
[kingVM-12-11-centos ~]$ head -5 cat.txt# n可以省略
hello 0
hello 1
hello 2
hello 3
hello 4

tail指令
功能:用于显示指定文件末尾内容 , 我们一般日志时肯定是最新的内容 , 也就是从尾部开始 , tail就能很好的帮助我们最近的内容
选项:
  • -f :循环读取
  • -n<行号> :显示行数

tail - f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新,使你看到最新的文件内容 , 非常适合日志

[kingVM-12-11-centos ~]$ tail cat.txt#tail不加行号默认显示尾10行
hello 991
hello 992
hello 993
hello 994
hello 995
hello 996
hello 997
hello 998
hello 999
hello 1000
[kingVM-12-11-centos ~]$ tail -n5 cat.txt#指定显示尾5行


推荐阅读