Home > Operation and Maintenance > Linux Operation and Maintenance > Detailed explanation of linux less command

Detailed explanation of linux less command

angryTom
Release: 2020-02-27 15:50:43
Original
5440 people have browsed it

Detailed explanation of linux less command

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 [参数]  文件
Copy after login

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]:   向上翻动一页
Copy after login

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
Copy after login

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]
:
Copy after login

Example 2. Browse multiple files

Command:

aijian.shi@U-aijian-shi:~/ALM$ less test2.log test.log
Copy after login

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
Copy after login

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
Copy after login

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 of

programming 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!

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