Everything You Need To Know About The More Command

The Linux More Command
The Linux More Command.

Introduction

This guide will teach you everything you need to know about the "more" command in Linux. There is a very similar command called the "less" command which performs similar functionality to the "more" command which is generally considered to be more useful

Within this guide you will find out the common uses for the "more" command. You will also be shown all the available switches along with their meanings.

What Does The Linux More Command Do

The more command allows you to display output in the terminal one page at a time. This is especially useful when running a command which causes a lot of scrolling such as the ls command or the du command.

Example Uses Of The More Command

Run the following command in a terminal window:

ps -ef

This returns a list of all the processes running on your system.

The results should scroll beyond the end of the screen. 

Now run the following command:

ps -ef | more

The screen will fill up with a list of data but will stop at the end of the page with the following message:

-- more --

To move on to the next page press the space bar on the keyboard.

You can continue pressing space until you reach the end of the output or you can press the "q" key to exit.

The more command works with any application that outputs to the screen. 

You don't need to pipe the output to the more command.

For example if you want to read a text file a page at a time use the more command on its own as follows:

more <filename>

A good way of testing this is to type the following into a terminal window:

more /etc/passwd

 

Change The Message

You can change the message for the more command so that it displays the following:

press space to continue, q to quit

To get the above message displayed use more in the following way.

ps -ef | more -d

This also changes the behaviour of the more command when you press an incorrect key.

By default there will be a beep but by using the -d switch you will see the following message instead.

Press h for instructions

How To Stop Text From Scrolling

By default the lines of text scroll up the page until the screen is filled with new text. If you want the screen to clear and the next page to be displayed without scrolling use the following command:

more -p <nameoffile>

You can also use the following command which will paint each screen from the top, clearing the remainder of each line as it is displayed.

more -c <nameoffile>

Squeeze Multiple Lines Into One Line

If you have a file with lots of blanks lines in it then you can get more to compress each block of blank lines into one line.

For example look at the following text:

this is a line of text



this line has 2 blank lines before it



this line has 4 blank lines before it

You can get the more command to display the lines as follows:

this is a line of text

this line has 2 blank lines before it

this line has 4 blanks lines before it

To get this functionality run the following command:

more -s <nameoffile>

Specify The Size Of The Screen

You can specify the number of lines to use before the more command stops displaying text.

For example:

more -u5 <nameoffile>

The above command will display the file 5 lines at a time.

Start More From A Certain Line Number

You can get more to start working from a certain line number:

For example imagine you had the following file:

this is line 1
this is line 2
this is line 3
this is line 4
this is line 5
this is line 6
this is line 7
this is line 8

Now look at this command:

more +u6 <nameoffile>

The output would be as follows

this is line 6
this is line 7
this is line 8

The scrolling aspect would remain. 

more +u3 -u2 <nameoffile>

The above command will display the following:

this is line 3
this is line 4
-- more --

Start From A Certain Line Of Text

If you want to skip most of a file until you get to a certain line of text use the following command:

more +/"the text to search for" <nameoffile>

This will display the word "skipping" until you get to the line of text.

Scroll A Certain Number Of Lines At A Time Using More

By default when you press the space bar the more command will scroll for the length of the page which is either the size of the screen or the setting specified by the -u switch.

If you want to scroll 2 lines at a time press the number 2 before pressing the space bar. For 5 lines press 5 before the space bar.

The above setting only lasts for that one key press however. 

You can set a new default which takes precedence over the previous one. To do this press the number of lines you wish to scroll by followed by the "z" key.

For example "9z" will cause the screen to scroll 9 lines. Now when you press space the scroll will always be 9 lines.

The return key scrolls one line at a time. If you want this to be 5 lines at a time press the number 5 followed by the return key. This becomes the new default so the return key will always scroll by 5 lines. You can of course use any number you choose, 5 is just an example.

There is a fourth key which you can use for scrolling. By default if you press the "d" key the screen will scroll 11 lines at a time. Again you can press any number before pressing the "d" key to set it at a new default. For example "4d" will cause more to scroll 4 lines at a time when "d" is pressed.

How To Skip Lines And Pages Of Text

When using the more command you can also skip lines of text.

For example pressing the "s" key skips 1 line of text. You can change the default by entering a number before the "s" key. For example "20s" changes the behaviour so that the skip is now 20 lines of text.

You can also skip whole pages of text. To do this press the "f" key. Again entering a number first will cause the more command to skip the specified number of pages of text.

If you have gone too far forward you can use the "b" key to skip back up a line of text. Again you can use a number before the "b" to skip a specified number of lines back up the way. This can only work when using the more command against a file. 

Display The Current Line Number

You can display the current line number by pressing the equals key (=).

How To Search For Text Using More

To search for a text pattern using the more command press the forward slash and enter an expression to search for.

For example "/hello world"

This will find the first occurrence of the text "hello world".

If you want to find the 5th occurrence of "hello world" use "5/"hello world""

Pressing the 'n' key will find the next occurrence of the previous search term. If you used a number prior to the search term that will take precedence. So if you searched for the 5th occurrence of "hello world" then pressing "n" will look for the next 5th occurrence of "hello world".

Pressing the apostrophe (') key will go to the place where the search started.

You can use any valid regular expression as part of the search term.

Summary

For more information about the more command read the Linux man page.

More From Us