English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux less 命令

Linux Command大全

less 与 more 类似,less 可以随意浏览文件,支持翻页和搜索,支持向上翻页和向下翻页。

语法

less [参数] 文件 

参数说明:

  • -b 设置缓冲区的大小
  • -e 当文件显示结束后,自动离开
  • -f 强迫打开特殊文件,例如外围设备代号、目录和二进制文件
  • -g 只标志最后搜索的关键词
  • -i 忽略搜索时的大小写
  • -m 显示类似more命令的百分比
  • -N 显示每行的行号
  • -o 将less 输出的内容在指定文件中保存起来
  • -Q 不使用警告音
  • -s 显示连续空行为一行
  • -S 行过长时间将超出部分舍弃
  • -x 将"tab"键显示为规定的数字空格
  • /字符串:向下搜索"字符串"的功能
  • ?字符串:向上搜索"字符串"的功能
  • n:重复前一个搜索(与 / 或 ? 有关)
  • N:反向重复前一个搜索(与 / 或 ? 有关)
  • b 向上翻一页
  • d 向后翻半页
  • h 显示帮助界面
  • Q 退出less 命令
  • u 向前滚动半页
  • y 向前滚动一行
  • 空格键 滚动一页
  • 回车键 滚动一行
  • [pagedown]: 向下翻动一页
  • [pageup]: 向上翻动一页

在线示例

1、查看文件

less log2013.log

2、ps查看进程信息并通过less分页显示

ps -ef |less

3View command history usage records and display them with less pagination

[root@localhost test]# history | less
22  scp -r tomcat6.0.32 [email protected]:/opt/soft
23  cd ..
24  scp -r web [email protected]:/opt/
25  cd soft
26  ls
……Omitted……

4Browsing Multiple Files

less log2013.log log2014.log

Description:
Enter :n to switch to log2014.log
Enter :p to switch to log2013.log

Additional Remarks

1Full Screen Navigation

  • ctrl + F - Move Up One Screen
  • ctrl + B - Move Down One Screen
  • ctrl + D - Move Up Half Screen
  • ctrl + U - Move Down Half Screen

2Single Line Navigation

  • j - Move Up One Line
  • k - Move Down One Line

3Other Navigation

  • G - Move to the Last Line
  • g - Move to the First Line
  • q / ZZ - Exit less Command

4Other Useful Commands

  • v - Edit the current file with the configured editor
  • h - Display the help document of less
  • &pattern; - Only display lines that match the pattern, not the entire file

5Mark Navigation

When viewing large files with less, you can mark any position and navigate to the text at the marked position with a command:

  • ma - Current Position of Text with a Tag
  • 'a - Navigate to Mark a

Linux Command大全