每日一个linux命令12-less

1. 命令解析

命令用途
与more类似的对输出进行分页显示的命令,但比more的功能更为强大;

命令格式

less [options] file...

命令参数

-b <缓冲区大小> 设置缓冲区的大小
-e 当文件显示结束后,自动离开
-f 强迫打开特殊文件,例如外围设备代号、目录和二进制文件
-g 只标志最后搜索的关键词
-i 忽略搜索时的大小写
-m 显示类似more命令的百分比
-N 显示每行的行号
-o <文件名> 将less 输出的内容在指定文件中保存起来
-Q 不使用警告音
-s 显示连续空行为一行
-S 行过长时间将超出部分舍弃
-x <数字> 将“tab”键显示为规定的数字空格

操作命令

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查看下一个结果
向后查找字符串cd,输入?cd,按n查看下一个结果

退出,按q

文件内容大时,可以设置标签,方便反复查看:
添加标签,先按m进入标签模式,再添加标签名称比如a(标签名称只能为一个字符)
进入标签a的位置,先按'进入选择标签模式,再输入a回到a的位置

你可能感兴趣的:(每日一个linux命令12-less)