What does less mean in linux?

青灯夜游
Release: 2022-06-17 15:12:48
Original
8504 people have browsed it

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.

What does less mean in linux?

#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 [选项] 文件名
Copy after login

The options available for this command and their respective meanings are shown in Table 1.

Table 1 less command options and meaning
          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 所示。

表 2 less 交互指令及功能
交互指令 功能
/字符串 向下搜索“字符串”的功能。
?字符串 向上搜索“字符串”的功能。
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
Copy after login

What does less mean in linux?

您还可以使用管道将命令的输出重定向到 less。例如,要逐页查看命令 ps 的输出,请键入:

ps aux | less
Copy after login

浏览文件内容

打开的文件内容太大而无法放入一个页面时,您将看到一个冒号 (:) 。

要转到下一页,请 f 按键或 空格键 。如果要向下移动特定数量的行,请键入数字,后跟空格或 f 键。

您可以按 向下键 或 回车 向后滚动一行,通过 向上键 向前滚动一行。

要返回上一页,请 b 按键。通过键入数字后跟 b 键,向上移动特定行数。

如果要搜索模式,请键入 / ,然后键入要搜索的模式。一旦你按下回车键, less 就会向前搜索匹配项。向后搜索使用 ? 后跟搜索模式。

到达文件末尾时,字符串 (END) 显示在屏幕底部。

要退出 less 并返回命令行,请按 q 。

What does less mean in linux?

相关推荐:《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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template