pr
Format files for printing
TLDR
Print multiple files with a default header and footer
Print with a custom centered header
Print with numbered lines and a custom date format
Print all files together, one in each column, without a header or footer
Print, beginning at page 2 up to page 5, with a given page length (including header and footer)
Print with an offset for each line and a truncating custom page width
SYNOPSIS
pr [OPTION]... [FILE]...
Common options:
pr [-a] [-c N] [-d] [-h HEADER] [-l PAGESIZE] [-m] [-n] [-o OFFSET] [-s[CHAR]] [-t] [-w WIDTH] [+FIRST_PAGE[:LAST_PAGE]] [FILE]...
PARAMETERS
+FIRST_PAGE[:LAST_PAGE]
Start printing output on FIRST_PAGE and optionally stop after LAST_PAGE.
-N
Format the output into N columns. Default is 1.
-a
Print columns across the page, then down (multi-column output).
-d
Double-space the output.
-e[CHAR][GAP]
Expand input tabs (or CHAR) to spaces. GAP specifies tab width (default 8).
-F, --form-feed
Separate pages with form feeds (instead of newlines).
-h HEADER
Use HEADER as the page header instead of the filename and date/time.
-i[CHAR][GAP]
Replace spaces with tabs (or CHAR) on output. GAP specifies tab width (default 8).
-l PAGESIZE
Set the page length to PAGESIZE lines (default 66).
-m
Print all specified files in parallel, one file per column.
-n[CHAR][WIDTH]
Number lines, using CHAR (default TAB) to separate the number from the line, and setting the number's WIDTH (default 5).
-o OFFSET
Indent each line by OFFSET spaces.
-p
Pause before each page and prompt for RETURN (interactive paging).
-s[CHAR]
Separate columns by a single character CHAR (default TAB).
-t
Omit page headers and footers (no top/bottom margins).
-w WIDTH
Set the page width to WIDTH characters (default 72 for multi-column, 132 for single).
DESCRIPTION
The pr command is a fundamental Unix/Linux utility designed to format and paginate text files, preparing them for printing. Its primary function is to transform raw text into a more readable layout by adding headers, page numbers, and optionally dividing content into multiple columns. The default output includes the filename, last modification date, time, and page number in a header, along with a footer of blank lines.
Users have extensive control over the output format, including specifying the number of columns (single or multi-column layouts), setting page length and width, enabling line numbering, and defining custom page headers. It can also merge multiple files into parallel columns, which is useful for side-by-side comparison or consolidated reports. While physical printing is less common today, pr remains valuable for command-line text processing, creating formatted output for viewing in a terminal, or piping to other tools.
CAVEATS
The pr command is primarily designed for plain text files and assumes fixed-width character output, typical of historical line printers or terminal displays. It is not suitable for formatting binary files or producing rich text/PDF output directly. For complex document formatting or graphical output, modern tools like word processors, desktop publishing software, or PDF generation utilities are more appropriate. While still useful for command-line text manipulation, its direct relevance to physical printing has diminished with the rise of GUI-based printing systems.
STANDARD INPUT/OUTPUT
When no FILE arguments are provided, or when a FILE is specified as a single hyphen (-), pr reads its input from standard input. The formatted output is always written to standard output, making it highly suitable for use in command-line pipelines with other utilities like lp or lpr.
PAGING VS. COLUMNATING
pr distinguishes between paging (breaking output into discrete pages with headers) and columnating (arranging text into multiple vertical columns). By default, it paginates a single column. Options like -N (for N columns) and -m (for merging files into columns) enable its columnating capabilities.
HISTORY
The pr command is one of the earliest and most enduring utilities in the Unix ecosystem, dating back to the original AT&T Unix releases. Its design reflects the computing environment of the time, where physical printers were the primary means of output and command-line text processing was standard. It was standardized by POSIX.1, ensuring its consistent behavior across various Unix-like operating systems. The GNU Core Utilities project provides the widely used implementation found in most Linux distributions.
While its original purpose of preparing files for dot-matrix or line printers has evolved, pr remains a valuable tool for quick text formatting, especially when piping output to other command-line tools or for simple readability enhancements in a terminal.