Linux more Command Tutorial for Beginners (5 Examples)

Sometimes, while working on the command line, you'll see outputs produced by commands in certain cases are so large that they don't fit into the screen area, and hence, you get to see only the last part of the output (as the initial part scrolls past the screen). Thankfully, there are utilities that are specifically designed to help you in such cases, and one of them is more.

In this tutorial, we will discuss the basics of more using some easy to understand examples. Please note that all examples in this article have been tested on an Ubuntu 16.04 LTS system.

Linux more command

The more command helps you navigate outputs from commands in a user-friendly way. Following is the tool's syntax:

more [options] file...

And here's how the man page defines it:

       more - file perusal filter for crt viewing

more is a filter for paging through text one screenful at a time.  This
       version is especially primitive.  Users  should  realize  that  less(1)
       provides more(1) emulation plus extensive enhancements.

Following are some Q&A-styled examples that will give you a good idea on how more works.

Q1. How to use more command?

Basic usage is very easy. Let's say you are trying to 'cat' a file, and it's too long/large to be displayed on your screen, then you can use the more command in the following way:

more [filename]

How to use more command

Now, to scroll the display up one line at a time, press enter. If you want to scroll a screenful in one go, use the space bar key. Backwards scrolling can be achieved by pressing 'b'. Oh, and yes, you can also search stuff by pressing '/' and entering the search keyword (just like you do in man pages).

Q2. How to use more with other command line tools?

You can also combine the more command with other command line tools, something which can be done using pipes. For example:

dmesg | more

In the above command, the display of the output produced by dmesg will be handled by more. So you can easily scroll up, down, and even perform search operations.

Here's another example:

ls -lart | grep *.txt | more

Q3. How to make more prompt useful information?

Use the -d command line option for this. This will enable more to prompt with "[Press space to continue, 'q' to quit.]", and display "[Press 'h' for instructions.]" whenever an illegal key is pressed.

For example:

more -d [filename]

How to make more prompt useful information

Q4. How to make more ignore multiple blank lines?

If you want, you can even force the more command to squeeze multiple blank lines into one. This can be done using the -s command line option.

more -s [filename]

For example, a file like this:

How to make more ignore multiple blank lines

was displayed by more in the following way when the -s option was used:

Blank lines removed from output

So you can see multiple empty lines got squeezed into a single one each time the more command encountered them.

Q5. How to reduce the number of lines more uses?

By default, more uses the complete screen to display output. However, you can even customize this in terms of number of lines used by the tool. This can be done by explicitly specifying the number of lines you want more to use.

For example, if we want more to display the output using 10 lines at a time, then we can do that in the following way:

more -10 [filename]

How to reduce the number of lines more uses

Conclusion

As you'll likely agree, the more command is a useful little utility that can be of great help in specific scenarios. We've discussed the basic operation here. Once you're done with it, you can learn more about the tool by heading to its man page.

Share this page:

0 Comment(s)