lpr Command Examples in Linux

The lpr command submits files for printing. Files supplied at the command-line are sent to the specified printer or to the print queue if the printer is busy. Without specifying the printer to use, the command will send the print job to the default printer, which you can configure with CUPS. The lpr command reads the print file from standard input if no files are supplied at the command-line.

Syntax

The syntax of the lpr command is:

# lpr [options] [file names]

lpr Command Options

The lpr command options are described in the following table.

Option Description
-E Force encryption when connecting to the server.
-P {destination} Send the print job to the destination printer specified.
-# {copies} Set the number of copies to print from 1 to 100.
-T {name} Set the job name.
-l Specify that the print file is already formatted and should be sent to the destination without being filtered.
-o {option} Set a job option, like printing in landscape mode, scaling the printed output, printing double-sided, etc. Job options vary depending on the printer.
-p Print the specified files with a shaded header that includes the date, time, job name, and page number.
-r Specify that the printed files should be deleted after printing.

lpr Command Examples

1. Print a file to the default printer:

# lpr path/to/file

2. Print 2 copies:

# lpr -# 2 path/to/file

3. Print to a named printer:

# lpr -P printer path/to/file

4. Print either a single page (e.g. 2) or a range of pages (e.g. 2–16):

# lpr -o page-ranges=2|2-16 path/to/file

5. Print double-sided either in portrait (long) or in landscape (short):

# lpr -o sides=two-sided-long-edge|two-sided-short-edge path/to/file

6. Set page size (more options may be available depending on setup):

# lpr -o media=a4|letter|legal path/to/file

7. Print multiple pages per sheet:

# lpr -o number-up=2|4|6|9|16 path/to/file

8. Print a manpage by piping to lpr’s standard input:

# man -t 5 printcap | lpr
Related Post