01
more命令
首先我们看看more命令,more命令有几个常用的参数,如下:
+n:从第n行开始显示
-n:定义屏幕的大小为n行
-s:将连续的过个空行显示为一行
+/string:从匹配string的那一行开始显示
接下来是测试环节,首先我们使用下面的脚本创建一个aaa.txt的文本文件,里面循环写了一些文字:
#!/bin/bash for((i=;i<=;i++)); do echo "this is line $i">>aaa.txt; done
然后我们使用more命令打开这个aaa的文件:
[dba_mysql /tmp]$cat aaa.txt|more -20 this is line this is line this is line this is line this is line this is line this is line this is line this is line this is line this is line this is line this is line this is line this is line this is line this is line this is line this is line this is line
我们使用了-20这样的方式,让当前页面只显示20行内容。此时我们按q键退出当前的观察模式。
当我们想要从第90行开始显示的时候,可以使用+90的命令,如下:
[dba_mysql /tmp]$cat aaa.txt|more + this is line this is line this is line this is line this is line this is line this is line this is line this is line this is line this is line
如果我们想要从包含50这个字符串的那一行开始的话,可以使用如下命令:
[dba_mysql /tmp]$cat aaa.txt|more +/50 this is line 51 this is line 52 this is line 53 this is line 54 this is line 55 this is line 56 this is line 57 this is line 58 this is line 59 this is line 60 this is line 61 this is line 62 this is line 63 this is line 64 this is line 65 this is line 66 this is line 67 this is line 68 this is line 69 this is line 70
当我们的文件中包含多个空行时,如果我们想要将这些空行显示为一行,那么可以使用-s命令,如下:
[dba_mysql /tmp]$cat bbb.txt aaaa bbbb cccc dddd [dba_mysql@ /tmp]$cat bbb.txt|more -s aaaa bbbb cccc dddd
除了常用的这几个命令,还有一些快捷键:
空格:向下翻页
q:退出观察模式
回车:向下滚动一行
b:向上翻页
=:输出当前行的行号
:f:输出当前文件名称和行号
v:调用vim,这个功能一般在找到匹配项之后使用。
除此之外,还有一些其他的参数和快捷键,但是不太用到,所以就没有列出来,有兴趣可以看看。
02
less命令
less命令和more命令比较像,但是less命令的可用性更好一些。如下:
-e 当文件显示结束后,自动离开
-i 忽略搜索时的大小写
-m 显示类似more命令的百分比
-N 显示每行的行号
-o <文件名> 将less 输出的内容在指定文件中保存起来
-Q 不使用警告音
-s 显示连续空行为一行
[dba_mysql /tmp]$less -mN aaa.txt
this is line
this is line
this is line
this is line
this is line
this is line
this is line
this is line
this is line
aaa.txt %
其中-m是显示百分比,-N是显示行号。
一般情况下,less是搭配一些管道运算符一起的,例如:
ls -lrt|less
cat aaa.txt|less
除此之外,还有一些快捷键,其实和vim里面的操作很像,如下:
/字符串:向下搜索"字符串"的功能
?字符串:向上搜索"字符串"的功能
n:重复前一个搜索(与 / 或 ? 有关)
N:反向重复前一个搜索(与 / 或 ? 有关)
d 向后翻半页
u 向前滚动半页
y 向前滚动一行
空格键 滚动一行
ctrl + F - 向前移动一屏
ctrl + B - 向后移动一屏
ctrl + D - 向前移动半屏
ctrl + U - 向后移动半屏
j - 向前移动一行
k - 向后移动一行
G - 移动到最后一行
g - 移动到第一行
q / ZZ - 退出 less 命令
v - 使用配置的编辑器编辑当前文件
继续阅读与本文标签相同的文章
MySQL中undo日志介绍
MySQL中两个小的优化案例
-
Unity 3D-Navigation网格导航系统使用教程
2026-05-27栏目: 教程
-
C#正则表达式语法教程
2026-05-27栏目: 教程
-
Unity 3D-AR开发-Vuforia教程手册
2026-05-27栏目: 教程
-
VS 提升代码辨识度 (工欲善其事必先利其器)新手开发必备!
2026-05-27栏目: 教程
-
Lua基本语法-lua与C#的交互(相当简单详细的例子)
2026-05-27栏目: 教程
