search
HomeOperation and MaintenanceLinux Operation and MaintenanceWhat are the differences between less and more in linux?

Difference: 1. Less can press the up and down arrow keys to display the upper and lower content, while more cannot control the display through the up and down arrow keys; 2. Less does not have to read the entire file, and the loading speed is faster than more; 3. Less After exiting, the shell will not leave the content just displayed, but after more exits, it will leave the content just displayed on the shell.

What are the differences between less and more in linux?

#The operating environment of this tutorial: CentOS 6 system, Dell G3 computer.

Linux more and less commands

more command

more command can display text files in pages The user can read the content of the file page by page. The basic format of this command is as follows:

[root@localhost ~]# more [选项] 文件名

more The command is relatively simple and generally does not require any options. For the options listed in Table 1, readers only need to read Just get to know it.

Table 1 more command options and meaning
          Options           Meaning
          -f             When calculating the number of lines, use the actual number of lines, not the number of lines after automatic line wrapping.
          -p             Instead of scrolling through each page, the screen is cleared first and then the content is displayed.
          -c             Similar to the -p option, except that the content is displayed first and other old data is cleared.
-s             When two or more consecutive blank lines are encountered, they are replaced with one blank line.
          -u             Do not display lower quotes (depending on the terminal specified by the environment variable TERM).
          n           Display the file contents starting from line n, where n represents a number.
          -n             The number of rows displayed at one time, n represents a number.

less 命令

less 命令的作用和 more 十分类似,都用来浏览文本文件中的内容,不同之处在于,使用 more 命令浏览文件内容时,只能不断向后翻看,而使用 less 命令浏览,既可以向后翻看,也可以向前翻看。

不仅如此,为了方面用户浏览文本内容,less 命令还提供了以下几个功能:

  • 使用光标键可以在文本文件中前后(左后)滚屏;

  • 用行号或百分比作为书签浏览文件;

  • 提供更加友好的检索、高亮显示等操作;

  • 兼容常用的字处理程序(如 Vim、Emacs)的键盘操作;

  • 阅读到文件结束时,less 命令不会退出;

  • 屏幕底部的信息提示更容易控制使用,而且提供了更多的信息。

less 命令的基本格式如下:

[root@localhost ~]# less [选项] 文件名

此命令可用的选项以及各自的含义如表 1 所示。

        表 1 less 命令选项及含义
                选项                 选项含义
                -N                 显示每行的行号。
                -S                 行过长时将超出部分舍弃。
                -e                 当文件显示结束后,自动离开。
                -g                 只标志最后搜索到的关键同。
                -Q                 不使用警告音。
                -i                 忽略搜索时的大小写。
                -m                 显示类似 more 命令的百分比。
                -f                 强迫打开特殊文件,比如外围设备代号、目录和二进制文件。
                -s                 显示连续空行为一行。
                -b                 设置缓冲区的大小。
                -o                 将 less 输出的内容保存到指定文件中。
                -x                 将【Tab】键显示为规定的数字空格。

more 和 less的区别:

1、 less可以按键盘上下方向键显示上下内容,而more不能通过上下方向键控制显示

2、less不必读整个文件,加载速度会比more更快

3、less退出后shell不会留下刚显示的内容,而more退出后会在shell上留下刚显示的内容

4、阅读到文件结束时,less不会退出,而more会

5、less可用行号或百分比作为书签浏览文件,而more不行

6、相比more,less提供更加友好的检索、高亮显示等操作

扩展知识:Linux less命令常用实例

查看文件内容

语法

less file

案例

我们使用 less 命令,查看 /etc/vimrc 的文件内容,具体命令如下:

less /etc/vimrc

运行后,终端输出如下:

What are the differences between less and more in linux?

我们看到,我们使用了 less 命令,查看了文件内容,现在,我们就可以使用上面的交互命令,对该文本进行操作了,比如,我们按下回车键,可以向下移动一行,运行后,终端输出如下:

What are the differences between less and more in linux?

同时,我们还可以使用空格键,向下移动一页,运行后,终端输出如下:

What are the differences between less and more in linux?

即,我们使用了 less 命令,分屏查看了文件内容。

查看文件内容并显示行号

语法

less -N file

案例

我们使用 less 命令,查看 /etc/vimrc 的文件内容,并显示行号,具体命令如下:

less -N /etc/vimrc

运行后,终端输出如下:

What are the differences between less and more in linux?

这次,我们使用了 less 命令,查看了文件内容,并显示了行号。

less命令字符串搜索

语法

/str

案例

我们使用 less 命令,查看 /etc/vimrc 的文件内容,具体命令如下:

less /etc/vimrc

运行后,终端输出如下:

What are the differences between less and more in linux?

现在,我们可以使用 /str 的形式,开始搜索字符串,如下图所示:

What are the differences between less and more in linux?

现在,我们按下回车,开始搜索,此时如下图所示:

What are the differences between less and more in linux?

我们看到,所有匹配的字符串都被高亮了,即,我们使用了 /str 的形式搜索了我们指定的字符串,同时,我们还可以使用 n 匹配下一个,使用 N 匹配上一个。

相关推荐:《Linux视频教程

The above is the detailed content of What are the differences between less and more in linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
Linux Maintenance Mode: Understanding the PurposeLinux Maintenance Mode: Understanding the PurposeApr 28, 2025 am 12:01 AM

Maintenance mode is used for system maintenance and repair, allowing administrators to work in a simplified environment. 1. System Repair: Repair corrupt file system and boot loader. 2. Password reset: reset the root user password. 3. Package management: Install, update or delete software packages. By modifying the GRUB configuration or entering maintenance mode with specific keys, you can safely exit after performing maintenance tasks.

Linux Operations: Networking and Network ConfigurationLinux Operations: Networking and Network ConfigurationApr 27, 2025 am 12:09 AM

Linux network configuration can be completed through the following steps: 1. Configure the network interface, use the ip command to temporarily set or edit the configuration file persistence settings. 2. Set up a static IP, suitable for devices that require a fixed IP. 3. Manage the firewall and use the iptables or firewalld tools to control network traffic.

Maintenance Mode in Linux: A System Administrator's GuideMaintenance Mode in Linux: A System Administrator's GuideApr 26, 2025 am 12:20 AM

Maintenance mode plays a key role in Linux system management, helping to repair, upgrade and configuration changes. 1. Enter maintenance mode. You can select it through the GRUB menu or use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can perform file system repair and system update operations. 3. Advanced usage includes tasks such as resetting the root password. 4. Common errors such as not being able to enter maintenance mode or mount the file system, can be fixed by checking the GRUB configuration and using the fsck command.

Maintenance Mode in Linux: When and Why to Use ItMaintenance Mode in Linux: When and Why to Use ItApr 25, 2025 am 12:15 AM

The timing and reasons for using Linux maintenance mode: 1) When the system starts up, 2) When performing major system updates or upgrades, 3) When performing file system maintenance. Maintenance mode provides a safe and controlled environment, ensuring operational safety and efficiency, reducing impact on users, and enhancing system security.

Linux: Essential Commands and OperationsLinux: Essential Commands and OperationsApr 24, 2025 am 12:20 AM

Indispensable commands in Linux include: 1.ls: list directory contents; 2.cd: change working directory; 3.mkdir: create a new directory; 4.rm: delete file or directory; 5.cp: copy file or directory; 6.mv: move or rename file or directory. These commands help users manage files and systems efficiently by interacting with the kernel.

Linux Operations: Managing Files, Directories, and PermissionsLinux Operations: Managing Files, Directories, and PermissionsApr 23, 2025 am 12:19 AM

In Linux, file and directory management uses ls, cd, mkdir, rm, cp, mv commands, and permission management uses chmod, chown, and chgrp commands. 1. File and directory management commands such as ls-l list detailed information, mkdir-p recursively create directories. 2. Permission management commands such as chmod755file set file permissions, chownuserfile changes file owner, and chgrpgroupfile changes file group. These commands are based on file system structure and user and group systems, and operate and control through system calls and metadata.

What is Maintenance Mode in Linux? ExplainedWhat is Maintenance Mode in Linux? ExplainedApr 22, 2025 am 12:06 AM

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo

Linux: A Deep Dive into Its Fundamental PartsLinux: A Deep Dive into Its Fundamental PartsApr 21, 2025 am 12:03 AM

The core components of Linux include kernel, file system, shell, user and kernel space, device drivers, and performance optimization and best practices. 1) The kernel is the core of the system, managing hardware, memory and processes. 2) The file system organizes data and supports multiple types such as ext4, Btrfs and XFS. 3) Shell is the command center for users to interact with the system and supports scripting. 4) Separate user space from kernel space to ensure system stability. 5) The device driver connects the hardware to the operating system. 6) Performance optimization includes tuning system configuration and following best practices.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool