Linux less/more命令詳解


    less 的用法比起 more 更加的有彈性。在 more 的時候,我們並沒有辦法向前面翻, 只能往后面看,但若使用了 less 時,就可以使用 [pageup] [pagedown] 等按鍵的功能來往前往后翻看文件,更容易用來查看一個文件的內容!除此之外,在 less 里頭可以擁有更多的搜索功能,不止可以向下搜,也可以向上搜。

less常見命令參數

-a  ........  --search-skip-screen
                 Forward search skips current screen.
 -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.
 -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.
 -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 long lines.
 -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.
               --no-keypad
                 Don't use termcap keypad 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)

more常見命令參數


usage: more [-dflpcsu] [+linenum | +/pattern] name1 name2 ...

 

常用的命令展示

 

顯示文件中從第3行起的內容

more  +3  /etc/passwd

image

從文件中查找第一個出現"omd"字符串的行,並從該處前兩行開始顯示輸出

more +/omd /etc/passwd 【+/pattern 在每個檔案顯示前搜尋該字串(pattern),然后從該字串前兩行之后開始顯示】

設定每屏顯示行數

more -3 /etc/passwd 【-n   定義屏幕大小為n行】

image

列一個目錄下的文件,每4個一列

ls /root/|more –4

more和less的使用技巧

less: -N  顯示行號

    首次展開一頁面

   回車表示一行

   空格表示一屏

  PageUp 向前翻一行

  PageDown向下走

more:

   回車向下

   空格一屏

   PageUp不能向上走

   PageDown向下走

more和less的區別

more

less

只能向下搜

可以隨意瀏覽文件,可以向下,也可向上

加載全文

查看之前不會加載全文

僅可以向下

不止可以向下搜,也可以向上搜。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM