辨析cat、more、less的用法

使用cat more less都可以查看文本內容,但是它們三者有什麼區別呢?
more和less的功能完全重複嗎?
以下是我個人的總結,歡迎大家一起來分享

cat        連續顯示、查看文件內容
more        分頁查看文件內容
less        分頁可控制查看文件內容

通俗點說:
cat一次性把文件內容全部顯示出來,管你看不看得清,顯示完了cat命令就返回了,不能進行交互式操作,適合察看內容短小、不超過一屏的文件;
more比cat強大一點,支持分頁顯示,你可以ctrl+B ctrl+F .....上下滾屏,但是不支持像shift+G(跳到文件尾)這種操作;
less比more更強大一點,支持各種命令,隨便翻頁、跳轉、查找.....想怎麼看,就怎麼看,愛怎麼看,就怎麼看。

附less的幫助內容


  1.                    SUMMARY OF LESS COMMANDS

  2.       Commands marked with * may be preceded by a number, N.
  3.       Notes in parentheses indicate the behavior if N is given.

  4.   h  H                 Display this help.
  5.   q  :q  Q  :Q  ZZ     Exit.
  6. ---------------------------------------------------------------------------

  7.                            MOVING

  8.   e  ^E  j  ^N  CR  *  Forward  one line   (or N lines).
  9.   y  ^Y  k  ^K  ^P  *  Backward one line   (or N lines).
  10.   f  ^F  ^V  SPACE  *  Forward  one window (or N lines).
  11.   b  ^B  ESC-v      *  Backward one window (or N lines).
  12.   z                 *  Forward  one window (and set window to N).
  13.   w                 *  Backward one window (and set window to N).
  14.   ESC-SPACE         *  Forward  one window, but don't stop at end-of-file.
  15.   d  ^D             *  Forward  one half-window (and set half-window to N).
  16.   u  ^U             *  Backward one half-window (and set half-window to N).
  17.   ESC-)  RightArrow *  Left  one half screen width (or N positions).
  18.   ESC-(  LeftArrow  *  Right one half screen width (or N positions).
  19.   F                    Forward forever; like "tail -f".
  20.   r  ^R  ^L            Repaint screen.
  21.   R                    Repaint screen, discarding buffered input.
  22.         ---------------------------------------------------
  23.         Default "window" is the screen height.
  24.         Default "half-window" is half of the screen height.
  25. ---------------------------------------------------------------------------

  26.                           SEARCHING

  27.   /pattern          *  Search forward for (N-th) matching line.
  28.   ?pattern          *  Search backward for (N-th) matching line.
  29.   n                 *  Repeat previous search (for N-th occurrence).
  30.   N                 *  Repeat previous search in reverse direction.
  31.   ESC-n             *  Repeat previous search, spanning files.
  32.   ESC-N             *  Repeat previous search, reverse dir. & spanning files.
  33.   ESC-u                Undo (toggle) search highlighting.
  34.         ---------------------------------------------------
  35.         Search patterns may be modified by one or more of:
  36.         ^N or !  Search for NON-matching lines.
  37.         ^E or *  Search multiple files (pass thru END OF FILE).
  38.         ^F or @  Start search at FIRST file (for /) or last file (for ?).
  39.         ^K       Highlight matches, but don't move (KEEP position).
  40.         ^R       Don't use REGULAR EXPRESSIONS.
  41. ---------------------------------------------------------------------------

  42.                            JUMPING

  43.   g  <  ESC-<       *  Go to first line in file (or line N).
  44.   G  >  ESC->       *  Go to last line in file (or line N).
  45.   p  %              *  Go to beginning of file (or N percent into file).
  46.   t                 *  Go to the (N-th) next tag.
  47.   T                 *  Go to the (N-th) previous tag.
  48.   {  (  [           *  Find close bracket } ) ].
  49.   }  )  ]           *  Find open bracket { ( [.
  50.   ESC-^F <c1> <c2>  *  Find close bracket <c2>.
  51.   ESC-^B <c1> <c2>  *  Find open bracket <c1> 
  52.         ---------------------------------------------------
  53.         Each "find close bracket" command goes forward to the close bracket 
  54.           matching the (N-th) open bracket in the top line.
  55.         Each "find open bracket" command goes backward to the open bracket 
  56.           matching the (N-th) close bracket in the bottom line.

  57.   m<letter>            Mark the current position with <letter>.
  58.   '<letter>            Go to a previously marked position.
  59.   ''                   Go to the previous position.
  60.   ^X^X                 Same as '.
  61.         ---------------------------------------------------
  62.         A mark is any upper-case or lower-case letter.
  63.         Certain marks are predefined:
  64.              ^  means  beginning of the file
  65.              $  means  end of the file
  66. ---------------------------------------------------------------------------

  67.                         CHANGING FILES

  68.   :e [file]            Examine a new file.
  69.   ^X^V                 Same as :e.
  70.   :n                *  Examine the (N-th) next file from the command line.
  71.   :p                *  Examine the (N-th) previous file from the command line.
  72.   :x                *  Examine the first (or N-th) file from the command line.
  73.   :d                   Delete the current file from the command line list.
  74.   =  ^G  :f            Print current file name.
  75. ---------------------------------------------------------------------------

  76.                     MISCELLANEOUS COMMANDS

  77.   -<flag>              Toggle a command line option [see OPTIONS below].
  78.   --<name>             Toggle a command line option, by name.
  79.   _<flag>              Display the setting of a command line option.
  80.   __<name>             Display the setting of an option, by name.
  81.   +cmd                 Execute the less cmd each time a new file is examined.

  82.   !command             Execute the shell command with $SHELL.
  83.   |Xcommand            Pipe file between current pos & mark X to shell command.
  84.   v                    Edit the current file with $VISUAL or $EDITOR.
  85.   V                    Print version number of "less".
  86. ---------------------------------------------------------------------------

  87.                            OPTIONS

  88.         Most options may be changed either on the command line,
  89.         or from within less by using the - or -- command.
  90.         Options may be given in one of two forms: either a single
  91.         character preceded by a -, or a name preceeded by --.

  92.   -?  ........  --help
  93.                   Display help (from command line).
  94.   -a  ........  --search-skip-screen
  95.                   Forward search skips current screen.
  96.   -b [N]  ....  --buffers=[N]
  97.                   Number of buffers.
  98.   -B  ........  --auto-buffers
  99.                   Don't automatically allocate buffers for pipes.
  100.   -c  -C  ....  --clear-screen  --CLEAR-SCREEN
  101.                   Repaint by scrolling/clearing.
  102.   -d  ........  --dumb
  103.                   Dumb terminal.
  104.   -D [xn.n]  .  --color=xn.n
  105.                   Set screen colors. (MS-DOS only)
  106.   -e  -E  ....  --quit-at-eof  --QUIT-AT-EOF
  107.                   Quit at end of file.
  108.   -f  ........  --force
  109.                   Force open non-regular files.
  110.   -F  ........  --quit-if-one-screen
  111.                   Quit if entire file fits on first screen.
  112.   -g  ........  --hilite-search
  113.                   Highlight only last match for searches.
  114.   -G  ........  --HILITE-SEARCH
  115.                   Don't highlight any matches for searches.
  116.   -h [N]  ....  --max-back-scroll=[N]
  117.                   Backward scroll limit.
  118.   -i  ........  --ignore-case
  119.                   Ignore case in searches that do not contain uppercase.
  120.   -I  ........  --IGNORE-CASE
  121.                   Ignore case in all searches.
  122.   -j [N]  ....  --jump-target=[N]
  123.                   Screen position of target lines.
  124.   -J  ........  --status-column
  125.                   Display a status column at left edge of screen.
  126.   -k [file]  .  --lesskey-file=[file]
  127.                   Use a lesskey file.
  128.   -L  ........  --no-lessopen
  129.                   Ignore the LESSOPEN environment variable.
  130.   -m  -M  ....  --long-prompt  --LONG-PROMPT
  131.                   Set prompt style.
  132.   -n  -N  ....  --line-numbers  --LINE-NUMBERS
  133.                   Use line numbers.
  134.   -o [file]  .  --log-file=[file]
  135.                   Copy to log file (standard input only).
  136.   -O [file]  .  --LOG-FILE=[file]
  137.                   Copy to log file (unconditionally overwrite).
  138.   -p [pattern]  --pattern=[pattern]
  139.                   Start at pattern (from command line).
  140.   -P [prompt]   --prompt=[prompt]
  141.                   Define new prompt.
  142.   -q  -Q  ....  --quiet  --QUIET  --silent --SILENT
  143.                   Quiet the terminal bell.
  144.   -r  -R  ....  --raw-control-chars  --RAW-CONTROL-CHARS
  145.                   Output "raw" control characters.
  146.   -s  ........  --squeeze-blank-lines
  147.                   Squeeze multiple blank lines.
  148.   -S  ........  --chop-long-lines
  149.                   Chop long lines.
  150.   -t [tag]  ..  --tag=[tag]
  151.                   Find a tag.
  152.   -T [tagsfile] --tag-file=[tagsfile]
  153.                   Use an alternate tags file.
  154.   -u  -U  ....  --underline-special  --UNDERLINE-SPECIAL
  155.                   Change handling of backspaces.
  156.   -V  ........  --version
  157.                   Display the version number of "less".
  158.   -w  ........  --hilite-unread
  159.                   Highlight first new line after forward-screen.
  160.   -W  ........  --HILITE-UNREAD
  161.                   Highlight first new line after any forward movement.
  162.   -x [N[,...]]  --tabs=[N[,...]]
  163.                   Set tab stops.
  164.   -X  ........  --no-init
  165.                   Don't use termcap init/deinit strings.
  166.                 --no-keypad
  167.                   Don't use termcap keypad init/deinit strings.
  168.   -y [N]  ....  --max-forw-scroll=[N]
  169.                   Forward scroll limit.
  170.   -z [N]  ....  --window=[N]
  171.                   Set size of window.
  172.   -" [c[c]]  .  --quotes=[c[c]]
  173.                   Set shell quote characters.
  174.   -~  ........  --tilde
  175.                   Don't display tildes after end of file.
  176.   -# [N]  ....  --shift=[N]
  177.                   Horizontal scroll amount (0 = one half screen width)

  178. ---------------------------------------------------------------------------

  179.                           LINE EDITING

  180.         These keys can be used to edit text being entered 
  181.         on the "command line" at the bottom of the screen.

  182. RightArrow                       ESC-l     Move cursor right one character.
  183. LeftArrow                        ESC-h     Move cursor left one character.
  184. CNTL-RightArrow  ESC-RightArrow  ESC-w     Move cursor right one word.
  185. CNTL-LeftArrow   ESC-LeftArrow   ESC-b     Move cursor left one word.
  186. HOME                             ESC-0     Move cursor to start of line.
  187. END                              ESC-$     Move cursor to end of line.
  188. BACKSPACE                                  Delete char to left of cursor.
  189. DELETE                           ESC-x     Delete char under cursor.
  190. CNTL-BACKSPACE   ESC-BACKSPACE             Delete word to left of cursor.
  191. CNTL-DELETE      ESC-DELETE      ESC-X     Delete word under cursor.
  192. CNTL-U           ESC (MS-DOS only)         Delete entire line.
  193. UpArrow                          ESC-k     Retrieve previous command line.
  194. DownArrow                        ESC-j     Retrieve next command line.
  195. TAB                                        Complete filename & cycle.
  196. SHIFT-TAB                        ESC-TAB   Complete filename & reverse cycle.
  197. CNTL-L                                     Complete filename, list all.

  198. HELP -- END -- Press g to see it again, or q when done
複製代碼
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章