Skip to main content
SysAdmin Shell Scripting Essentials

lpr print Command Syntax, CLI Reference, Troubleshooting

lpr print sends a file to a computer or printer sharing device running the Line printer Daemon (LPD) service in preparation for printing.

lpr -S 10.0.0.45 -P Laserprinter1 -o l PostScript_file.ps

Syntax

lpr [-S <servername>] -P <printername> [-C <bannercontent>] [-J <jobname>] [-o | -o l] [-x] [-d] <filename>
lpr [-P <destination>] [-# <copies>] [-o <option=value>] <filename>

Troubleshooting & Common Errors

Error Message / Behavior Root Cause Resolution Command / Action
lpr: unable to connect to <host> LPD service not running on target, or firewall blocks port 515 On printer/server: verify LPD is enabled. On client: telnet <host> 515 to test port reachability.
lpr: unknown printer queue Queue name case-sensitive or does not exist List queues: on target run lpstat -p (CUPS) or check LPD configuration. Use exact case.
File sent but printer does nothing Missing -o l (Windows) or -o raw (CUPS) for raw data Windows: lpr -S <host> -P <queue> -o l <file>; CUPS: lpr -o raw <file>
lpr: operation failed Generic LPD protocol failure (job too large, unreadable file) Check file permissions and size. Retry with -x on Windows for debug output.
Job goes to wrong printer -P queue name misspelled or default destination overrides Always specify -P explicitly. CUPS: check lpoptions -l for default.
See also  Linux Command Useradd: CLI Command Reference, Syntax, Flags

Key Features of lpr print

Parameter Windows (Microsoft LPR) CUPS (man-lpr)
Server specification -S <hostname/IP> Defined via printer URI in /etc/cups/printers.conf; not a direct flag
Queue name (case-sensitive) -P <printername> -P <destination> (printer queue name)
Banner page content -C <bannertext> N/A (use -o job-sheets=..)
Job name -J <jobname> N/A (set via -t in CUPS but not in core lpr)
Binary mode -o l (letter l) to bypass PostScript -o raw for raw printing
Debug / verbose -x (Windows only, debug mode) N/A
Copies N/A (use lp -n or job ticket) -# <copies>
Job options (media, sides) N/A -o media=A4 -o sides=two-sided-long-edge

The most critical metric is queue naming: LPD queues are case-sensitive on most LPD servers. A mismatch in case will cause lpr: printer queue not found errors. On Windows, the -S flag is mandatory when sending to a remote LPD service; the local server flag must resolve to a running LPD service (e.g., via sc query LPDSVC). CUPS lpr does not need -S because it relies on the configured printer URI in lpinfo.

Advantages and Limitations of lpr print

Advantages

  • Protocol-agnostic: works over TCP/IP with any LPD-compliant printer or server.
  • Lightweight: no dependency on IPP or web services; raw file transfer.
  • Cross-platform: available on Windows (native), Linux (CUPS), macOS (via CUPS), and legacy Unix.
  • Simple syntax: one command to send files with minimal overhead.
  • Supports banner pages and job names on Windows (via -C and -J).
  • Works behind firewalls (port 515 only).

Limitations

  • No encryption: LPR sends data and control files in cleartext over TCP.
  • No job prioritization or authentication built into the base protocol.
  • Queue names are case-sensitive and vary by implementation.
  • No built-in spool monitoring (use lpstat on CUPS or check printer logs).
  • Windows implementation expects an active LPD service (LPDSVC) to be running, which is not installed by default after Windows Server 2012.
  • Limited error feedback: often returns only lpr: operation failed without detailed cause.
See also  nslookup Command Windows - Syntax & Troubleshooting Guide

Veredicto: lpr print is ideal for environments with legacy LPD printers or when a minimal, scriptable printing solution is required. Avoid it if print jobs contain sensitive data or when modern features like IPP Everywhere or secure print release are needed.

Comparison with Alternatives

Metric lpr (Windows LPR) lpr (CUPS) lp (CUPS IPP)
Protocol LPR (RFC 1179) LPR (RFC 1179) IPP (RFC 8011)
Encryption None (plain TCP) None (unless tunneled) Optional via TLS (IPP-S)
Authentication None None Kerberos, LDAP, certificate
Job options Only banner/job name Via -o (media, sides, etc.) Comprehensive set via -o
Copies Not directly -# N -n N
Default destination -P mandatory; no default Uses system default printer Uses system default printer

While the original LPR protocol lacks modern security, both Windows and CUPS lpr implementations can be used in isolated LANs with firewalled port 515. For multi-platform environments, CUPS lpr provides richer job options via -o flags (media, duplex, number-up) that are absent in the Windows LPR client. There is no direct cloud CLI equivalent for lpr because LPR is a local network protocol; cloud print services (e.g., AWS EC2 Print, Azure Universal Print) use IPP or own APIs, not LPR.

Verified References

Every command below was cross-checked against authoritative sources — official Microsoft LPR documentation and CUPS man pages. The following sources were used:

  • Microsoft Windows Server LPR command documentation
  • CUPS man-lpr (cupstestdsc and related)

Frequently Asked Questions

When should I use the `-#` flag with `lpr`?

Answer: When you need multiple identical copies of a print job without manual resubmission.

The `-#` flag is processed by the spooler (CUPS/LPD) and does not require client-side duplication. For duplex or collated copies, use `lp -n` instead. Example:

lpr -# 3 -o sides=two-sided-long-edge invoice.pdf

Generates 3 two-sided copies.

How do I fix `lpr: Error – no default destination`?

Answer: Set a default printer via `lpadmin -d PRINTER` (root) or define `$PRINTER` environment variable in shell profile.

CUPS requires an explicit default. First list available printers:

lpstat -p

Then set default system-wide as root:

lpadmin -d HP_LaserJet

Or per-user:

export PRINTER=HP_LaserJet; echo 'export PRINTER=HP_LaserJet' >> ~/.bashrc

Verify with lpstat -d.

Does `lpr` work on AWS EC2 instances running Amazon Linux 2?

Answer: Yes.

Install CUPS client if missing:

sudo yum install cups-client

For network printers (e.g., IPP), `lpr` works immediately. For USB passthrough, attach device and load drivers:

sudo modprobe usblp

Test with:

echo "test" | lpr

What is the fastest way to print a PDF from a headless Linux server using `lpr`?

Answer: Pipe the PDF directly to `lpr` without intermediate conversion – CUPS uses a filter chain automatically.

Avoid manual PDF-to-PostScript conversion. Use

lpr -P target_printer document.pdf

CUPS auto-detects MIME type and applies `pdftops` filter. For bulk print jobs, combine with `find` and `parallel`:

find . -name '*.pdf' -print0 | parallel -0 lpr -P fast_queue {}

This saturates the print spool while minimizing latency.