Americas

  • United States
sandra_henrystocker
Unix Dweeb

There’s more to more than meets the eye

How-To
Aug 18, 20234 mins
Linux

The more command on Linux may have a lot more options than you know and use.

analyze / inspect / examine / find / research / data / magnifying glass
Credit: Thinkstock

The Linux more command is a fairly obvious command to use when you want to scan through a text file a screen at a time, but there still might be quite a few things you don’t know about this command. For one thing, you don’t have to start at the top of the file if you don’t want to. Add an argument like +20 and you will start with the 20th line in the file with a command like that shown below.

$ man +20 myfile

Note that the more command automatically adjusts itself to the number of lines in your terminal window. In addition, the last line displayed will not be a line from the file by default, but an indication of what percentage of the text has been displayed thus far – at least if there’s more text to follow. It will look like this:

--More--(14%)

So, if your terminal window is 40 lines tall, more will display 39 lines from your file followed by the percentage of text displayed thus far. Use the -d option and you’ll see this instead of just the percentage indication shown above.

--More--(45%)[Press space to continue, 'q' to quit.]

Keep reading to check out some additional options.

Moving up and down when viewing a file

When viewing a file using the more command, you can move back up in the file using the up arrow or pressing “b”. You can move all the way to the beginning and then review the entire file a second time if you want.

Automatically exit at the end of the file

The more command will leave you staring at (END) when you reach the end of a file – and then continue adding a screenful of blank lines as long as you continue pressing the space bar. The benefit is that you’ll still be using more and that you will be able to move back up through the text using the up arrow key if you want. If, however, you simply want to exit as soon as you reach the end of the file, use the -e (exit) option like this:

$ more -e myfile

Squeezing out white space

To turn multiple blank lines into a single line everywhere they appear in your file, use the -s (squeeze) option.

$ more -s myfile

Scrolling slowly through a file

To scroll through a text file less than a screenful of lines at a time, use the -n (number of lines) option. This will add the number of lines you specify each time you press the enter key and can make it easier to focus on each section of the output.

$ more -n 10 myfile

Note that you can specify a number that exceeds the lines on your screen and the extra text will slide past the top of your window.

Displaying multiple files

You can ask the more command to display multiple files simply by listing them in this manner:

$ more file1 file2

You will see each file name displayed before its content as shown in the example below.

::::::::::::::
file1
::::::::::::::
This is a boring file.
I can't even get my cat to look at it.
How will she ever come to enjoy the Linux command line?

To get to the next file, you have to press the 2-character string “:n” and then the enter key.

...Skipping
...Skipping to file file2

::::::::::::::
file2
::::::::::::::
This is a short file.
Isn't it?

Wrap-up

The more command is one of a number of commands that will allow you to examine the content of files. Check out the post listed below to view some additional options.

5 ways to examine the content of files on Linux

sandra_henrystocker
Unix Dweeb

Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she's chasing the bears away from her bird feeders.

The opinions expressed in this blog are those of Sandra Henry-Stocker and do not necessarily represent those of IDG Communications, Inc., its parent, subsidiary or affiliated companies.

More from this author