If you’re a newcomer to Linux, you might be confused between more, less, and most, the three command-line tools. In this article, I will compare these three command line tools and show some examples of their respective use in Linux. Overall, there are similarities and differences between these command-line tools, and they come with them on most Linux distributions.
Let’s first look at the more command.
More is an old-fashioned, basic terminal paging reader that can be used to open specified files and read them interactively. If the content of the file is too long to be displayed in a full screen, the content of the file will be displayed page by page. You can scroll through the contents of the file by using the Enter key or the Space key, but there is a limitation that you can only scroll in one direction. That is to say, you can only turn down the page in order, but not look back.
Some Linux users pointed out to me that you can page up in more. However, the original version of more does allow only downward page-turning, and later newer versions allow a limited number of upward page-turning, which can be done by pressing the B key during browsing. The only limitation is that more cannot be used with pipes (e.g., LS | more). (LCTT Note: The original author here is suspected to be wrong. Translators can use more with pipes, perhaps related to different versions of more.)
Press Q to exit more.
Open the ostechnix.txt file for interactive reading, you can execute the following commands:
$ more ostechnix.txt
In the reading process, if you need to find a string, just enter the slash (/) as follows, and then enter what you need to find:
Press n to jump to the next matching string.
If you need to start reading on line 10 of the document, you only need to execute:
$ more +10 file
You can start displaying the contents of the file from line 10.
If you need more to prompt you to press the space bar to turn the page, add the – D parameter:
$ more -d ostechnix.txt
As shown in the figure above, more will prompt you to press the space bar to turn the page.
If you need to view all the options and the corresponding keys, you can press the H key.
For more details, you can refer to the manual:
$ man more
The less command is also used to open a specified file and read it interactively. It also supports page turning and search. If the content of the file is too long, the output will also be paginated, so you can also turn the page to read. Better than the more command, less supports page-turning up and page-turning down, that is, it can be read arbitrarily throughout the file.
Less has more advantages than more commands in terms of functionality. Here are a few of them:
- Support up and down page turning
- Support for up and down search
- You can jump to the end of the file and start reading immediately from the beginning of the file.
- Open the specified file in the editor
Open the file:
$ less ostechnix.txt
Press the space key or the return key to turn the page down, and press the B key to turn the page up.
If you need to search downward, enter the slash (/) followed by the search:
Press n to jump to the next matching string. If you need to jump to the last matching string, press N.
If you need to search up, enter a question mark (?) and then enter what you want to search for:
Similarly, press the N key or the N key to jump to the next or last matching string.
Just press the V key, the file you are reading will be opened in the default editor, and then you can edit the file in various ways.
Press the H key to see the options of less tool and the corresponding keys.
You can quit reading by pressing the Q key.
For more details on less, you can refer to the manual:
$ man less
Most is also a terminal reading tool, and has more functions than more and less. Most supports opening multiple files at the same time. You can switch between open files, edit currently open files, quickly jump to a line in the file, split-screen reading, lock or scroll multiple screens at the same time, and so on. By default, for longer rows, most does not truncate them into multi-line displays, but provides the ability to scroll left and right to display in the same line.
Open the file:
$ most ostechnix1.txt
Press the e key to edit the current file.
If you need to search downward, enter the search after the slash (/) or S or f, and press n to jump to the next matching string.
If you need to search up, enter what you need to search after the question mark (?), and also jump to the next matching string by pressing the n key.
Open multiple files at the same time:
$ most ostechnix1.txt ostechnix2.txt ostechnix3.txt
In the state of opening more than one file, you can enter: n to switch to the next file, use the_or_key to select the file you need to switch to, press Enter key to view the corresponding file.
To open a file and jump to the location where a string first appears (for example, linux), you can execute the following commands:
$ most file +/linux
Press h to see help.
Key Operations List
- Space or D – Scroll down a screen
- DELETE key or U key – scroll up a screen
- _Key – Move one line down
- _Key – Move up one line
- T key – Move to the beginning of the file
- Key B – Move to the end of the file
- > Key or TAB key – scroll to the right
- Key – Scroll the screen to the left
- Key – Move a column to the right
- _Key – Move a column to the left
- J key or G key — Move to a line, for example, 10J can move to line 10
- % Key – Move to a percentage of the file length
- Ctrl-X 2, Ctrl-W 2-split screen
- Ctrl-X 1, Ctrl-W 1 — Show only one window
- O key, Ctrl-X O — switch to another window
- Ctrl-X 0 – Delete window
- S key or F key or / key – search down
- Key – Search up
- N key – jump to the next matching string
- Q key – exit most, and all open files will be closed
- N,: n — Exit the current file and view the next file (select the next file by using the_key and_key)
For more details on most, you can refer to the manual:
$ man most
more – Traditional and basic paging reading tools only support down-page and limited number of up-page.
more It has rich functions, supports page-turning down and page-turning up, and also supports text search. When large files are opened, they start faster than text editors like VI.
most – On the basis of the above two tools, a lot of functions such as opening multiple files, locking or scrolling multiple screens at the same time, dividing screens and so on are added.
The above is my introduction, I hope you can have a certain understanding of these three tools through my article. If you want to know more about these tools beyond this article, please refer to their man manual.