A modern terminal pager
Command Line – most
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.
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).
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.
Infos
Buy this article as PDF
(incl. VAT)