• 一天一个 Linux 命令(16):less 命令


    一、简介

    less 与 more 类似,对文件或其它输出进行分页显示less,可以随意浏览文件内容,支持翻页和搜索,支持向上翻页和向下翻页。

    二、格式说明

    less [options] file
    less [参数] 文件 
    

    三、选项说明

      -?  ........  --help
                      Display help (from command line).
      -a  ........  --search-skip-screen
                      Search skips current screen.
      -A  ........  --SEARCH-SKIP-SCREEN
                      Search starts just after target line.
      -b [N]  ....  --buffers=[N]
                      Number of buffers.
      -B  ........  --auto-buffers
                      Don't automatically allocate buffers for pipes.
      -c  -C  ....  --clear-screen --CLEAR-SCREEN
                      Repaint by clearing rather than scrolling.
      -d  ........  --dumb
                      Dumb terminal.
      -D [xn.n]  .  --color=xn.n
                      Set screen colors. (MS-DOS only)
      -e  -E  ....  --quit-at-eof  --QUIT-AT-EOF
                      Quit at end of file.
      -f  ........  --force
                      Force open non-regular files.
      -F  ........  --quit-if-one-screen
                      Quit if entire file fits on first screen.
      -g  ........  --hilite-search
                      Highlight only last match for searches.
      -G  ........  --HILITE-SEARCH
                      Don't highlight any matches for searches.
      --old-bot
                      Revert to the old bottom of screen behavior.
      -h [N]  ....  --max-back-scroll=[N]
                      Backward scroll limit.
      -i  ........  --ignore-case
                      Ignore case in searches that do not contain uppercase.
      -I  ........  --IGNORE-CASE
                      Ignore case in all searches.
      -j [N]  ....  --jump-target=[N]
                      Screen position of target lines.
      -J  ........  --status-column
                      Display a status column at left edge of screen.
      -k [file]  .  --lesskey-file=[file]
                      Use a lesskey file.
      -K            --quit-on-intr
                      Exit less in response to ctrl-C.
      -L  ........  --no-lessopen
                      Ignore the LESSOPEN environment variable.
      -m  -M  ....  --long-prompt  --LONG-PROMPT
                      Set prompt style.
      -n  ........  --line-numbers
                      Don't use line numbers.
      -N  ........  --LINE-NUMBERS
                      Use line numbers.
      -o [file]  .  --log-file=[file]
                      Copy to log file (standard input only).
      -O [file]  .  --LOG-FILE=[file]
                      Copy to log file (unconditionally overwrite).
      -p [pattern]  --pattern=[pattern]
                      Start at pattern (from command line).
      -P [prompt]   --prompt=[prompt]
                      Define new prompt.
      -q  -Q  ....  --quiet  --QUIET  --silent --SILENT
                      Quiet the terminal bell.
      -r  -R  ....  --raw-control-chars  --RAW-CONTROL-CHARS
                      Output "raw" control characters.
      -s  ........  --squeeze-blank-lines
                      Squeeze multiple blank lines.
      -S  ........  --chop-long-lines
                      Chop (truncate) long lines rather than wrapping.
      -t [tag]  ..  --tag=[tag]
                      Find a tag.
      -T [tagsfile] --tag-file=[tagsfile]
                      Use an alternate tags file.
      -u  -U  ....  --underline-special  --UNDERLINE-SPECIAL
                      Change handling of backspaces.
      -V  ........  --version
                      Display the version number of "less".
      -w  ........  --hilite-unread
                      Highlight first new line after forward-screen.
      -W  ........  --HILITE-UNREAD
                      Highlight first new line after any forward movement.
      -x [N[,...]]  --tabs=[N[,...]]
                      Set tab stops.
      -X  ........  --no-init
                      Don't use termcap init/deinit strings.
      -y [N]  ....  --max-forw-scroll=[N]
                      Forward scroll limit.
      -z [N]  ....  --window=[N]
                      Set size of window.
      -" [c[c]]  .  --quotes=[c[c]]
                      Set shell quote characters.
      -~  ........  --tilde
                      Don't display tildes after end of file.
      -# [N]  ....  --shift=[N]
                      Horizontal scroll amount (0 = one half screen width)
          ........  --no-keypad
                      Don't send termcap keypad init/deinit strings.
          ........  --follow-name
                      The F command changes files if the input file is renamed.
          ........  --use-backslash
                      Subsequent options use backslash as escape char.
                      
    -a 跳过当前屏幕搜索
    -A 在目标线之后开始搜索。
    -b <缓冲区大小> 设置缓冲区的大小
    -e 当文件显示结束后,自动离开
    -f 强迫打开特殊文件,例如外围设备代号、目录和二进制文件
    -g 只标志最后搜索的关键词
    -i 忽略搜索时的大小写
    -m 显示类似more命令的百分比
    -N 显示每行的行号
    -o <文件名> 将less 输出的内容在指定文件中保存起来
    -Q 不使用警告音
    -s 显示连续空行为一行
    -S 行过长时间将超出部分舍弃
    -x <数字> 将"tab"键显示为规定的数字空格
    /字符串:向下搜索"字符串"的功能
    ?字符串:向上搜索"字符串"的功能
    n:重复前一个搜索(与 / 或 ? 有关)
    N:反向重复前一个搜索(与 / 或 ? 有关)
    b 向上翻一页
    d 向后翻半页
    h 显示帮助界面
    Q 退出less 命令
    u 向前滚动半页
    y 向前滚动一行
    空格键 滚动一页
    回车键 滚动一行
    [pagedown]: 向下翻动一页
    [pageup]: 向上翻动一页
    

    四、命令功能

    less 与 more 类似,但使用 less 可以随意浏览文件,而 more 仅能向下移动,却不能向上移动,而且 less 在查看之前不会加载整个文件。

    五、常见用法

    1.查看文件

    less /var/log/messages
    

    2.查看文件显示行号

    less -N /var/log/messages
    

    3.浏览多个文件

    less test1.txt test2.txt
    

    4.ps查看进程信息并通过less分页显示

    ps -ef | less
    

    5.查看命令历史使用记录并通过less分页显示

    history | less
    

    6.跳过当前页面进行搜索

    less -N -a /var/log/messages
    

    六、快捷命令

    1.全屏导航

    • ctrl + F - 向前移动一屏
    • ctrl + B - 向后移动一屏
    • ctrl + D - 向前移动半屏
    • ctrl + U - 向后移动半屏

    2.单行导航

    • j - 下一行
    • k - 上一行

    3.其它导航

    • G - 移动到最后一行
    • g - 移动到第一行
    • q / ZZ - 退出 less 命令

    4.其它有用的命令

    • v - 使用配置的编辑器编辑当前文件
    • h - 显示 less 的帮助文档
    • &pattern - 仅显示匹配模式的行,而不是整个文件

    5.标记导航

    当使用 less 查看大文件时,可以在任何一个位置作标记,可以通过命令导航到标有特定标记的文本位置:

    • ma - 使用 a 标记文本的当前位置
    • 'a - 导航到标记 a 处

     

  • 相关阅读:
    关键字查询(含代码)
    数据表的基本操作(含代码)
    Java第一课!
    怎样学好 java ?
    01-C语言程序框架
    00-C语言概述
    RabbitMQ 数万个amq.gen-*的队列,导致内存溢出
    FFmpeg学习笔记1-C++编程
    C++ 应用程序发布相关问题
    动态链接库(DLL)
  • 原文地址:https://www.cnblogs.com/joshua317/p/15321455.html
Copyright © 2020-2023  润新知