A Quick Guide to CUPS and lpr

Printer

For many Linux users, the printer remains a mysterious box that only communicates through cryptic GUI menus. But if you're a power user or a terminal enthusiast, you know that the command line offers far more precision.

By leveraging CUPS (Common Unix Printing System), you can manage your print jobs with simple, scriptable commands. Here is everything you need to know about configuring and using your printer from the terminal.

CUPS

1. Finding Your Hardware

Before you can print, you need to know what your system calls your printer. CUPS doesn't always use the friendly name on the sticker.

  • List all printers: lpstat -p
  • Check the current default: lpstat -d
  • See a full status report: lpstat -s

2. Setting Your Default Printer

Tired of typing -P printer_name every time? You can set a default for your specific user account. This creates a preference file in your home directory (~/.cups/lpoptions), so you don't need root/sudo access.

To set your default: lpoptions -d Your_Printer_Name

Now, whenever you type lpr, it automatically sends the file to that device.


3. Will it Print or Just Gibberish?

A common fear when using lpr is that the printer will spit out hundreds of pages of raw postscript code or "garbage" text.

The Good News: CUPS uses a sophisticated filtering system. When you send a PDF, CUPS detects the file type and converts it into the printer's native language (PCL or PostScript) automatically.

What works natively:

  • PDFs: Print perfectly with all formatting intact.
  • Text Files (.txt): Printed with standard margins and monospaced fonts.
  • Images (.jpg, .png): Printed to fit the page.

What requires a GUI:

  • Office Documents (.docx, .xlsx, .odt): The lpr command cannot "render" these layouts. You must export these files to PDF first, then use the command line.

4. Customizing Your Layout

You don't need a print dialog box to change your settings. You can bake your preferences into your user profile using the -o (option) flag with lpoptions.

Common Configuration Commands:
  • Double-Sided (Portrait):
    lpoptions -p Name -o sides=two-sided-long-edge
  • Landscape Mode:
    lpoptions -p Name -o orientation-requested=4
  • Single-Sided:
    lpoptions -p Name -o sides=one-sided

Quick Tip: To see a full list of "secret" options supported by your specific printer driver, run:
lpoptions -p Your_Printer_Name -l


5. The "One-Off" Override

Sometimes you want to break your own rules. If your default is set to double-sided, but you need a single-sided print right now, you can override your settings directly in the lpr command:

lpr -o sides=one-sided -o orientation-requested=4 document.pdf


Summary

The Linux terminal isn't just for code and system administration; it's a highly efficient way to manage your physical hardware. Once you've set your defaults with lpoptions, printing a PDF becomes as fast as typing a single command.

Happy Printing!