What is more command in Linux and how to use

Today, We will learn the basic understanding of the “more” command in Linux. We will also see the usages of the “more” command and their example. Read: pipe (|) operator in Linux command

What is the “more” command in Linux?

Sometimes, while working on the command line, We will see outputs produced by commands in certain cases are so large that they don’t fit into the screen area, and hence, we get to see only the last part of the output. The “more” command is specially designed for these cases to see the command output on a screen area. For better understanding, let’s have few use cases and examples: Also Read: Filter Logs with Grep : linux Command Grep

Use of the “more” command

The more command helps you navigate outputs from commands in a user-friendly way. Following is the syntax of the “more” command:

more [options] filename

The basic Use of the “more” command

As the “cat” command displays the file content, the same way the “more” command also displays the content of a file. The only difference is that, in the case of larger files, the “cat” command output will scroll off your screen while the “more” command displays output one screenful at a time.

Following keys are used in the “more” command to scroll the page:

  • Enter key: To scroll down page line by line.
  • Space bar: To go to next page.
  • b key: To go to the backward page.
  • / key: Lets you search the string.

Example of the “more” command to display the file content.

# more /etc/httpd/conf/httpd.conf
more command example

Look at the above snapshot, in the below-left corner of the snapshot it shows 12%, which indicates that 12% page is displayed.

To scroll down using the “space” button, the next page will be displayed.

If you want to scroll down the page line by line using the “enter” key.

If you want to go to the last or backward page using the “b” key.

you can also search stuff by pressing “/” and entering the search keyword (just like you do in man pages or with the “vi” command).

The “more” command use with other commands

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 the “dmesg” command 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

Do more with the “more” command

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]

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]

By default, more uses the complete screen to display output. However, you can even customize this in terms of the 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]

Read Also : grep : Linux Command

Leave a Reply