Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The function and use example of less Command in linux

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Today, the editor shares with you the functions and examples of the less command in linux. I believe many people do not know much about it. In order to let you know more about the less command in linux, I have summarized the following contents and let's move on. I'm sure you'll get something.

Detailed explanation of linux less command

The less tool is a tool for pagination display of files or other output. It should be said that it is a tool for linux orthodox viewing the contents of files. It is extremely powerful.

Less has more search functions, not only to search down, but also to search up. And less does not load the entire file before viewing it.

1. Command format:

Less [parameters] file

2. Command function:

Less is similar to more, but you can browse files at will with less, while more can only move forward, but not backward, and less does not load the entire file before viewing it.

Recommended study (Linux video tutorial)

3. Command parameters:

-b sets the size of the buffer-e when the file display is over, automatically leave-f force the special file to be opened For example, peripheral code, Directories and binaries-g only marks the last keyword searched-I ignore the case of the search-m displays the percentage similar to the more command-N displays the line number of each line-o saves the less output in the specified file-Q does not use warning tone-s displays continuous null behavior one line-S line discards the excess part for too long-x will "tab" The key is displayed as a specified numeric space / string: the ability to search down for "string"? String: the ability to search up for "string" n: repeat the previous search (and / or? About) N: reverse repeat the previous search (and / or? About) b turn back one page d turn back half page h display help interface Q exit less command u scroll forward half page y scroll forward space key scroll one page [pagedown]: flip a page down [pageup]: flip a page up

4. Use an example:

The instance 1:ps views the process information and displays the line number through less paging display

Command:

Aijian.shi@U-aijian-shi:~/ALM$ ps-ef | less-N

Output:

1 UID PID PPID C STIME TTY TIME CMD 2 root 1 00 Aug08? 00:00:00 / sbin/init 3 root 2 00 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 20 Aug08? 00:00:00 [migration/3] 15 root 18 20 Aug08? 00:00:01 [ksoftirqd/3] 16 root 19 20 Aug08? 00:00:00 [watchdog/3] 17 root 20 20 Aug08? 00:00:00 [migration/4] 18 root 22 20 Aug08? 00:00:00 [ksoftirqd/4] 19 root 23 20 Aug08? 00:00:00 [watchdog/4] 20 root 24 20 Aug08? 00:00:00 [migration/5] 21 root 26 20 Aug08? 00:00:00 [ksoftirqd/5] 22 root 27 20 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:

After entering: n, switch to test.log

After entering: P, switch to test2.log

Ps: when you are 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 backwards one screen

Ctrl + D-move half screen forward

Ctrl + U-move half screen backward

two。 One-way navigation

J-move forward one line

K-move backward one line

3. Other navigation

G-move to the last line

G-move to the first line

Q / ZZ-exits the less command

4. Other useful commands

V-use the configured editor to edit the current file

H-displays help documentation for less

& pattern-displays only the lines that match the pattern, not the entire file

5. Tag navigation

When viewing a large file using less, you can mark it anywhere, and you can navigate to a text location marked with a specific tag through the command:

Ma-use a to mark the current position of the text

'a-navigate to mark a

6. Find

Both more and less have the search function. Press / then enter the string you are looking for, then press Enter, press n (next) to continue looking, uppercase N is to look back (above), press Q (quit) or ZZ to leave

On the linux less command functions and use examples to share here, I hope that the above content can have a certain reference value, you can learn to apply. If you like this article, you might as well share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report