Linux pr command

Updated: 06/16/2017 by Computer Hope

About pr

Formats a file to make it look better when printed.


pr paginates or columnates FILE(s) for printing.

The -t option is implied if PAGE_LENGTH is less than or equal to 10.

If no FILE is specified, or when FILE is a dash ("-"), pr reads from standard input instead.

Mandatory arguments to long options are mandatory for short options as well:

pr syntax

pr [OPTION]... [FILE]...


+FIRST_PAGE[:LAST_PAGE], --pages=FIRST_PAGE[:LAST_PAGE] Begin printing at page FIRST_PAGE (and, if specified, stop at LAST_PAGE).
-COLUMN, --columns=COLUMN Output COLUMN columns and print columns down, unless -a is specified (see below); balance the number of lines in the columns on each page.
-a, --across Print columns across rather than down, used together with -COLUMN.
-c, --show-control-chars Use caret notation (^G) and octal backslash notation.
-d, --double-space Double-space the output.
-D, --date-format=FORMAT Use FORMAT for the header date.
-e[CHAR[WIDTH]], --expand-tabs[=CHAR[WIDTH]] Expand input character CHAR (by default, the tab character) to tab width WIDTH (by default, 8) spaces.
-F, -f, --form-feed Use form feeds instead of newlines to separate pages (by a 3-line page header with -F, or a 5-line header and trailer without -F)
-h, --header=HEADER Use a centered HEADER instead of the file name in the page header. -h "" prints a blank line, but make sure to specify a space between -h and "".
-i[CHAR[WIDTH]], --output-tabs[=CHAR[WIDTH]] Replace spaces with the character CHAR (defaults to the tab character) to tab width WIDTH (default 8).
-J, --join-lines Merge full lines. Turns off -W line truncation. No column alignment is performed, and if specified, --sep-string[=STRING] sets separators.
-l, --length=PAGE_LENGTH Set the page length to PAGE_LENGTH (default 66) lines. For text the default is 56, and if -F is specified, the default is 63.
-m, --merge Print all files in parallel, one in each column. Truncate lines, but join lines of full length with -J.
-n[SEP[DIGITS]], --number-lines[=SEP[DIGITS]] Prepend lines with line numbers. Use DIGITS (default 5) digits, then character separator SEP (default is the tab character). By default, counting starts with the first line of the input FILE.
-N, --first-line-number=NUMBER Start counting with NUMBER at the first line of the first page printed (see +FIRST_PAGE).
-o, --indent=MARGIN Offset each line with MARGIN (default 0) spaces. Do not affect -w or -W. MARGIN will be added to PAGE_WIDTH.
-r, --no-file-warnings Do not issue a warning if a FILE cannot be opened.
-s[CHAR], --separator[=CHAR] Separate columns by a single character. Default for CHAR is the tab character without -w and 'no char' with -w. -s[CHAR] turns off line truncation of all 3 column options (-COLUMN|-a -COLUMN|-m), except when -w is set.
-S, --sep-string[=STRING] Separate columns by STRING, without -S. Default separator is the tab character with -J and the Space character otherwise (which is the same as -S" "). There is no effect on column options.
-t, --omit-header Omit page headers and trailers.
-T, --omit-pagination Omit page headers and trailers, eliminate any pagination by form feeds set in input FILEs.
-v, --show-nonprinting Use octal backslash notation.
-w, --width=PAGE_WIDTH Set page width to PAGE_WIDTH (default 72) characters for multiple text-column output only, -s[CHAR] turns this off.
-W, --page-width=PAGE_WIDTH Set page width to PAGE_WIDTH (default 72) characters always. Truncate lines, except when -J option is set. Does not interfere with -S or -s.
--help Display a help message, and exit.
--version Display version information, and exit.

pr examples

ls -a | pr -n -h "Files in $(pwd)" > directory.txt

Fetch a listing of all files in the current directory using the ls command, and pipe the output to pr, which formats the data in a printer-friendly format with a custom header and numbered lines. The formatted pr output is written to the file directory.txt, which can then be printed.

expand — Expand tab characters to a series of spaces.
lp — Print a file on the System V operating system.