linux命令大全:more

2023年 7月 11日 44.6k 0

more命令,功能类似 catcat命令是整个文件的内容从上到下显示在屏幕上。more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会往回(back)一页显示,而且还有搜寻字串的功能 。more命令从前向后读取文件,因此在启动时就加载整个文件。

1.命令格式

more [-dlfpcsu ] [-num ] [+/ pattern] [+ linenum] 下载地址

Shell

2.命令功能

more命令和cat的功能一样都是查看文件里的内容,但有所不同的是more可以按页来查看文件的内容,还支持直接跳转行等功能。

3.命令参数

  • +n 从笫n行开始显示
  • -n 定义屏幕大小为n
  • +/pattern 在每个档案显示前搜寻该字串(pattern),然后从该字串前两行之后开始显示
  • -c 从顶部清屏,然后显示
  • -d 提示“Press space to continue,’q’ to quit(按空格键继续,按q键退出)”,禁用响铃功能
  • -l 忽略Ctrl+l(换页)字符
  • -p 通过清除窗口而不是滚屏来对文件进行换页,与-c选项相似
  • -s 把连续的多个空行显示为一行
  • -u 把文件内容中的下画线去掉

4.常用操作命令

  • Enter 向下n行,需要定义。默认为1
  • Ctrl+F 向下滚动一屏
  • 空格键 向下滚动一屏
  • Ctrl+B 返回上一屏
  • = 输出当前行的行号
  • :f 输出文件名和当前行的行号
  • V 调用vi编辑器
  • ! 命令, 调用Shell,并执行命令
  • q 退出more

5.命令实例

实例1

显示文件中从第3行起的内容 命令:

more +3 log.log

Shell

输出: linux命令大全:more

实例2

从文件中查找第一个出现”line 5“字符串的行,并从该处前两行开始显示输出 命令:

 more +/line5 log.log

Shell

输出:

this is line 4.

this is line5.

this is line 6.
this is line 7.
this is line 8.
this is line 9.
this is line 10.
this is line 11.
this is line 12.
this is line 13.
this is line 14.
this is line 15.
this is line 16.
this is line 17.
this is line 18.
--More--(76%)

Shell

实例3

设定每屏显示行数 命令:

more -5 log.log

Shell

输出:

[yiibai@localhost test]$ more -5 log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.

--More--(16%)

Shell

说明:如上面所示--More--(16%),最下面显示了该屏展示的内容占文件总行数的比例,按 Ctrl+F 或者 空格键 将会显示下一屏5条内容,百分比也会跟着变化。

实例4

列一个目录下的文件,由于内容太多,所以应该学会用more来分页显示。这得和管道 | 结合起来 命令:

ls -l  | more -5

Shell

输出:

[yiibai@localhost /]$ pwd
/
[yiibai@localhost /]$ ls -l  | more -5
total 20
lrwxrwxrwx.   1 root root    7 Feb 12 22:20 bin -> usr/bin
dr-xr-xr-x.   4 root root 4096 Feb 12 22:32 boot
drwxr-xr-x.  20 root root 3240 Feb 13 19:38 dev
drwxr-xr-x.  78 root root 8192 Feb 13 19:29 etc
drwxr-xr-x.   3 root root   20 Feb 12 22:29 home
lrwxrwxrwx.   1 root root    7 Feb 12 22:20 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Feb 12 22:20 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 Nov  5 11:38 media
--More--

Shell

说明:每页显示5个文件信息,按 Ctrl+F 或者 空格键 将会显示下5条文件信息。

相关文章

服务器端口转发,带你了解服务器端口转发
服务器开放端口,服务器开放端口的步骤
产品推荐:7月受欢迎AI容器镜像来了,有Qwen系列大模型镜像
如何使用 WinGet 下载 Microsoft Store 应用
百度搜索:蓝易云 – 熟悉ubuntu apt-get命令详解
百度搜索:蓝易云 – 域名解析成功但ping不通解决方案

发布评论