lpr
Print files to a printer
TLDR
Print a file to the default printer
Print 2 copies
Print to a named printer
Print either a single page (e.g. 2) or a range of pages (e.g. 2-16)
Print double-sided either in portrait (long) or in landscape (short)
Set page size (more options may be available depending on setup)
Print multiple pages per sheet
SYNOPSIS
lpr [OPTIONS] [FILE...]
lpr [-P destination] [-# num-copies] [-J job-name] [-o option=value] [file...]
PARAMETERS
-P destination
Specifies the printer or class to send the job to. If not specified, the default printer is used.
-# num-copies
Prints the specified number of copies of each file.
-h
Does not print the standard banner page or header for the job.
-J job-name
Sets the job name, which may be displayed in the print queue.
-o option=value
Passes a specific option to the printer backend. Common options include media=size, orientation=landscape, sides=two-sided-long-edge, fit-to-page, etc.
-r
Deletes the input file(s) after successfully spooling the print job. Use with caution.
-l
Prints the file literally, without any filtering or formatting. This is useful for printing files that are already formatted for a specific printer, such as PostScript files.
-s
Creates a symbolic link to the print file instead of copying it to the spool directory. This means the original file must remain accessible and unchanged until the job is printed. (Note: CUPS lpr
always copies files by default, so -s
may have specific behavior or be ignored depending on implementation).
--help
Displays a brief usage message and exits.
--version
Displays the CUPS version information and exits.
DESCRIPTION
lpr
is a command-line utility used to submit print jobs to a printer or print queue. Historically, it originated from the Berkeley Software Distribution (BSD) Unix printing system, where lpr
stood for "line printer remote." On modern Linux systems, lpr
is typically provided by the Common Unix Printing System (CUPS) and serves as a compatibility layer or wrapper for CUPS's internal printing mechanisms. When you use lpr
, the specified file(s) (or standard input) are sent to the CUPS spooler, which then processes them according to the printer's configuration (e.g., converting formats like PDF, PostScript, images, or plain text) and sends them to the designated printer. It offers various options to control job attributes like destination printer, number of copies, job title, and printing options.
CAVEATS
Modern lpr
on Linux systems relies heavily on the CUPS daemon (cupsd
) being active and correctly configured. If CUPS is not running or printers are not set up, lpr
will fail.
The behavior of lpr
(especially regarding options like -s
or -h
) can differ significantly between the older BSD lpr
implementation and the current CUPS lpr
. This analysis focuses on the CUPS version.
By default, lpr
copies the input file(s) to a spool directory. This ensures the file is available even if the original is deleted or modified before printing. The -s
option can override this, but requires the original file to persist.
DEFAULT PRINTER SELECTION
The default printer lpr
uses can be determined by several factors, in order: the LPDEST
environment variable, the PRINTER
environment variable, or the system-wide default printer configured in CUPS (usually through /etc/cups/printers.conf
).
PRINTER DISCOVERY
You can list available printers configured on your system using commands like lpstat -p -d
or lpstat -a
.
RAW VS. FILTERED PRINTING
By default, lpr
(via CUPS) attempts to filter input files (e.g., converting PDF to PostScript or a printer-specific language). The -l (literal) option can be used to send files directly to the printer without filtering, which is useful for files already in the printer's native language or for troubleshooting.
HISTORY
The lpr
command originated as part of the Berkeley Software Distribution (BSD) Unix printing system in the 1980s, designed to interface with line printers. Its name, "line printer remote," reflects its initial purpose of sending jobs to printers across a network. With the rise of Linux, many systems initially adopted similar BSD-style printing systems. However, the Common Unix Printing System (CUPS) emerged in the late 1990s as a more robust, modern, and cross-platform printing solution. CUPS rapidly became the de facto standard for Unix-like operating systems, including Linux. Consequently, the lpr
command on most contemporary Linux distributions is now a part of the CUPS suite, often being a symbolic link or a wrapper that calls the CUPS lp
command internally, maintaining backward compatibility with older scripts and user habits while leveraging CUPS's advanced features and printer support.