How to Use the lpr Command to Print Files from the Linux Terminal

Before the widespread adoption of graphical desktop environments and print dialog boxes, printing a document on a UNIX or Linux system meant sending data directly from the command line to a line printer daemon. While most users today simply click “Print” in a GUI application, system administrators and shell script authors still rely heavily on the legacy lpr command to send raw text files, postscript documents, and PDFs directly to the printing queue from the terminal.

Basic Usage: Printing a File

The lpr (Line Printer) command is incredibly simple to use. If you have a default printer already configured in your system (usually managed by CUPS on modern Linux distributions), you only need to provide the name of the file you wish to print.

lpr invoice.pdf

The command will instantly read the file, spool the job to the print daemon, and return you to the command prompt. There is no confirmation message; if the command succeeds silently, the job has been queued.

You can also print multiple files at once by listing them sequentially:

lpr chapter1.txt chapter2.txt chapter3.txt

Printing to a Specific Printer

If you are working in an office environment with multiple printers on the network, the document will go to your system’s default printer unless you specify otherwise. You can route the job to a specific destination using the -P (Printer) flag followed by the exact name of the printer queue.

lpr -P HP_LaserJet_Office invoice.pdf

Tip: If you do not know the names of the available printers on your network, you can run the lpstat -p command to list them.

Printing from Standard Input (Piping)

One of the most powerful features of lpr is its ability to accept standard input via a pipe (|). This allows you to generate data on the fly using other Linux commands and print the output directly without ever saving it to a file.

For example, if you want to print a physical hard copy of all the running processes on the system that are consuming the most memory, you can pipe the output of the top or ps command directly into the printer:

ps aux --sort=-%mem | head -n 20 | lpr

This command pipeline retrieves the process list, sorts it by memory usage, extracts only the top 20 lines using head, and instantly prints those 20 lines to paper.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.