Linux 日志查看 | more 命令

more命令是一个基于vi编辑器文本过滤器,它以全屏幕的方式按页显示文本文件的内容,支持vi中的关键字定位操作。more名单中内置了若干快捷键,常用的有H(获得帮助信息),Enter(向下翻滚一行),空格(向下滚动一屏),Q(退出命令)。more命令从前向后读取文件,因此在启动时就加载整个文件。

该命令一次显示一屏文本,满屏后停下来,并且在屏幕的底部出现一个提示信息,给出至今己显示的该文件的百分比:–More–(XX%)可以用下列不同的方法对提示做出回答:

  1. 按Space键:显示文本的下一屏内容;
  2. 按Enier键:只显示文本的下一行内容;
  3. 按斜线符|:接着输入一个模式,可以在文本中寻找下一个相匹配的模式;
  4. 按H键:显示帮助屏,该屏上有相关的帮助信息;
  5. 按B键:显示上一屏内容;
  6. 按Q键:退出more命令。
NAME(名称)
       more - file perusal filter for crt viewing
			  文件过滤器

SYNOPSIS(概要,大纲)
       more [options] file [...]

DESCRIPTION(描述)
       more  is  a filter for paging through text one screenful at a time.  
	   This version is especially primitive.  
	   Users should realize that less(1) provides more(1) emulation plus extensive enhancements.
	   more 命令以全屏幕的方式按页显示文本文件的内容。
	   这个版本特别原始。
	   用户应该了解 less 命令提供了比 more 命令更多更强大的功能。

OPTIONS(选项)
       Command-line options are described below.  
	   Options are also taken from the environment variable MORE (make sure to precede them with a dash (``-''))  
	   but  command  line options will override them.
	   命令行选项如下所示。
	   这些选项也可以从环境变量 MORE 中获得(确保在这些选项前面有“-”)
	   另外,命令行选项可以覆盖他们。

       -number
              This option specifies an integer number which is the screen size (in lines).
			  指定每屏显示的行数为 number

       -d     more will prompt the user with the message "[Press space to continue, 'q' to quit.]" 
			  and will display "[Press 'h' for instructions.]" instead of ringing the bell
              when an illegal key is pressed.
			  提示使用者,在画面下方显示 [Press space to continue, 'q' to quit.] ,
			  如果使用者按错键,则会显示 [Press 'h' for instructions.] 而不是 '哔' 声

       -l     more usually treats ^L (form feed) as a special character, 
			  and will pause after any line that contains a form feed.  
			  The -l option will prevent this behavior.
			  取消遇见特殊字元 ^L(送纸字元)时会暂停的功能

       -f     Causes more to count logical, rather than screen lines (i.e., long lines are not folded).
			  计算行数时,以实际上的行数,而非自动换行过后的行数(有些单行字数太长的会被扩展为两行或两行以上)

       -p     Do not scroll.  Instead, clear the whole screen and then display the text.  
			  Notice that this option is switched on automatically if the executable is named page.
			  不以滚动的方式显示每一页,而是先清除萤幕后再显示内容。
			  注意,如果可执行文件被命名为page,那么这个选项就会自动打开。

       -c     Do not scroll.  Instead, paint each screen from the top, clearing the remainder of each line as it is displayed.
			  跟 -p 相似,不同的是先显示内容再清除其他旧资料

       -s     Squeeze multiple blank lines into one.
			  当遇到有连续两行以上的空白行,就代换为一行的空白行

       -u     Suppress underlining.
			  不显示下划线(根据环境变数 TERM 指定的 terminal 而有所不同)

       +/     The +/ option specifies a string that will be searched for before each file is displayed.
			  在每个文档显示前搜寻该字串(string),然后从该字串之后开始显示

       +number
              Start at line number.
			  从文件第 number 行开始显示

COMMANDS(命令)
       Interactive commands for more are based on vi(1).  
	   Some commands may be preceded by a decimal number, called k in the descriptions below.   
	   In  the  following  descriptions, ^X means control-X.
	   more 的交互命令是基于 vi 的。

              h or ?    Help: display a summary of these commands.  
						If you forget all the other commands, remember this one.
						显示所有命令及功能解释。

              SPACE     Display next k lines of text.  Defaults to current screen size.
						显示文件接下来的 k 行。默认为当前的屏幕大小。

              z         Display next k lines of text.  Defaults to current screen size.  Argument becomes new default.
						显示接下来的 k 行。默认为当前的屏幕大小。使用后参数变成默认的。

              RETURN    Display next k lines of text.  Defaults to 1.  Argument becomes new default.
						显示接下来的 k 行。默认为当前的屏幕大小。使用后参数变成默认的。

              d or ^D   Scroll k lines.  Default is current scroll size, initially 11.  Argument becomes new default.
						向下滚动 k 行,默认为当前的滚动大小,初始值是11。使用后参数变成默认的。

              q or Q or INTERRUPT
                        Exit.
						退出

              s         Skip forward k lines of text.  Defaults to 1.
						跳过 k 行。并向前滚动。默认为 1。

              f         Skip forward k screenfuls of text.  Defaults to 1.
						跳过 k 个整屏的文本。默认为 1。

              b or ^B   Skip backwards k screenfuls of text.  Defaults to 1.  Only works with files, not pipes.
						跳过k个大屏幕的文本。默认为1。只处理文件,而不是管道。

			  ´         Go to place where previous search started.
						跳转到之前搜索开始的地方。

              =         Display current line number.
						显示当前的行数。

              /pattern  Search for kth occurrence of regular expression.  Defaults to 1.
						查找正则表达式的第k次出现。默认为1。

              n         Search for kth occurrence of last regular expression.  Defaults to 1.
						查找正则表达式的倒数第k次出现。默认为1。

              !command or :!command
                        Execute command in a subshell.
						在子shell中执行命令。

              v         Start  up  an  editor  at  current  line.   
						The editor is taken from the environment variable VISUAL if defined, 
						or EDITOR if VISUAL is not defined, or defaults to vi if neither VISUAL nor EDITOR is defined.
						在当前行启动编辑器。
						如果定义了环境变量,那么编辑器就会从环境变量中获取,如果没有定义,
						那么编辑器将被定义为vi,如果没有定义可视化和编辑器,则默认为vi。

              ^L        Redraw screen.
						屏幕重绘

              :n        Go to kth next file.  Defaults to 1.
						向前跳转到第K个文件

              :P        Go to kth previous file.  Defaults to 1.
						向回跳转到第K个文件

              :f        Display current file name and line number.
						显示当前的文件名称和行号

              .         Repeat previous command.
						重复上一个命令

ENVIRONMENT(环境)
       More utilizes the following environment variables, if they exist:
	   如果存在以下环境变量,More将使用以下环境变量:

       MORE   This variable may be set with favored options to more.
			  这个变量可以设置more常用的选项。

       SHELL  Current shell in use (normally set by the shell at login time).
			  当前使用的shell(通常在登录时由shell设置)。

       TERM   Specifies terminal type, used by more to get the terminal characteristics necessary to manipulate the screen.
			  指定终端类型,更多地用于获取操作屏幕所需的终端特征。

       VISUAL Editor the user is preferring.  Used when key command v is pressed.
			  用户更喜欢的编辑器。在按下键命令v时使用。

       EDITOR Editor of choise when VISUAL is not specified.
			  当VISUAL环境变量没有被指定时,使用choise编辑器。

1、逐页显示 test.log 文档内容,如有连续两行以上空白行则以一行空白行显示。

[root@peipei3514 usr]# more -s test.log
1 2018-03-02 12:39:06:698 YZXBB
2 2018-03-03 12:40:16:700 VGLHY
3 2018-03-04 12:41:17:701 XANRN

        4 2018-03-05 12:42:22:701 RXNYJ
5 2018-03-06 12:43:14:701 BBUEM
6 2018-03-07 12:44:14:701 FKYDL
7 2018-03-08 12:45:08:701 KAHMA
8 2018-03-09 12:46:14:702 GZZXG
9 2018-03-10 12:47:16:702 OEVDO
10 2018-03-11 12:48:06:702 ALXQQ
11 2018-03-12 12:49:10:702 HOCSQ
--More--(5%)

2、从第 20 行开始显示 testfile 之文档内容。

[root@peipei3514 usr]# more +20 test2.log
220 2018-10-07 19:09:36:781 DJAOD
221 2018-10-08 19:10:31:781 TBYYK
222 2018-10-09 19:11:30:781 LYYPT
223 2018-10-10 19:12:37:781 AXVWT
224 2018-10-11 19:13:33:781 UXSGR
225 2018-10-12 19:14:34:781 TBMJP
226 2018-10-13 19:15:33:781 IMNNK
227 2018-10-14 19:16:23:781 LHEGY
228 2018-10-15 19:17:37:782 YMZPO
--More--(14%)

3、从文件中查找第一个出现"ZCJ"字符串的行,并从该处前两行开始显示输出

[root@peipei3514 usr]# more +/ZCJ test2.log

...跳过
203 2018-09-20 18:52:37:779 UZDCE
204 2018-09-21 18:53:40:779 NCISH
205 2018-09-22 18:54:34:779 ZCJUY
206 2018-09-23 18:55:38:779 SEJKZ
207 2018-09-24 18:56:27:779 CNGMW
208 2018-09-25 18:57:31:779 GLILU
209 2018-09-26 18:58:24:779 VWUSO
210 2018-09-27 18:59:39:779 HDRAT
211 2018-09-28 19:00:40:779 CFGHE
212 2018-09-29 19:01:41:780 VHLIB
213 2018-09-30 19:02:34:780 NMJPE
214 2018-10-01 19:03:29:780 CJWWI
215 2018-10-02 19:04:40:780 HISAY
--More--(7%)

4、设定每屏显示行数

[root@peipei3514 usr]# more -5 test2.log
201 2018-09-18 18:50:25:778 ZHWKD
202 2018-09-19 18:51:26:778 VQGRP
203 2018-09-20 18:52:37:779 UZDCE
204 2018-09-21 18:53:40:779 NCISH
205 2018-09-22 18:54:34:779 ZCJUY
--More--(2%)

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

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

[root@peipei3514 usr]# ls -l| more -5
总用量 116
dr-xr-xr-x.  2 root root 20480 12月 29 15:20 bin
drwxr-xr-x.  2 root root     6 11月  5 2016 etc
drwxr-xr-x.  2 root root     6 11月  5 2016 games
drwxr-xr-x.  3 root root    23 12月 23 23:12 include
--More--

6、显示文件接下来的 5 行

先按数字键5,再按空格键。
  • 3
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值