less 工具也是对文件或其他输出进行分页显示的工具,应该说是 Linux 正统查看文件的工具,功能极其强大。less 的用法比 more 更加有弹性。在 more 的时候,我们没有办法向前翻页,只能往后面看,但若使用 less ,就可以使用 [pageup] [pagedown] 等按键的功能来往前往后翻页查看文件。此外,在 less 里还拥有更多的搜索功能,比如向下搜索,向上搜索。
命令格式 - less [参数] 文件
命令功能 - 与 more 类似,可以随意浏览文件,并且 less 在查看之前不会加载整个文件;
命令参数 -
命令内部操作 -
按键功能如下 :
搜索 :
全屏导航 :
单行导航 :
其他导航 :
编辑文件 :
标记导航 :
命令实例 -
实例一:查看文件
命令
xxxxxxxxxx11less log.log输出
xxxxxxxxxx81Qs-MacBook-Pro:dir1 qiu$ less log.log22019-0132019-0242019-03562019-0472019-058log.log (END)实例二:ps查看进程信息并通过 less 分页显示
命令
xxxxxxxxxx11ps -ef | less输出
xxxxxxxxxx181Qs-MacBook-Pro:dir1 qiu$ ps -ef | less2UID PID PPID C STIME TTY TIME CMD3 0 1 0 0 4 419 ?? 36:23.20 /sbin/launchd4 0 33 1 0 4 419 ?? 0:29.45 /usr/sbin/syslogd5 0 34 1 0 4 419 ?? 0:58.69 /usr/libexec/UserEventAgent (System)6 0 37 1 0 4 419 ?? 0:17.00 /System/Library/PrivateFrameworks/Uninstal7l.framework/Resources/uninstalld8 0 38 1 0 4 419 ?? 1:58.00 /usr/libexec/kextd9 0 39 1 0 4 419 ?? 22:29.84 /System/Library/Frameworks/CoreServices.fr10amework/Versions/A/Frameworks/FSEvents.framework/Versions/A/Support/fseventsd11 0 41 1 0 4 419 ?? 0:34.46 /System/Library/PrivateFrameworks/MediaRem12ote.framework/Support/mediaremoted13 55 44 1 0 4 419 ?? 0:03.53 /System/Library/CoreServices/appleeventsd 14--server15 0 45 1 0 4 419 ?? 56:24.11 /usr/sbin/systemstats --daemon16 0 47 1 0 4 419 ?? 1:06.93 /usr/libexec/configd17 0 48 1 0 4 419 ?? 10:55.03 /System/Library/CoreServices/powerd.bundle18/powerd实例三:查看命令历史使用记录并通过 less 分页显示
命令
xxxxxxxxxx11history | less输出
xxxxxxxxxx191Qs-MacBook-Pro:dir1 qiu$ history | less2 201 pwd3 202 ll4 203 cls5 204 ls -R6 205 cp log1.log dir27 206 ls -R8 207 cp -a log1.log dir29 208 cls10 209 ls -R11 210 cp log1.log dir212 211 cp log1.log dir213 212 cp -i log1.log dir214 213 ls15 214 cls16 215 ls -lR17 216 cp -i log1.log dir218 217 ls -lR19 218 pwd实例四:浏览多个文件
命令
xxxxxxxxxx1less log.log log1.log2// 打开文件后3:n //切换到下一个文件4:p //切换到上一个文件输出
xxxxxxxxxx1Qs-MacBook-Pro:dir1 qiu$ less log.log log1.log2log.log342019-0152019-0262019-03782019-0492019-0510log.log (file 1 of 2) (END) - Next: log1.log1112:n13log1.log14152019-01162019-02172019-03182019-04192019-0520~21~22log1.log (file 2 of 2) (END)2324:p25log.log26272019-01282019-02292019-0330312019-04322019-0533~34~35log.log (file 1 of 2) (END) - Next: log1.log36