


Detailed explanation of linux less command
The less tool is a tool for paging display of files or other output. It should be said that it is the orthodox Linux viewing file content. tool, extremely powerful.
less has more search functions, you can not only search down, but also search up. And less doesn't load the entire file before viewing it.
1. Command format:
less [参数] 文件
2. Command function:
less is similar to more, but you can use less to browse files at will, while more can only move forward, but not backward, and less will not load the entire file before viewing.
Recommended learning (Linux video tutorial)
3. Command parameters:
-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]: 向上翻动一页
4. Usage example:
Example 1: ps to view process information and display line numbers through less paging
Command:
aijian.shi@U-aijian-shi:~/ALM$ ps -ef|less -N
Output:
1 UID PID PPID C STIME TTY TIME CMD 2 root 1 0 0 Aug08 ? 00:00:00 /sbin/init 3 root 2 0 0 Aug08 ? 00:00:00 [kthreadd] 4 root 3 2 0 Aug08 ? 00:00:02 [ksoftirqd/0] 5 root 6 2 0 Aug08 ? 00:00:00 [migration/0] 6 root 7 2 0 Aug08 ? 00:00:00 [watchdog/0] 7 root 8 2 0 Aug08 ? 00:00:00 [migration/1] 8 root 9 2 0 Aug08 ? 00:00:00 [kworker/1:0] 9 root 10 2 0 Aug08 ? 00:00:01 [ksoftirqd/1] 10 root 11 2 0 Aug08 ? 00:00:00 [watchdog/1] 11 root 12 2 0 Aug08 ? 00:00:00 [migration/2] 12 root 14 2 0 Aug08 ? 00:00:01 [ksoftirqd/2] 13 root 15 2 0 Aug08 ? 00:00:00 [watchdog/2] 14 root 16 2 0 Aug08 ? 00:00:00 [migration/3] 15 root 18 2 0 Aug08 ? 00:00:01 [ksoftirqd/3] 16 root 19 2 0 Aug08 ? 00:00:00 [watchdog/3] 17 root 20 2 0 Aug08 ? 00:00:00 [migration/4] 18 root 22 2 0 Aug08 ? 00:00:00 [ksoftirqd/4] 19 root 23 2 0 Aug08 ? 00:00:00 [watchdog/4] 20 root 24 2 0 Aug08 ? 00:00:00 [migration/5] 21 root 26 2 0 Aug08 ? 00:00:00 [ksoftirqd/5] 22 root 27 2 0 Aug08 ? 00:00:00 [watchdog/5] 23 root 28 2 0 Aug08 ? 00:00:00 [migration/6] :
Example 2. Browse multiple files
Command:
aijian.shi@U-aijian-shi:~/ALM$ less test2.log test.log
Output:
1 ifconfig 2 ping www.baidu.com 3 ifconfig 4 //10.128.161.108/share 5 10.128.161.108/share 6 ssh 7 keygen 8 trsa 9 ssh 10 .ssh/ test2.log (file 1 of 2) (END) - Next: test.log
Description:
Input: n, switch After entering :p into test.log
, switch to test2.log
ps: When browsing a file, you can also use the :e command to open another file.
Command:
less file1 :e file2
5. Additional remarks
1. Full screen navigation
ctrl F - Move forward one screen
ctrl B - Move backward One screen
ctrl D - Move half screen forward
ctrl U - Move half screen backward
2. Single line navigation
j - Move forward one line
k - Move one line backward
3. Other navigation
G - Move to the last line
g - Move to the first line
q / ZZ - Exit less command
##4. Other useful commands
v - Edit the current file using the configured editor h - Display the help documentation for less &pattern - Show only matches Pattern lines, rather than the entire file
5. Mark navigation
When using less to view large files, you can mark any position, you can Navigate to the position of text marked with a specific mark through the command:ma - Mark the current position of the text with a 'a - Navigate to the mark a
6. Search
more and less all have search functions. Press / and then enter the string you are looking for, then press Enter. Press n(next) to continue searching. , the capital N means go back (up), press q (quit) or ZZ to leave PHP Chinese website, a large number ofprogramming learning courses, welcome to learn!
The above is the detailed content of Detailed explanation of linux less command. For more information, please follow other related articles on the PHP Chinese website!

Linux is a Unix-based multi-user, multi-tasking operating system that emphasizes simplicity, modularity and openness. Its core functions include: file system: organized in a tree structure, supports multiple file systems such as ext4, XFS, Btrfs, and use df-T to view file system types. Process management: View the process through the ps command, manage the process using PID, involving priority settings and signal processing. Network configuration: Flexible setting of IP addresses and managing network services, and use sudoipaddradd to configure IP. These features are applied in real-life operations through basic commands and advanced script automation, improving efficiency and reducing errors.

The methods to enter Linux maintenance mode include: 1. Edit the GRUB configuration file, add "single" or "1" parameters and update the GRUB configuration; 2. Edit the startup parameters in the GRUB menu, add "single" or "1". Exit maintenance mode only requires restarting the system. With these steps, you can quickly enter maintenance mode when needed and exit safely, ensuring system stability and security.

The core components of Linux include kernel, shell, file system, process management and memory management. 1) Kernel management system resources, 2) shell provides user interaction interface, 3) file system supports multiple formats, 4) Process management is implemented through system calls such as fork, and 5) memory management uses virtual memory technology.

The core components of the Linux system include the kernel, file system, and user space. 1. The kernel manages hardware resources and provides basic services. 2. The file system is responsible for data storage and organization. 3. Run user programs and services in the user space.

Maintenance mode is a special operating level entered in Linux systems through single-user mode or rescue mode, and is used for system maintenance and repair. 1. Enter maintenance mode and use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can check and repair the file system and use the command "fsck/dev/sda1". 3. Advanced usage includes resetting the root user password, mounting the file system in read and write mode and editing the password file.

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 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 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.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
