linux日志命令三more

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/uotail/article/details/87687373

more命令

more命令类似与cat命令,却比cat命令强大,它以全屏幕的方式按页显示文本文件的内容,支持vi中的关键字定位操作。

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

more 20190212-231419.log   

分页显示日志 如有连续两行以上空白行则以一行空白行显示。

在linux命令下输入man more 查看该命令的帮助信息

MORE(1)                                                                                                        User Commands                                                                                                       MORE(1)

NAME
       more - file perusal filter for crt viewing    -文件阅读过滤器crt查看

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(1)提供了更多(1)模拟和广泛的增强。

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).
              此选项指定屏幕大小的整数(以行表示)。
              eg: more -5 20190216-233725.log  一次只显示5行

       -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.
              将提示用户“[按空格键继续,'q'键退出”。,并会显示[按'h'键指示]。,而不是按下非法键时按铃。
              eg: more -d 20190216-233725.log
                  more -5 -d 20190216-233725.log

       -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.

       -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.

       -c     Do not scroll.  Instead, paint each screen from the top, clearing the remainder of each line as it is displayed.

       -s     Squeeze multiple blank lines into one.
              将多个空行压缩到一个空行中。

       -u     Suppress underlining.

       +/     The +/ option specifies a string that will be searched for before each file is displayed.
              +/ 选项指定在显示每个文件之前要搜索的字符串。

       +number
              Start at line 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.
       更多交互式命令基于vi(1)。有些命令前面可能有一个十进制数,在下面的描述中称为k。在以下描述,^X 意思就是control-X.

              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行文本。默认为当前屏幕大小。
                        * 假如我们在按下space键之前按了一个数字键(这个数字为k),则显示k行文本

              z         Display next k lines of text.  Defaults to current screen size.  Argument becomes new default.
                        显示下k行文本。默认为当前屏幕大小。参数成为新的默认值。
                        * 如果按下1然后按z,则当前屏幕默认为1行,每次SPACE只显示1行

              RETURN    Display next k lines of text.  Defaults to 1.  Argument becomes new default.

              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.
                        在当前行启动编辑器。如果定义了编辑器,则从环境变量VISUAL中获取;如果没有定义VISUAL,则从编辑器中获取;如果没有定义VISUAL或编辑器,则从缺省值vi中获取。
              ^L        Redraw screen.
                        屏幕重绘。

              :n        Go to kth next file.  Defaults to 1.
                        转到第k个文件。默认为1。

              :P        Go to kth previous file.  Defaults to 1.
                        转到第k个先前的文件。默认为1。

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

              .         Repeat previous command.
                        重复以前的命令。 

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

2、从第 20 行开始显示 testfile 之文档内容。
more +20 test2.log

3、从文件中查找第一个出现”ZCJ”字符串的行,并从该处前两行开始显示输出
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

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来分页显示。这得和管道 | 结合起来 。

扫描二维码关注公众号,回复: 5419738 查看本文章

[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,再按空格键。

猜你喜欢

转载自blog.csdn.net/uotail/article/details/87687373