In Linux, less means "turn the page to view". It is a command to view the contents of a file. The syntax is "less [option] file name". The less command is used to display the contents of a file or command output. It only displays one page at a time, but allows the user to navigate forward and backward in the file; when using the less command to browse a file, you can both look backward and forward. Look through.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
In Linux, less means "turn the page to view" and is a command to view the contents of a file. The
less command is used to display the contents of a file or command output. It only displays one page at a time but allows the user to navigate forward and backward in the file.
The role of the less command is very similar to that of more. They are both used to browse the contents of text files. The difference is that when using the more command to browse the content of the file, you can only continue to browse backwards, while using the less command When browsing, you can browse backward or forward.
The less command is mainly used to open large files. less does not read the entire file, which results in faster loading times compared to text editors like vim or nano.
Not only that, in order to facilitate users to browse text content, the less command also provides the following functions:
Use the cursor keys to move forward and backward in the text file (left back )Scroll;
Use line numbers or percentages as bookmarks to browse files;
Provides more friendly retrieval, highlighting and other operations;
Compatible with keyboard operations of commonly used word processing programs (such as Vim, Emacs);
The less command will not exit when reading to the end of the file ;
The information prompts at the bottom of the screen are easier to control and use, and provide more information.
#The basic format of the less command is as follows:
# less [选项] 文件名
The options available for this command and their respective meanings are shown in Table 1.
Options | Option meaning |
---|---|
-N | Display the line number of each line. |
-S | If the line is too long, the excess part will be discarded. |
-e | When the file display ends, it will automatically leave. |
-g | Only the last searched key is marked. |
-Q | No warning tones are used. |
-i | Ignore case when searching. |
-m | Display the percentage similar to the more command. |
-f | Force opening of special files such as peripheral device codes, directories, and binaries. |
-s | Display consecutive empty lines in a row. |
-b | Set the buffer size. |
-o | Save the output of less to the specified file. |
-x | Display the [Tab] key as the specified number space. |
在使用 less 命令查看文件内容的过程中,和 more 命令一样,也会进入交互界面,因此需要读者掌握一些常用的交互指令,如表 2 所示。
交互指令 | 功能 |
---|---|
/字符串 | 向下搜索“字符串”的功能。 |
?字符串 | 向上搜索“字符串”的功能。 |
n | 重复*前一个搜索(与 / 成 ? 有关)。 |
N | 反向重复前一个搜索(与 / 或 ? 有关)。 |
b | 向上移动一页。 |
d | 向下移动半页。 |
h 或 H | 显示帮助界面。 |
q 或 Q | 退出 less 命令。 |
y | 向上移动一行。 |
空格键 | 向下移动一页。 |
回车键 | 向下移动一行。 |
【PgDn】键 | 向下移动一页。 |
【PgUp】键 | 向上移动一页。 |
Ctrl+f | 向下移动一页。 |
Ctrl+b | 向上移动一页。 |
Ctrl+d | 向下移动一页。 |
Ctrl+u | 向上移动半页。 |
j | 向下移动一行。 |
k | 向上移动一行。 |
G | 移动至最后一行。 |
g | 移动到第一行。 |
ZZ | 退出 less 命令。 |
v | 使用配置的编辑器编辑当前文件。 |
[ | 移动到本文档的上一个节点。 |
] | 移动到本文档的下一个节点。 |
p | 移动到同级的上一个节点。 |
u | 向上移动半页。 |
示例:
要查看 /usr/share/common-licenses/GPL-3的文件内容,您要输入:
less /usr/share/common-licenses/GPL-3
您还可以使用管道将命令的输出重定向到 less。例如,要逐页查看命令 ps 的输出,请键入:
ps aux | less
浏览文件内容
打开的文件内容太大而无法放入一个页面时,您将看到一个冒号 (:) 。
要转到下一页,请 f 按键或 空格键 。如果要向下移动特定数量的行,请键入数字,后跟空格或 f 键。
您可以按 向下键 或 回车 向后滚动一行,通过 向上键 向前滚动一行。
要返回上一页,请 b 按键。通过键入数字后跟 b 键,向上移动特定行数。
如果要搜索模式,请键入 / ,然后键入要搜索的模式。一旦你按下回车键, less 就会向前搜索匹配项。向后搜索使用 ? 后跟搜索模式。
到达文件末尾时,字符串 (END) 显示在屏幕底部。
要退出 less 并返回命令行,请按 q 。
相关推荐:《Linux视频教程》
The above is the detailed content of What does less mean in linux?. For more information, please follow other related articles on the PHP Chinese website!