26

I saw "pager" in several places:

less is a terminal pager program on Unix

option -P for man Specify which output pager to use.

What is a pager? How is it related to and different from a terminal? Thanks.

Tim
  • 101,790

2 Answers2

35

As the name implies, roughly a pager is a piece of software that helps the user get the output one page at a time, by getting the size of rows of the terminal and displaying that many lines.

The most popular pagers in a UNIX text environment are more and less. The latter is kind of a joke as less can actually do more then more.

U. Windl
  • 1,411
schaiba
  • 7,631
  • 1
    what is like with and without a pager? Thanks. – Tim Jul 11 '14 at 15:35
  • 7
    if you don't pipe your output through a pager (less, more and most come to mind), that output will appear on your screen all at once and thus you might lose something if said output is bigger than the number of lines of your terminal. – schaiba Jul 11 '14 at 15:39
  • 1
    You only need to use a pager if the output is longer than the terminal hight. However if the terminal has a scroll back, you may feel that you do not need it, as you can scroll back, but the pager still has the advantage of starting at the top. Scrolling back starts at the bottom. – ctrl-alt-delor Jul 11 '14 at 15:42
  • @Tim, give it a try. Find a command that outputs lots of lines (more than a screen full), such as ls in a directory full of files. Then add | less to end of command. You should see just the first page. Then press space to go to next page. – ctrl-alt-delor Jul 11 '14 at 15:46
  • 4
    Scroll back is also finite. A pager is not limited to any particular size. – Faheem Mitha Jul 11 '14 at 16:08
  • 2
    Most pagers also provide extra features such as pattern searching and position marking. – Kevin Thibedeau Jul 11 '14 at 17:59
  • (1) Another pager that’s available on some versions of Unix is pg. (2) While most (if not all) terminals have a finite scroll-back capacity, some pagers (e.g., more) cannot scroll back at all when the input is from a pipe. (3) An interesting wrinkle is that some pagers (in some environments) write into the terminal’s scroll-back memory, so you can quit the pager and then still scroll back and review (re-see?) its output. Others create a separate viewing environment, so, when you terminate the pager, its output vanishes. … – Scott - Слава Україні Jul 12 '14 at 01:13
  • … (4) Another feature of (many) pagers is that they let you skip over some of the output (either by searching for a string or pattern, or by specifying a number of lines or screen/page-fuls to skip). This is especially useful when the pager’s output is stored in the terminal’s scroll-back memory (i.e., it determines how far back you need to scroll to look at the output from the command(s) before you ran the pager). – Scott - Слава Україні Jul 12 '14 at 01:14
  • pager is must for consoles where scroll buffering is not possible. ie: in grub rescue mode. you can't scroll. – Akhil May 12 '21 at 15:41
3

I would like to confirm the comments of @schaiba and @Faheem Mitha.

@schaiba :

if you don't pipe your output through a pager (less, more and most come to mind), that output will appear on your screen all at once and thus you might lose something if said output is bigger than the number of lines of your terminal.

@Faheem Mitha:

Scroll back is also finite. A pager is not limited to any particular size.


You can try easily by changing the terminal environment variables setttings

First, try man bash (You need a command manpage that's long enough. Google told me man bash is longest one) with default pager. (I don't know which it's the default one but whatever it definitely has one).

Then set PAGER to empty. (Need to export or it won't be written into terminal environment variables)

PAGER=
export PAGER

Again, try man bash. You will find that even if you sroll up, you can't see the beginning of the man bash page.

So now you(I) understand how pagers matter.

Rick
  • 1,157