A modern terminal pager

Command Line – most

© Lead Image © Leeavision, 123RF.com

© Lead Image © Leeavision, 123RF.com

Article from Issue 273/2023
Author(s):

The most terminal pager offers a feature-rich, better organized alternative to less.

Pagers are commands for viewing files one page at a time in the terminal. Roughly speaking, pagers serve the same function at the command line as Plasma's Okular, although pagers are usually used for text files or as a pipe to make screen output from other commands more readable without scrolling. At times, a version of cat can be used for the same purpose, but technically, the pager name is reserved for three commands: less, more, and – most recently – most [1], names that are a sequence of puns, less being more, as the popular saying goes, and more being greater than less. As the newest pager, most is by far the most usable (Figure 1), because the alternatives are limited or awkward to use as soon as you go beyond the bare command.

Figure 1: Displaying a text file with most.

The trouble with cat is that, strictly speaking, it is not a pager at all. Its main function is to concatenate or join files together. It can function as a pager, especially for a short file, simply by specifying a single file, but cat cannot scroll or do more than number lines and display non-printing characters. A cat clone, bat, offers all the functions of cat, plus backwards scrolling, range, and the ability to display in a pager with --pager PAGER. However, bat is at best a basic pager.

As for more, it is 45 years old. Its age shows in the fact that some versions of more do not support backwards scrolling, even today, as well as in the continued existence of --print-over (-p), which instead of scrolling, clears each screen as the next one is printing, and of --plain (-u), which would suppress underlining, except that today it is left unenabled. The best that can be said for more is that it has a handful more options than bat.

Such limitations leave most users with less. While highly functional, less sometimes seems an over-reaction to more with less's dozens of options, including those for search and navigation. In general, less is a solid foundation, which is why it continues to be the standard pager, despite most's longer feature list.

Making the Most of most

By taking advantage of today's readily available memory, most offers features that less does not. In particular, if compiled that way, most can open multiple files of at least two lines, a feature that is ideal for file comparison. Multiple files are opened by listing them in a space-separated list after the command and any options:

most OPTIONS FILE1 FILE2

The name of the file is displayed at the bottom of a window in the status line. Below the status line is any current activity or a set of basic instructions (Figure 2).

Figure 2: At the bottom of the current main window, you see that most is about to switch to another open file.

Within each window, commands can be given simply by typing the letter, without the one- or two-hyphen prefix required by an option when starting most. Note, though, that which option is used for each command depends on how most is compiled, so if one option listed in the man page fails to work, another may be successful (the options covered here are the ones that worked for me, sometimes after trial and error). Each window can be scrolled independently, or synced with other windows using l or L, which adds an asterisk (*) to the status line. By default, most does not wrap lines; long lines are indicated by a dollar sign ($) in the right margin of the window. You can see the rest of the line by scrolling with the right arrow key or by expanding the width of the terminal window. However, adding the -w option to the command wraps lines, marking the right margin with a back slash (\). Conveniently, by adding the -e option to the command, you can edit the current window, which means that most can also act as a text editor. To move to another window, enter n and the name of the next file entered in the command appears at the bottom of the window; you can access that file by pressing the Enter key. However, you might prefer instead to split the current window with Ctrl+X+2.

Like less, most has an extensive list of keyboard shortcuts for navigation. The most man page lists several dozen, many of which have two or even three alternatives. Mercifully, though, within a window, you do not need to learn all of the shortcuts to navigate efficiently. That said, t and b are handy for moving to the top and bottom of the window. So are NUMBER J to jump to a specific line number or NUMBER % to jump to a percentage of the way through a file. In a long file, you might also opt for NUMBER U to jump back a set number of screens. More simply, you can just use the Up and Down arrow keys to scroll, either by the default single line or by your choice of lines by entering a number before you press the arrow key.

A set of search functions are also available with most. When starting most, you can add -c to make searches case sensitive. Within most, f prompts for a string for which to search forward. Similarly, a question mark (?) prompts for a string for which to search backwards. With both f and ?, Ctrl+G cancels the search. Once you have located a string, m sets a bookmark. From there, Ctrl+X then Ctrl+x (with the same keys used twice) can return you to another bookmark, so you can toggle back and forth, a handy feature as you edit.

Simplifying Learning

Another advantage of most over less is that it is better organized than less. For one thing, most has far fewer options to add to the command, and most of those turn features on or off that the majority of users are unlikely to need. Although most's man page is still unusually long, it is shorter and far better organized than that for less.

The same is true of most's environmental variables. There are fewer of them than in less, and several are designed to minimize the need to memorize options and commands. MOST_SWITCHES sets options, one per line. For example,

define MOST_SWITCHES "-s"

stops the display of more than one blank line in a row. MOST_INITFILE is even more convenient because it defines a configuration file, looking for it in /etc/most.conf or in .mostrc in the current account's home directory. No matter where it is found, this configuration sets the default keybindings, using for each the format

setkey "FUNCTION" "KEYBOARD SHORTCUT"

Taking the time to create a configuration file can save regular most users the need for memorization, as well as involved typing. MOST_HELP can also be used to set a custom help file with details not mentioned in the default one. As well, those who edit in most may also want to set their editor of choice in MOST_EDITOR. The advantage of most lies not only in features and organization, but in these time-saving devices. Like templates in a word processor, these environmental variables take time to set up, but in the end can bring users quickly up to speed and save time.

The Author

Bruce Byfield is a computer journalist and a freelance writer and editor specializing in free and open source software. In addition to his writing projects, he also teaches live and e-learning courses. In his spare time, Bruce writes about Northwest Coast art (http://brucebyfield.wordpress.com). He is also co-founder of Prentice Pieces, a blog about writing and fantasy at https://prenticepieces.com/.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Most Is More Than Less

    If you like to customize your command-line file pager, check out most.

  • Command Line: File Viewers

    Practical tools such as cat, less, and head are convenient for viewing text.

  • Command Line: Archives

    Gzip and bzip2 not only compress files, they also provide lean and powerful tools for viewing, searching, and comparing text files.

  • DeskTOPia: Skippy

    If your window manager is too boring or Spartan for your liking, why not add a touch of pep? Skippy is an imaginative screen pager with an integrated preview function.

  • A Tale of tails

    When it comes to file monitoring, tail's replacements, colortail and MultiTail, offer more sophisticated control over how your information is displayed.

comments powered by Disqus