简述
使用 cat 命令查看文件时,如果文件有很多内容,会出现滚屏现象,这时可以使用 more 或者 less 命令来查看,more 和 less 可以单独使用,也可以和其他命令组合使用。
| 版权声明:一去、二三里,未经博主允许不得转载。
命令介绍
- 命令名称
more - 基本语法
more [选项] 文件… - 功能描述
more 是 一个过滤器,用于分页显示(一次一屏)文本。
命令选项
选项 | 说明 |
| 显示帮助,而不是响铃 |
| 统计逻辑行数而不是屏幕行数 |
| 抑制换页(form feed)后的暂停 |
| 不滚屏,清屏并显示文本 |
| 不滚屏,显示文本并清理行尾 |
| 抑制下划线 |
| 将多个空行压缩为一行 |
| 指定每屏显示的行数为 NUM |
| 从文件第 NUM 行开始显示 |
| 从匹配搜索字符串 STRING 的文件位置开始显示 |
| 显示版本信息并退出 |
交互式命令
more 的交互命令基于 vi
,有些命令以一个十进制数字开始,在下面的描述里称之为 k
。后面的描述中,^X
指 control-X
。
-
h 或 ?
:帮助,显示这些命令的摘要,如果忘掉所有其他的命令, 请记住这个。 -
SPACE
:显示接下来的 k 行文本,缺省值是当前的屏幕大小。 -
z
:显示接下来的 k 行文本,缺省值是当前的屏幕大小,参数成为新的缺省值。 -
RETURN
:显示接下来的 k 行文本,缺省值是 1,参数成为新的缺省值。 -
d 或 ^D
:卷屏 k 行,缺省值是当前的卷屏大小,初始化为 11,参数成为新的缺省值。 -
q 或 Q 或 INTERRUPT
:退出 more 命令 -
s
:向前跳过 k 行文本,缺省值是 1。 -
f
:向前跳过 k 屏文本,缺省值是 1。 -
b 或 ^B
:向后跳回 k 屏文本,缺省值是 1。 -
'
:跳到上一次搜索开始的地方。 -
=
:显示当前行号 -
/pattern
:搜索第 k 个 符合正则表达式的文本串,缺省值是 1。 -
n
:搜索最后第 k 个符合正则表达式的文本串,缺省值是 1。 -
!<cmd>
或:!<cmd>
:在子 shell 中执行<cmd>
。 -
v
:启动/usr/bin/vi
,指向当前行。 -
^L
:刷新屏幕。 -
:n
:跳到后面第 k 个文件,缺省值是 1。 -
:p
:跳到前面第 k 个文件,缺省值是 1。 -
:f
:显示当前文件名和行号。 -
.
:重复上次命令。
more 命令一次显示一屏文本,满屏后停下来,并且在屏幕的底部出现一个提示信息,给出至今己显示的该文件的百分比:--More--(XX%)
,可以用上述命令进行交互。
使用范例
1.查看文件内容
查看一个关于 Python 安装包中的 README 文件,由于文件内容过多,使用 more README
来分页显示。
可以看到,屏幕的底部出现一个提示信息,给出至今己显示的该文件的百分比(15%)。
2.设定每屏显示行数
使用选项 -NUM
,指定每屏显示的行数为,这里指定显示 5 行。
3.从文件第 NUM 行开始显示
使用选项 +NUM
,从文件第 NUM 行开始显示,这里从第 10 行开始显示。
4.从匹配搜索字符串 STRING 的文件位置开始显示
使用选项 +/STRING
,从文件中查找第一个出现“Unix”字符串的行,并从该处前两行开始显示输出。
5.和其他命令组合使用
列出一个目录下的文件,如果内容过多,可以用 more 来分页显示,需要和管道 |
结合起来。
less 命令的作用与 more 十分相似,都可以用来按页显示文件,不同之处在于 less 命令在显示文件时允许用户既可以向前又可以向后翻阅文件。而 more 命令只能向前浏览。用 less 命令显示文件时,用 PageUp 键向上翻页,用 PageDown 键向下翻页。若要在文件中往前移动,按 b 键;要移动到文件的百分比表示的某位置,则指定一个 0 ~ 100 之间的数,并按 p 键盘即可。less 命令使用与 more 类似,在此就不再赘述了,如有不清楚的地方查看联机帮助。