linux命令大全:more

2019-02-0919:58:37服务器及运维Comments2,094 views字数 1648阅读模式

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

1.命令格式

more [-dlfpcsu ] [-num ] [+/ pattern] [+ linenum] 
Shell

2.命令功能

more命令和cat的功能一样都是查看文件里的内容,但有所不同的是more可以按页来查看文件的内容,还支持直接跳转行等功能。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9520.html

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行起的内容
命令:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9520.html

more +3 log.log
Shell

输出:
linux命令大全:more文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9520.html

实例2

从文件中查找第一个出现”line 5“字符串的行,并从该处前两行开始显示输出
命令:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9520.html

 more +/line5 log.log
Shell

输出:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9520.html

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

设定每屏显示行数
命令:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9520.html

more -5 log.log
Shell

输出:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9520.html

[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条内容,百分比也会跟着变化。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9520.html

实例4

列一个目录下的文件,由于内容太多,所以应该学会用more来分页显示。这得和管道 | 结合起来
命令:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9520.html

ls -l  | more -5
Shell

输出:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9520.html

[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条文件信息。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9520.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9520.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/yunwei/9520.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定