pg
View text files, one screenful at a time
TLDR
View a file
Display help
SYNOPSIS
pg [options] [file...]
pg [-n lines] [-cefns] [+line] [+/pattern/] [file ...]
PARAMETERS
-n lines
Specifies the number of lines to display per screen. If omitted, pg calculates this from the terminal's screen size.
-c
Clears the screen before displaying each new page of text.
-e
Prevents pg from pausing at the end of each file when multiple files are specified. It will automatically proceed to the next file.
-f
Prevents pg from splitting (folding) long lines. Instead, lines longer than the screen width will simply be truncated.
-s
Displays messages, such as the : prompt or file information, in standout mode (e.g., reverse video) on compatible terminals.
+line
Starts displaying the file from the specified line number.
+/pattern/
Starts displaying the file from the first line that contains the specified pattern.
DESCRIPTION
pg is a command-line utility used to display text files or command output one screenful (or "page") at a time. It functions as a simple pager, allowing users to read long documents by pausing at the end of each screen. While more basic than modern pagers like less, pg provides essential features such as specifying the number of lines per screen, searching for patterns, and navigating through the file. It was commonly used on Unix-like systems for quick file viewing, especially on older terminals or in environments where more feature-rich pagers might not be available or desired. Users interact with pg via simple single-character commands at a prompt, typically :.
CAVEATS
pg is a more traditional and less feature-rich pager compared to less(1). Its interactive commands are simpler, and it offers limited backward navigation capabilities. On many modern Linux distributions, pg might not be installed by default or is often symlinked to more(1) or less(1). For complex text viewing and advanced features like live log following or extensive search functionalities, less(1) is generally preferred.
INTERACTIVE COMMANDS
When pg pauses, it displays a prompt (by default, :). At this prompt, users can enter various single-character commands to navigate or perform actions:
RETURN: Displays the next page of text.
d or ^D: Scrolls forward by half a screen.
l: Scrolls forward by a single line.
w: Scrolls forward by a full screen (window).
s n: Skips forward n pages.
^: Jumps to the beginning of the file.
$: Jumps to the end of the file.
/pattern/: Searches forward for the specified pattern.
?pattern?: Searches backward for the specified pattern.
n: When viewing multiple files, moves to the next file in the list.
p: When viewing multiple files, moves to the previous file in the list.
!command: Executes the specified command in a subshell.
h: Displays a help message with a list of available commands.
q: Quits pg.
HISTORY
The pg command is one of the older text pagers in the Unix ecosystem, designed for line-oriented terminals. It provided a basic way to view large files without overwhelming the terminal, pausing output one screen at a time. While it was a significant utility in its time, its development and usage have largely been superseded by more advanced pagers like less(1), which offer superior navigation (especially backward scrolling), searching capabilities, and overall interactivity. Despite this, pg remains available in the util-linux package on many Linux systems, serving as a simple, no-frills option or for historical compatibility.