LINUX

LINUX LESS指令

介紹

less指令用來檢視檔案且每次僅輸出一頁。

語法

less [options] [files]

常用的options

-c  Clear the screen before displaying the next page. This avoids scrolling and may be more comfortable on the eyes.

-m  Print a more verbose prompt, displaying the percentage of the file displayed so far.

-N  Display line numbers.

-r  Display control characters literally; normally less converts them to a human-readable format.

-s  Squeeze multiple, adjacent blank lines into a single blank line.

-S  Truncate long lines to the width of the screen, instead of wrapping.

常用的按鍵

h, H                  View a help page.

Space bar, f, ^V, ^F  Move forward one screenful.

Enter                 Move forward one line.

b, ^B, ESC-v          Move backward one screenful.

/                     Enter search mode. Follow it with a regular expression and press Enter, and less will look for the first matching line.

?                     Same as /, but it searches backward in the file.

n                     Next match: Repeat your most recent search forward.

N                     Repeat your most recent search backward.

v                     Edit the current file with your default text editor (the value of environment variable VISUAL, or if not defined, EDITOR, or if not defined, the program vi).

<, g                  Jump to beginning of file.

>, G                  Jump to end of file.

:n                    Jump to next file.

:p                    Jump to previous file.

範例

你可以檢視檔案且每次僅輸出一頁:

⤍ less myfile

常常搭配管線來閱讀最後的輸出:

⤍ command1 | command2 | command3 | less

發佈留言