
在Linux系统中,命令less是一个浏览文件内容的工具,类似于记事本查看文件一样,如果文件内容过多,less命令的结果只会显示部分文件的内容,它会将文件内内容以分页的形式显示出来,并不会全部显示。此外,命令less支持【up】【down】等按键功能,可以通过上下键来完成向前或向后翻页文件。另外命令 more与less作用类似,关于more的详细内容会在下一篇说道。

语法
less [参数选项] [文件]
【注】命令less也有交互式命令,比如在查看文件内容的同时可以使用vi编辑器来编辑内容

参数说明
-e 当文件全部显示后会自动停止less查看模式
-f 强制打开特殊文件。如:二进制文件
-N 查看内容显示行号
-o <文件名> 将less输出的内容保存起来
-s 将连续的空行输出为1行
-x <数字> 将‘tab’键显示为指定 的数字空
![]()
交互式子命令
![]()
/ 字符串 向下搜索‘字符串’的功能
?字符串 向上搜索‘字符串’的功能
n:重复前一个搜索(与 / ?有关)
N:反向重复前一个搜索(与 / ?有关)
G 移到最后一行
g 移到第一行
h 显示帮助界面
q 退出less命令
u 向前翻半页
d 向后翻半页
b 或【up】向前翻一页
空格键 或 【down】 向后翻一页

案例
不带参数时 全屏显示内容【仍是分页全屏显示】
root@master bin]# less yum # 分页查看yum的内容#!/usr/bin/pythonimport systry:import yumexcept ImportError:print >> sys.stderr, """There was a problem importing one of the Python modulesrequired to run yum. The error leading to this problem was:%sPlease install a package which provides this module, orverify that the module is installed correctly.It's possible that the above module doesn't match thecurrent version of Python, which is:%sIf you cannot solve this problem yourself, please go tothe yum faq at:http://yum.baseurl.org/wiki/Faq""" % (sys.exc_value, sys.version)sys.exit(1)sys.path.insert(0, '/usr/share/yum-cli')try:import yummainyummain.user_main(sys.argv[1:], exit_code=True)yum
-N 参数添加行号
[root@master bin]# less -N yum1 #!/usr/bin/python2 import sys3 try:4 import yum5 except ImportError:6 print >> sys.stderr, """7 There was a problem importing one of the Python modules8 required to run yum. The error leading to this problem was:910 %s1112 Please install a package which provides this module, or13 verify that the module is installed correctly.1415 It's possible that the above module doesn't match the16 current version of Python, which is:17 %s1819 If you cannot solve this problem yourself, please go to20 the yum faq at:21 http://yum.baseurl.org/wiki/Faq2223 """ % (sys.exc_value, sys.version)24 sys.exit(1)2526 sys.path.insert(0, '/usr/share/yum-cli')27 try:28 import yummain29 yummain.user_main(sys.argv[1:], exit_code=True)yum
结合其他命令 将内容分页输出显示
[root@master /]# ls /etc/ | lessadjtimealiasesaliases.dbalternativesanacrontabasound.confaudispauditbash_completion.denvironmentethertypesexportsfavicon.pngfilesystemsfirewalld:
上述命令解释: 使用ls命令查看/etc 目录下有哪些文件并将结果分页显示
---END---
更多内容及资源请关注公众号:数据与编程之美

最后
以上就是细腻玉米最近收集整理的关于每天一条Linux命令(28) less (分页显示内容)的全部内容,更多相关每天一条Linux命令(28)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复