Linux more command: displays long text files page by page

Source: Internet
Author: User

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 use the more 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 more

To 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 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 page

When executing the more command, it will occupy all the space in your terminal window for display. However, you can use the parameter-number to limit the number of lines displayed on each page.

For example, if you want to display up to 12 lines per page, 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 message

As 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 problem, we can add the-d parameter during execution, which will display an additional line of user information "[press the Space key to continue, 'q' to launch.]"

If you press a button other than 'space' or 'q', more will display 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 the "B" button, which allows you to return to the previous page. In other words, the "B" button can be used to flip the page forward.

You can use the information on the first 1 page in the upper left corner to confirm that the current page is displayed.

Do not scroll

Through the-c parameter, the more command does not scroll the page, but directly clears the previous content and replaces it with the content on the next page. With-c option, 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 rows

The parameter-s is used to ignore unnecessary blank rows. The following is an example:

After we add the parameter-s:

$ more -s doc_30.txt

Search for strings

If 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 search for strings using the +/string parameter. The keywords found are displayed on the first line. For example, to search for "dhclient" in the/var/logs/syslog file, the format of the more command is as follows:

$ more +/dhclient /var/log/syslog

Then, if you want to continue searching for the next one in the file, you only need to press the/button, followed by the keyword dhclient.

Display from the specified row

You can also specify the row to be displayed through the parameter + number. For example, we have a 15-row file:

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:

Conclusion

More is a basic tool used to view text files. It cannot be used to display binary files. In general, we can obtain the command man more or more -- help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.