If you're used to working on a Linux system, you'll find that there are a lot of text files in the Linux world. Configuration files and log files are usually in text format. These files usually have very long content and cannot be displayed in a single screen. So when we're working with this kind of file, we need pagination. Then we can use the more command.
What's more?
More is a command for paging through large text files, which are built into each Linux distribution by default.
How to use more
Using the more command, you only need to type:
$ more file_name
For example, we want to check the log file syslog in the/var/log directory and just type:
$ more/var/log/syslog
More command
Then we can see a hint in the lower left corner of the screen telling us that the current zoom is 0%. It looks like this file is quite large, so the first page is 0% of all pages. Use the SPACEBAR to turn the page down, and then you can see the percentage of the hint increase.
Scroll page
Limit the number of rows displayed per page
When you execute the more command, it takes up all the space in your terminal window for display. But you can limit the number of rows displayed per page by parameter-number.
For example, if you want to limit the display of 12 lines per page, you can use the following command:
$ more-12/var/log/syslog
Limit display of 12 rows per page
Limit display of 12 rows per page
Now, you will see that only 12 lines are displayed on each page, and when the SPACEBAR is pressed, the next 12 lines are displayed.
Display User Message
We know that the more command prompts the percentage of the current content in the lower-left corner of the display area. For the person who uses the more command for the first time, he or she may want to know how to page down. To avoid this, we can add the-D argument at execution time, which will display an extra line of user Information "[Press SPACEBAR to continue, ' Q ' launches.]"
More with-d option
More with-d option
If the user presses a key other than ' space ' or ' Q ', more will display a line of help information "[Press ' H ' key to view the hint.] ]”
More displaying Help message
More displaying Help message
If you press the H key, a Help message is displayed:
Display Help
Display Help
An interesting instruction is the B button, and the B button allows you to return to the previous page. In other words, the B button allows you to page forward.
You can go through the top left corner ... The first 1 pages of information to confirm that the previous page is currently displayed.
Turn the page forward in the more
No scrolling
The parameter-c,more command does not scroll the page, but instead directly clears the previous content and replaces it with the contents of the next page. WITH-C option, more would not scroll the page. It'll clear the previous page and put the next page or lines there.
$ more-10-c Lynis.log
Suppress scroll
If you press the SPACEBAR, the next page will still have the same size.
Suppress scroll
Ignore extra blank lines
Use parameter-S to ignore extra blank lines, here's an example:
Multiple blank lines of files
When we add the parameter-s:
$ more-s Doc_30.txt
Extra blank lines are ignored
Find string
If your log file is very large, it is not so easy to find the string you want. The more command's lookup function can help you through the parameters +/string can be used to search for strings, the found keyword will be displayed in the first line. For example, we want to search for "dhclient" in the/var/logs/syslog file, the format of the more command:
$ more +/dhclient/var/log/syslog
Find string
Then, if you want to continue searching the next one in the file, just press the/button and follow the keyword dhclient.
Show starting from specified line
You can also specify the rows to begin with by using the parameter + number, for example, we have a 15-line file:
Multi-line file
Multi-line file
Then we want to show the contents of the file from line 5th, and the command looks like this:
$ more +5 Doc_30.txt
Show starting from specified line
Can I display a binary file?
The answer is no. The more command prompts for such information, such as:
Display binary files
Conclusion
More is a basic tool for viewing text files, and it cannot be used to display binary files. In general, we can get more information on how to use it by ordering man or more--help.