LinuxCommandLibrary

pg

View text files, one screenful at a time

TLDR

View a file

$ pg [path/to/file]
copy

Display help
$ pg [[-h|--help]]
copy

SYNOPSIS

pg [-c] [-e] [-f] [-i] [-n] [-r] [-s] [-p string] [-number] [+line] [filename...]

PARAMETERS

-c
    Clear screen before displaying next page

-e
    Stop paging and exit at end-of-file

-f
    Do not fold (split) long lines

-i
    Ignore case when searching for patterns

-n
    Precede each line with its line number

-p string
    Use string as the prompt

-r
    Restricted mode: disable shell escapes

-s
    Squeeze multiple adjacent blank lines into one

-number
    Set lines per page to number (default 23)

+line
    Begin displaying at line number line

DESCRIPTION

pg is a classic pager utility designed for viewing text files or output one screen at a time on CRT terminals. It pauses after each page, allowing users to advance with space, scroll back, search, and more.

Unlike cat, which outputs everything continuously, pg prevents overwhelming the screen with long content. It supports piping, e.g., ls -l | pg, and direct file viewing. Key features include customizable page size, prompts, line folding control, and case-insensitive searches.

Interactive commands mimic early pagers: h for help, /pattern to search forward, ?pattern backward, n/N for next/previous match, +/- to scroll by lines, and q to quit. While functional, pg lacks some modern features like vi-style keys found in less.

Primarily from BSD heritage, it's available in some Linux distros via util-linux or separately, but less is the standard replacement today due to superior backward scrolling and pipe handling.

CAVEATS

pg does not support backward scrolling through pipes.
Not installed by default on many modern systems; use less instead.
Behavior varies slightly between BSD and Linux implementations.

COMMON INTERACTIVE COMMANDS

h: help
space: next page
b: previous page
/pattern: search forward
?pattern: search backward
q: quit
=: show current position

EXAMPLE USAGE

pg /etc/passwd: view file interactively.
man gcc | pg -p "GCC> ": page manual with custom prompt.
pg +100 largefile.txt: start at line 100.

HISTORY

Developed in early 1980s for 4.1BSD UNIX as a full-screen pager for CRTs. Preceded more enhancements; integrated into System V. Maintained in util-linux for Linux compatibility but largely obsoleted by less (1984+), which added regex search and better pipe support.

SEE ALSO

less(1), more(1), most(1)

Copied to clipboard