On Unix-like operating systems, the pg command displays the contents of text files, one page at a time.

This page covers the Linux version of pg.

Description

pg displays a text file, pausing after each “page” (the height of the terminal screen). After each page, a prompt is displayed. The user may then either press the newline key to view the next page or one of the keys described below.

  • Description
  • Syntax
  • Environment variables
  • Examples
  • Related commands
  • Linux commands help

If no file name is given on the command line, pg reads from standard input. If standard output is not a terminal, pg acts like cat but precedes each file with its name if there is more than one.

If input comes from a pipe, pg stores the data in a buffer file while reading to make navigation possible.

Syntax

pg [-number] [-p string] [-cefnrs] [+line] [+/pattern/] [file…]

Options

Commands

The following commands may be entered at the prompt. Commands preceded by i accept a number as argument, positive or negative. If this argument starts with + or -, it is interpreted relative to the current position in the input file, otherwise relative to the beginning.

The search commands accept an added letter. If t is given, the line containing the pattern is displayed at the top of the screen, which is the default. m selects the middle and b the bottom of the screen. The selected position is used in following searches, too.

If the user presses the interrupt or quit key while pg reads from the input file or writes on the terminal, pg will immediately display the prompt. In all other situations these keys will terminate pg.

Environment variables

The following environment variables affect the behaviour of pg:

Examples

pg myfile.txt

Displays the first screenful of the contents of text file myfile.txt, and a prompt (":"). Pressing the Return key displays the next page, or any of the command listed above may be entered to otherwise navigate the file.

cat — Output the contents of a file.more — Display text one screen at a time.