sebastiano.tronto.net

Source files and build scripts for my personal website
git clone https://git.tronto.net/sebastiano.tronto.net
Download | Log | Files | Refs | README

more.md (7452B)


      1 # The man page reading club: more(1)
      2 
      3 *This post is part of a [series](../../series)*
      4 
      5 In the second episode of this blog series we are going to cover a UNIX
      6 pager.  Instead of the popular less(1), we are going to check out the
      7 classic more(1).
      8 
      9 ## In the bunker
     10 
     11 *After installing your new OS and checking out the basic documentation,
     12 you are excited to discover what your laptop can do. But there is
     13 something keeping you back. Maybe it's the rumors that the nuclear
     14 winter will be raging for years to come and you are in there for the
     15 long run. No, it's not that.*
     16 
     17 *You feel that learning is fun, and fun is precious, so you should not
     18 waste it.  Entertainment is a scarce resource in the bunker: social
     19 interactions are awkward, and the battery-charging gym only offers
     20 re-runs of crappy mainstream reality shows.*
     21 
     22 *You dedice to play the slow game and
     23 [RTFM](https://en.wikipedia.org/wiki/RTFM) some more before doing actual
     24 work. You have just found out that the man(1) program calls an external
     25 utility, called less(1), to actually display the page. Learning more
     26 abut this makes sense.*
     27 
     28 ```
     29 $ man less
     30 ```
     31 
     32 *You start reading, but you soon feel overwhelmed: this manual page is a
     33 fucking novel! There are pages and pages of options, and on top of that
     34 there are commands, and you can't make sense of what is actually useful.
     35 You scroll back to the top of the page and something catches your eyes:*
     36 
     37 ```
     38 less is similar to the traditional more(1), but with many more features.
     39 ```
     40 
     41 *Hoping it will be easier to grasp, you decide to look into more(1)*
     42 
     43 ```
     44 $ man more
     45 ```
     46 
     47 *No, wait! Let's use what we learned [last time](../2022-05-29-man):*
     48 
     49 ```
     50 $ PAGER=more man more
     51 ```
     52 
     53 ## more(1)
     54 
     55 *Follow along at [man.openbsd.org](https://man.openbsd.org/OpenBSD-7.1/more)*
     56 
     57 The description of more(1) starts with
     58 
     59 ```
     60 The more pager displays text one screenful at a time. After showing each
     61 screenful, it prompts the user for a command.  Most commands scroll the text
     62 or move to a different place in the file, while some switch to another file.
     63 ```
     64 
     65 So "commands" seem to be the interesting part. There are also a handful of
     66 options, but they seem quite technical and not so interesting. Just to name
     67 a few: `-n` changes the number of lines per screenful, `-p` can be used to
     68 execute a command when a file is first opened and `-t` can be used to view
     69 a file containing a specific "tag". This last one is enticing, but it
     70 redirects to ctags(1), which may be a good topic for a future post.
     71 
     72 Let's move on to the juicy part!
     73 
     74 ```
     75 COMMANDS
     76 	Interactive commands for more are based on vi(1).  Some commands may be
     77 	preceded by a decimal number, called N in the descriptions below.  In the
     78 	following descriptions, ^X means control-X.
     79 ```
     80 
     81 The first command is `h`, which displays a help page for more(1). It is
     82 basically a more terse, cheatsheet-like version of the COMMANDS section
     83 that we are reading.
     84 
     85 The basic navigation commands scroll the current page up or down. They can
     86 all be preceded by the number of lines to be scrolled, but have different
     87 defaults: `j` (or `RETURN`) scrolls down one line, `k` up one line. `f`
     88 (or `SPACE`, or `^F`) and `b` (or `^B`) scroll one window down and up,
     89 respectively. `d` and `u` (or `^D` and `^U`) scroll half a
     90 window down and up, respectively. It is not documented in the manual, but
     91 arrow keys, and `PgUp` and `PgDn`, seem to work just fine too.
     92 
     93 Perhaps more interestingly, the commands `m` and `'` (single quote) allow
     94 you to "mark" certain lines and move to them:
     95 
     96 ```
     97 m	Followed by any lowercase letter, marks the current position with that letter.
     98 
     99 '	(Single quote.)  Followed by any lowercase letter, returns to the position
    100 	which was previously marked with that letter.  Followed by another single
    101 	quote, returns to the position at whcih the last "large" movement command was
    102 	executed, or the beginning of the file if no such movements have occurred.
    103 	All marks are lost when a new file is examined.
    104 ```
    105 
    106 There is also a search function:
    107 
    108 ```
    109 /pattern   Search forward in the file for the N-th line containing the pattern.
    110            N defaults to 1.  The pattern is a basic regular expression (BRE).
    111            See re_format(7) for more information on regular expressions.
    112            The search starts at the second line displayed.
    113 ```
    114 
    115 Regular expressions are a powerful tool, but we will not see them in detail
    116 today. For now it is enough to know that plain text is a perfectly fine
    117 regular expression.
    118 
    119 There are alternative commands for searching: using `?` instead of `/`
    120 searches backwards from the top line, while `/!` and `?!` search for lines
    121 that *do not* match the pattern. In each case the search command can be
    122 preceded by a number `N`, meaning we want to find the `N`-th line that
    123 matches the search. I can see this being useful with `N=2` in case you
    124 want to find the first next occurrence of a word that appears on the
    125 current screen. But it is probably easier to just rely on the `n` and `N`
    126 commands, which simply repeat the previous search, in the same or opposite
    127 direction respectively; for example, using `N` after a `?` search searches
    128 for the same pattern *forward*.
    129 
    130 The next group of commands is used to move between different files: `:e`
    131 to open a new one, `:n` for the next file and `:p` for the previous.
    132 `:t` is used to move between the aforementioned (but not explained) tags.
    133 
    134 If you are using more to view a file, the command `v` can be used to edit it,
    135 using the editor vi(1) by default.
    136 
    137 And finally
    138 
    139 ```
    140 q | :q | ZZ    Exits more.
    141 ```
    142 
    143 The last sections are fairly short, but worth skimming through.
    144 
    145 The ENVIRONMENT section explains that more can read some environment
    146 variables to change its behavior. In my opionion the most interesting
    147 ones are `EDITOR`, which changes the editor to be used with the `v`
    148 command, and `MORE`, which can be used to set default options for more.
    149 
    150 An interesting example in the EXAMPLES section:
    151 
    152 ```
    153 Examine several manual pages, starting from the options description in
    154 the DESCRIPTION section:
    155 
    156 	$ more -p '/DESCRIPTION
    157 	> /options
    158 	> ' *.1
    159 ```
    160 
    161 And a word of warning from the STANDARDS section:
    162 
    163 ```
    164 The more utility is compliant with the IEEE Std 1003.1-2008 ("POSIX.1") specification,
    165 though its presence is optional.
    166 ```
    167 
    168 This means that, unfortunately, when dealing with some more obscure POSIX
    169 operating system you may not have the luxury of a pager program. Too bad.
    170 
    171 ## Conclusions
    172 
    173 It is worth noting that the more(1) manual page states
    174 
    175 ```
    176 The present implementation is actually less(1) in disguise.
    177 ```
    178 
    179 In practice this means that in OpenBSD, even when using more, one can
    180 make full use of the extra features of less described in its manual
    181 page. One of the few differences is how certain options are interpreted.
    182 
    183 I originally planned to write about less(1), but I was, as the fictional
    184 *you* in the nuclear bunker, overwhelmed by the amount of options
    185 available.  Most of them are either quite technical or just change
    186 slightly the behavior of the pager. Some can be nice, but definitely
    187 not necessary (e.g.  `-P` to change the prompt).
    188 
    189 I don't see myself using any of the extra features described in the less(1)
    190 man page, with the notable exception of the `|` (pipe) command, which 
    191 can be used to pipe arbitrary portions of the current file to an external
    192 command. But apart from this I could easily live in the pre-1985 era.
    193 
    194 See you next time!
    195 
    196 *Next in the series: [shutdown(8)](../2022-07-07-shutdown)*