Terminal Pagers

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

A terminal pager, or paging program, is a computer program used to view (but not modify) the contents of a text file moving down the file one line or one screen at a time. Some, but not all, pagers allow movement up a file. A popular cross-platform terminal pager is more. More can move forwards and backwards in text files but cannot move backwards in pipes. Less is a more advanced pager that allows movement forward and backward, and contains extra functions such as search.

Some programs incorporate their own paging function, for example bash’s tab completion function.

Examples

  • more
  • less
  • most
  • pg
  • nano --view
  • emacs -nw -e "(view-mode)"

In this article we will discuss the differences Between more, less, and most in Linux

Overview

When viewing file contents in Linux, we may benefit from some interactive features to help us. We might need to see statistics of a file that we’re viewing, mark a certain line then return to it, or view the contents of a file while it’s being updated.

In this tutorial, we’ll briefly discuss the usage and differences of three terminal pagers that are used in Linux.

Terminal pagers are used to view files page by page, and/or line by line. We’re going to explore three of them: more, less, and most. All of them have similar features such as viewing multiple files simultaneously, but each one has a prominent feature or advantage that might make us consider using it.

Usage

We can use all of the tools by passing one or more file names:

more unixcop1.txt unixcop2.txt unixcop3.txt
less unixcop1.txt unixcop2.txt unixcop3.txt
most unixcop1.txt unixcop2.txt unixcop3.txt

To exit any of the tools, we can press q or ctrl+c.

We can also pipe the output of another command as an input:

history | less

The output:

Availability

The more tool is available on most Linux and Unix-like operating systems. less is also widely available, but some Alpine Linux distributions don’t have it installed by default. On the other hand, most is usually not installed by default.

We can install most using a package manager. For example, on Ubuntu, we can install it using:

apt install most

1. more

1.1. Using more

more is one of the oldest terminal pagers in the UNIX ecosystem. Originally, more could only scroll down, but now we can use it to scroll up one screen-full at a time, and scroll down either one line or one screen-full:

more unixcop.repo

An example output would be:

On its status bar, more shows the percentage of the file read. It automatically closes when it reaches the end of the file without having to press a button.

1.2. Interactive Commands

more has many interactive commands we can invoke by keystrokes:

  • space â€“ go to the next page in accordance with the terminal’s size
  • b â€“ go back one page
  • enter â€“ scroll down one line
  • = – display the current line number
  • :v – start up the vi text editor at the current line

2. less

One of the reasons why less was introduced was to allow backward movement line by line. It has a lot of commands that are similar to the vi text editor’s commands, and it supports horizontal scrolling, live monitoring, and more.

2.1. Support of File Formats

less has support for different file formats. For example, if we try to read a pngjpeg, or jpg file with more, it would just print its binary data, whereas less would print its metadata:

less picture.jpg

picture.jpg JPG 743x533 743x533+0+0 8-bit sRGB 45.6KB

less supports other file formats such as jar, war, zip, pdf, tar.gz, gif, png, tiff, tif, and rar.

2.2. Marking

While reading a large file, we may want to set bookmarks in certain locations to be able to return to them.

With less, we can mark a certain line by pressing m followed by another character, for example, A. We can mark another line by pressing m followed by another character such as B. Then, after we have scrolled elsewhere in the file, we can return to the marked lines by pressing the apostrophe key (‘) followed by the character that we used for marking.

In this example, we can switch between our bookmarks by typing â€˜A and â€˜B.

2.3. Monitoring

Let’s say we want to watch the content of a log file while it’s being updated, but we don’t want to have to re-run less on it over and over. We can switch to seeing the updating content of the file by pressing Shift+F keys, or by executing the command with the addition of the +F flag:

less +F /var/log/syslog

3. most

Most allows us to view multiple files simultaneously and switch between them. It’s very useful for viewing large data sets because most does not wrap lines that have more characters than the terminal page. Instead, it truncates them and offers column-by-column horizontal scrolling.

3.1. Multiple Windows

We can display multiple files and switch between them by passing files as arguments to most:

most text.txt file.txt

-- MOST: text.txt                                   (18,4) 5%

By default, while reading a file, the status bar displays the file name, the percentage that we’ve viewed so far, the current line number, and current position horizontally since we can scroll left and right by pressing left and right keys.

We can switch between files by pressing :n. Then, we can use up/down arrow keys to change file names, and press enter to switch to the selected file:

-- MOST: text.txt                                   (18,4) 5%
Next File (1): file.txt

We may also want to read one file in binary mode and another file in non-binary mode. most allows us to view different files in different modes. For example, we can toggle options while viewing a file by pressing : followed by o, then we can toggle the binary mode by pressing b.

Comparing the Tools

If we want a simple terminal pager that is widely available, then we would choose more.

But, if we want to use vi text editor’s commands, and prefer a tool that has more sophisticated scrolling both horizontally and vertically, then less is a good option.

more and less have the option to view multiple files at once. more allows us to view them as a single file separated by lines, and less allows us to switch between them. However, both more and less display all the opened files with the same options.

Finally, if we want to open multiple files with different options, or see more information on the status bar while viewing a file, then most is a good choice, but may require installing in our Linux environment.

Conclusion

In this article, we learned about the features of the most common Linux terminal pagers — moreless, and most.

Then we looked at how the tools differ and how to choose between them.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
MQ-Jr
MQ-Jr
unixcop Admin

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook