1. 命令解析
命令用途:
與more類似的對輸出進行分頁顯示的命令,但比more的功能更為強大;
命令格式:
less [options] file...
命令參數(shù):
-b <緩沖區(qū)大小> 設(shè)置緩沖區(qū)的大小
-e 當文件顯示結(jié)束后,自動離開
-f 強迫打開特殊文件,例如外圍設(shè)備代號、目錄和二進制文件
-g 只標志最后搜索的關(guān)鍵詞
-i 忽略搜索時的大小寫
-m 顯示類似more命令的百分比
-N 顯示每行的行號
-o <文件名> 將less 輸出的內(nèi)容在指定文件中保存起來
-Q 不使用警告音
-s 顯示連續(xù)空行為一行
-S 行過長時間將超出部分舍棄
-x <數(shù)字> 將“tab”鍵顯示為規(guī)定的數(shù)字空格
操作命令
MOVING
e ^E j ^N CR * Forward one line (or N lines).
y ^Y k ^K ^P * Backward one line (or N lines).
f ^F ^V SPACE * Forward one window (or N lines).
b ^B ESC-v * Backward one window (or N lines).
z * Forward one window (and set window to N).
w * Backward one window (and set window to N).
ESC-SPACE * Forward one window, but don't stop at end-of-file.
d ^D * Forward one half-window (and set half-window to N).
u ^U * Backward one half-window (and set half-window to N).
ESC-) RightArrow * Left one half screen width (or N positions).
ESC-( LeftArrow * Right one half screen width (or N positions).
F Forward forever; like "tail -f".
r ^R ^L Repaint screen.
R Repaint screen, discarding buffered input.
SEARCHING
/pattern * Search forward for (N-th) matching line.
?pattern * Search backward for (N-th) matching line.
n * Repeat previous search (for N-th occurrence).
N * Repeat previous search in reverse direction.
ESC-n * Repeat previous search, spanning files.
ESC-N * Repeat previous search, reverse dir. & spanning files.
ESC-u Undo (toggle) search highlighting.
&pattern * Display only matching lines
JUMPING
g < ESC-< * Go to first line in file (or line N).
G > ESC-> * Go to last line in file (or line N).
p % * Go to beginning of file (or N percent into file).
t * Go to the (N-th) next tag.
T * Go to the (N-th) previous tag.
{ ( [ * Find close bracket } ) ].
} ) ] * Find open bracket { ( [.
2. 示例
2.1 分頁查看文件
less f1
2.2 分頁查看ps的輸出
ps -ef| less
2.3 瀏覽多個文件
less f1 f2
2.4 常用命令
前翻一頁按f
后翻一頁按b
前翻一行按e
后翻一行按y
回到首行,按g
回到末行,按G
向前查找字符串cd,輸入/cd,按n查看下一個結(jié)果
向后查找字符串cd,輸入?cd,按n查看下一個結(jié)果
退出,按q
文件內(nèi)容大時,可以設(shè)置標簽,方便反復(fù)查看:
添加標簽,先按m進入標簽?zāi)J剑偬砑訕撕灻Q比如a(標簽名稱只能為一個字符)
進入標簽a的位置,先按'進入選擇標簽?zāi)J?,再輸入a回到a的位置