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

What is the use of more and less commands in Linux system

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is to share with you about the use of more and less commands in Linux systems. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

In Linux system, more and less commands are mainly used to view files.

1. More command

The more function is similar to cat, where the cat command displays the contents of the entire file on the screen from top to bottom. More will be a page-by-page display to facilitate users to read page by page, and the most basic instruction is to press the blank key (space) to display to the next page, press the b key to go back to (back) a page to display, and has the function of searching for strings. The more command reads the file back and forth, so the entire file is loaded at startup.

1. Command format:

More [- dlfpcsu] [- num] [+ / pattern] [+ linenum] [file... ]

2. Command function:

The more command is the same as cat's function is to view the contents of the file, but the difference is that more can view the contents of the file by page, but also supports direct jump line and other functions.

3. Command parameters:

+ n starts with line n.

-n defines the screen size as n lines

+ / pattern searches for the string (pattern) before each file is displayed, and then displays it after the first two lines of the string

-c clear the screen from the top and display

-d prompt "Press space to continue,'q' to quit (press Spacebar to continue, press Q key to exit)" to disable the ringing function

-l ignores Ctrl+l (page feed) characters

-p page the file by clearing the window instead of scrolling, similar to the-c option

-s displays consecutive blank lines as one line

-u remove the underline from the contents of the file

4. Common operation commands:

Enter goes down n lines and needs to be defined. The default is 1 line

Ctrl+F scrolls down one screen

The space bar scrolls down one screen

Ctrl+B returns to the previous screen

= output the line number of the current line

: F output file name and line number of the current line

V calls the vi editor

! Command invokes Shell and executes the command

Q exit more

5. Command example:

Example 1: displays the contents of the file starting from line 3

Command:

Aijian.shi@U-aijian-shi:~/ALM$ cat test.log # displays all log contents aijian.shi@U-aijian-shi:~/ALM$ more + 3 test.log # displays the log content output from the third line:

1 aijian.shi@U-aijian-shi:~/ALM$ cat test.log 2 2016-8-1 aijian.shi 3 2016-8-2 yafang.wei 4 2016-8-3 hong.zhan 5 2016-8-4 yuyan.zhang 6 2016-8-5 senlin.zhao 7 2016-8-6 yanbin.liu 8 2016-8-7 hui.liu 9 2016-8-8-8 yanhua.liu 10 2016-8-9 baoixn.cui 11 2016-8-10 ge.song 12 2016-8-11 zhongjun.zhen 13 2016- 8-12 qiu.liaoaijian.shi@U-aijian-shi:~/ALM$ more + 3 test.log2016-8-3 hong.zhan2016-8-4 yuyan.zhang2016-8-5 senlin.zhao2016-8-6 yanbin.liu2016-8-7 hui.liu2016-8-8 yanhua.liu2016-8-9 baoixn.cui2016-8-10 ge.song2016-8-11 zhongjun.zhen2016-8-12 qiu.lia instance 2. Set the content of the log to 4 lines per screen

Command:

Aijian.shi@U-aijian-shi:~/ALM$ more-4 test.log output:

1 aijian.shi@U-aijian-shi:~/ALM$ more-4 test.log 2 2016-8-1 aijian.shi 3 2016-8-2 yafang.wei 4 2016-8-3 hong.zhan 5 2016-8-4 yuyan.zhang 6 7... skipping one line # here use ctrl+F or the space key to scroll 8 2016-8-6 yanbin.liu 9 2016-8-7 hui.liu 10 2016-8-8 yanhua.liu 11 2016-8-9 baoixn .cui 12 13... skipping one line 14 2016-8-11 zhongjun.zhen 15 2016-8-12 qiu.liao instance 3. Find the first line in the file where the "liu" string appears, and display the output from the first two lines there

Command:

Aijian.shi@U-aijian-shi:~/ALM$ more + / liu test.log output:

1 aijian.shi@U-aijian-shi:~/ALM$ more + / liu test.log 2 3... skipping 4 2016-8-4 yuyan.zhang 5 2016-8-5 senlin.zhao 6 2016-8-6 yanbin.liu 7 2016-8-7 hui.liu 8 2016-8-8 yanhua.liu 9 2016-8-9 baoixn.cui 10 2016-8-10 ge.song 11 2016-8-11 zhongjun.zhen 12 2016-8-12 qiu.liao instance 4. When there are too many files in a directory, it can be paged and displayed with more. This has to be combined with plumbing |

Command:

Aijian.shi@U-aijian-shi:~/ALM$ cat test.log | more-5 # "|" indicates the pipe, and the function is to use the output of the previous command as the input and output of the following command:

1 aijian.shi@U-aijian-shi:~/ALM$ cat test.log | more- 5 2 2016-8-1 aijian.shi 3 2016-8-2 yafang.wei 4 2016-8-3 hong.zhan 5 2016-8-4 yuyan.zhang 6 2016-8-5 senlin.zhao 7 8.. skipping one line 9 2016-8-7 hui.liu 10 2016-8-8 yanhua.liu 11 2016-8-9 baoixn.cui 12 2016-8-10 ge.song 13 2016-8-11 zhongjun.zhen 14-more-- II, less instruction

The less tool is also 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, which is extremely powerful. The usage of less is more flexible than that of more. In more, we have no way to turn to the front, we can only look back, but if we use less, we can use the function of [pageup] [pagedown] and other keys to go back and forth to browse the file, which is easier to view the contents of a file! In addition, less can have more search functions, not only to search down, but also to search up.

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.

3. Command parameters:

-b sets the size of the buffer

-e automatically leave when the file is displayed

-f force the opening of special files, such as peripheral codes, directories, and binaries

-g marks only 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 Save the less output in the specified file

-Q does not use warning tones

-s displays a row of continuous empty behavior

-S line will be discarded if it takes too long

-x displays the "tab" key as a specified number space

/ string: the ability to search down for "string"

? Strings: the ability to search up for "strings"

N: repeat the previous search (and / or? Related)

N: reverse repeat the previous search (and / or? Related)

B turn back one page

D turn back half a page

H displays the help interface

Q exits the less command

U scroll forward half a page

Y scroll forward one line

The spacebar scrolls one line

Press enter to scroll one page

[pagedown]: turn a page down

[pageup]: turn 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 1 UID PID PPID C STIME TTY TIME CMD 2 2 root 1 00 Aug08? 00:00:00 / sbin/init 3 3 root 2 00 Aug08? 00:00:00 [kthreadd] 4 4 root 3 2 0 Aug08? 00:00:02 [ksoftirqd/0] 5 5 root 6 2 0 Aug08? 00:00:00 [migration/0] 6 6 root 7 2 0 Aug08? 00:00:00 [watchdog/0] 7 7 root 8 2 0 Aug08? 00:00:00 [migration/1] 8 8 root 9 2 0 Aug08? 00:00:00 [kworker/1:0 ] 9 9 root 10 2 0 Aug08? 00:00:01 [ksoftirqd/1] 10 10 root 11 2 0 Aug08? 00:00:00 [watchdog/1] 11 11 root 12 2 0 Aug08? 00:00:00 [migration/2] 12 12 root 14 2 0 Aug08? 00:00:01 [ksoftirqd/2] 13 13 root 15 2 0 Aug08? 00:00:00 [watchdog/2] 14 14 root 16 2 0 Aug08? 00:00:00 [migration/3] 15 15 root 18 2 0 Aug08? 00:00:01 [ksoftirqd/3] 16 16 root 19 2 0 Aug08? 00:00:00 [watchdog/3] 17 17 root 20 20 Aug08? 00:00:00 [migration/4] 18 18 root 22 20 Aug08? 00:00:00 [ksoftirqd/4] 19 19 root 23 20 Aug08? 00:00:00 [watchdog/4] 20 20 root 24 20 Aug08? 00:00:00 [migration/5] 21 21 root 26 20 Aug08? 00:00:00 [ksoftirqd/5] 22 22 root 27 20 Aug08? 00:00:00 [watchdog/5] 23 23 root 28 20 Aug08? 00:00:00 [migration/6] 24: instance 2. Browse multiple files

Command:

Aijian.shi@U-aijian-shi:~/ALM$ less test2.log test.log output:

11 ifconfig 2 2 ping www.baidu.com 3 3 ifconfig 4 4 / / 10.128.161.108/share 5 5 10.128.161.108/share 6 6 ssh 7 7 keygen 8 8 trsa 9 9 ssh 10 10 .ssh / 11 12 13 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 file25. 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

Thank you for reading! This is the end of this article on "what is the use of more and less commands in Linux systems?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out 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

Development

Wechat

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

12
Report