A flexible, command-line pager

Command Line – most

© Lead Image © Sergey Jarochkin, 123RF.com

© Lead Image © Sergey Jarochkin, 123RF.com

Article from Issue 220/2019
Author(s):

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

Many files you may want to view from the command line require more than a single screen to display. As a result, they scroll by too quickly to read and are most conveniently read with a file pager. The oldest surviving pager is the more [1] command, which has a limited set of options. When a more sophisticated pager was released, it was called less [2], because, as the old saying goes, "less is more." A third-generation pager continues the joke by being called most [3], apparently on the ground that most is more than less.

As a joke, the name ranks for better or worse with recursive acronyms like GNU's Not Unix (GNU). However, as a pager, most offers far more flexibility than less or more in viewing, navigation, and customization.

Enabling Display Behaviors

most is apparently written with the assumption that it will be used most of the time to scan a file's contents. If you simply enter the basic command followed by the file to view, you will notice that the display has some peculiarities (Figure 1). For example, if a line has more characters than most's terminal width, the lines are truncated with a dollar sign ($) as the last character in the line. To view the rest of the line, you must use the right arrow key. If you use the -w option to wrap the line, then a backslash (/) is added unless you also add the -d option. So, should you want to view a file without these extra characters, the basic command structure should be:

Figure 1: Some of most's features include the status information on the bottom, the $ sign that marks truncated lines, and options for line numbering and displaying tabs as ^I.
most -wd FILE

However, you can also enable or disable other aspects of the display. For instance, to save space, you can use the -v option to have control characters display with a prefix of ^ rather than Ctrl-CHARACTER. Similarly, the -t option renders tabs as ^I. If a file contains several blank lines in a row, you might add -s to replace them with a single blank line.

If you are referring to the file in detail and moving back and forth in it, another useful option is to add line numbers using +lineno. Still another option is to view the file as binary using -b (Figure 2). When you want to find a certain passage in a long file, you can also use the option +/STRING to jump directly to a keyword or phrase, further refining the search by making it case-sensitive with -c.

Figure 2: most also supports viewing files in binary format.

If you are looking at files to decide what to delete, still another useful option is +d. With this option enabled, you can activate a toggle once the file is open to delete it after confirming the action.

Other options that you can toggle while viewing a file include :c for case sensitivity and :o or :O, which allows you to add b (binary), d (selective display), t (tab), v (verbose), or w (wrap). Without these toggles, upon discovering a need for these options, you would have to exit and edit the command to use them.

Navigating Basics

While viewing a file in most, you can navigate with just the Up and Down arrow keys and close the file with Q, Ctrl+X, or Ctrl+C – whichever you prefer. Each time you press an arrow key, the cursor moves one line. However, if you enter a number before pressing an arrow key, you will move that number of lines.

By default, most displays in a 60-column line, truncating the rest of the line. You can view the rest of the line with the right arrow plus the Tab key, or the left arrow plus Ctrl+B, depending where the cursor is on the line.

You can make larger jumps in the displayed file, too. T+Esc takes you to the top of the file and B+Esc to the bottom. When the file displays over several windows, you can use the structure NUMBER% (such as 3%) to jump to a specific spot in the file. If you are moving back and forth in a file, you can use Ctrl+@ or Ctrl+K to add a bookmark to the current line. Once you have one bookmark, you can return to it by pressing Ctrl+X or Ctrl+K+Enter, which also creates another bookmark at your current position if one does not already exist.

Working with Multiple Files

With all these options for viewing a file, you might almost overlook the fact that a single instance of the command can deal with multiple files. Working with multiple files isn't made easier by the fact that most's man pages eke out information by separate snippets. Some users, too, might wonder whether the reference to displaying each file refers to a separate terminal or a separate screen of information (which is actually the case).

However, once you piece the information together, working with multiple files is straightforward. All that is required is a space-separated list of filenames in the command. If you want, you can specify the same file twice, so you have convenient access to different passages.

To move between multiple files, you can toggle :n to move to the next file in the list, selecting it by pressing any key except Q. Each file can have its own separate options for display, and can be searched separately. However, you can toggle L to lock each file, which is indicated by an asterisk (*) on the left of the status bar at the bottom of the display. All windows that are locked will scroll together, a feature that can help you compare two copies of a file for differences.

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

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News