More commands for displaying long text files page by page in CentOS
If you are used to working on Linux, you will surely find a large number of text files in the Linux World. Configuration files and log files are generally in text format. These files usually have a long content and cannot be displayed on a single screen. Therefore, when processing such files, we need to display them by page. In this case, we can useMore command.
What is more?More is a command used to display large text files by page. It is built in various Linux releases by default.
How to use moreTo use the more command, just type:
$ more file_name
For example, to check the syslog file in the/var/log directory, you only need to enter:
$ more /var/log/syslog
Then we can see thatThere is a prompt in the lower-left corner of the screen, telling us that the current display ratio is 0%. It seems that this file is quite large, so the first page is 0% of the total number of pages. You can use the space key to flip down the page and then you can see that the percentage of the prompt increases.
Limit the number of lines displayed per pageWhen executing the more command, it will occupy all the space in your terminal window for display. However, you can use parameters-Number to limit the number of lines displayed per page.
For example, you wantThe limit is 12 lines. You can run the following command:
$ more -12 /var/log/syslog
Now, you can see that only 12 rows are displayed on each page. After you press the Space key, the next 12 rows are displayed on the page.
Display user messageAs we know, the more command prompts the percentage of the current content in the lower left corner of the display area. For the first time using the more command, he or she may want to know how to flip the page. To avoid this situation, we can add-D parameter, this will display an additional line of user information "[Press the Space key to continue. 'q' is available.]"
If you pressFor buttons other than 'space' or 'q', more displays a line of help information."[Press 'H' to view the prompt.]"
If you press the h key, a help message is displayed:
An interesting instruction is:Button B,Button B allows you to return to the previous page. In other words, the bbutton can allowFlip the page forward.
You can use... The first page information to confirm that the current display is the previous page.
Do not scrollPASS ParametersThe-c and more commands do not scroll the page, but directly clear the previous content and replace it with the content on the next page. With-Coption, more will not scroll the page. It will clear the previous page and put the next page or lines there.
$ more -10 -c lynis.log
If you press the Space key, the next page will still have the same size.
Ignore unnecessary blank rowsParameters Used-S to ignore unnecessary blank rows. The following is an example:
When we add Parameters-S:
$ more -s doc_30.txt
Search for stringsIf your log file is very large, it is not that easy to search for the desired string. The search function of the more command can help you through Parameters+/String can be used to search for strings. The keywords found are displayed in the first line. For exampleSearch for"Dhclient ", the more command format:
$ more +/dhclient /var/log/syslog
Then, if you want to continue searching for the next one in the file, you only need to press/Button, followed by the dhclient keyword.
Display from the specified rowYou can also use parameters+ Number to specify the row to be displayed. For example, we have a file with 15 rows:
Then we want to display the content of this file starting from line 1, and the command will look like this:
$ more +5 doc_30.txt
Can binary files be displayed?The answer is no. The more command will prompt such information, for example:
ConclusionMore is a basic tool used to view text files. It cannot be used to display binary files. Generally, we can use the commandMan more orMore -- help to get