lpr Command Examples

lpr is a command-line tool used in the CUPS (Common Unix Printing System) environment for printing files from the terminal. It provides users with a simple and efficient way to send print jobs to printers connected to the system or accessible over the network. lpr serves as a fundamental component of the printing workflow in Unix-like operating systems, offering users a convenient interface for initiating print tasks directly from the command line.

Key features and functionalities of lpr include:

  • File Printing: lpr allows users to print one or more files by specifying their filenames or paths as command-line arguments. Users can initiate printing of text files, documents, images, PDFs, and other printable file formats directly from the terminal without the need for graphical user interfaces or printing dialogs.
  • Print Options: lpr supports various options for customizing print jobs, including specifying the printer destination, print options, and print settings. Users can specify options such as the number of copies, paper size, page orientation, print quality, color mode, and print job priority to tailor the print output to their preferences.
  • Printer Selection: Users can specify the target printer for the print job by its name, queue identifier, or network address. lpr allows users to select the desired printer from the available list of printers configured on the system, making it easy to route print jobs to the appropriate printer based on location, printer capabilities, or user preferences.
  • Print Job Management: lpr manages the submission of print jobs to the CUPS print server, which then processes and schedules the print jobs for printing. Users can monitor the status of print jobs, view print queues, and cancel or prioritize specific print jobs using other CUPS command-line utilities such as lpstat and lpadmin.
  • Print Queue Interaction: lpr interacts with the print queues managed by CUPS, allowing users to submit print jobs to specific queues and manage print job scheduling and processing. Users can view the status of print queues, monitor printer availability, and troubleshoot printing issues using lpr in conjunction with other CUPS tools.
  • Integration with CUPS: lpr seamlessly integrates with the CUPS printing system, leveraging its capabilities for print job processing, printer management, and print queue administration. It leverages the features and functionalities provided by CUPS to ensure reliable and efficient printing operations in Unix-like environments.
  • Cross-Platform Compatibility: lpr is compatible with various Unix-like operating systems, including Linux, macOS, and BSD distributions, that support the CUPS printing system. It provides consistent printing capabilities across different platforms, allowing users to initiate print tasks from the command line regardless of their preferred operating system.

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]

Summary

In summary, lpr is a versatile and essential command-line tool for printing files in Unix-like environments using the CUPS printing system. With its support for file printing, print options, printer selection, print job management, print queue interaction, integration with CUPS, and cross-platform compatibility, lpr provides users with a reliable and efficient solution for initiating and managing print tasks directly from the terminal.

Related Post