|

Linux CLI 51🐧 pr, lpr and lp commands

ls /etc | pr -4 -w 70 | head -n 10
ls /etc | pr -4 -w 70 -h "etc directory" | head -n 10

lpstat -a
lpr file1.txt file2.txt
cat file1.txt | lpr -P canon -# 1
lpr -P canon -o media=A4 -o page-ranges=1-5 file1.txt
lp file1.txt
lp -d canon file1.txt

pr, lpr, and lp cover the three stages of printing on Linux: pr formats text for a page, lpr and lp send files to a printer. lpr is the Berkeley-style command; lp is the System V-style command. Both talk to CUPS — the Common UNIX Printing System that almost every Linux distro uses today.

Key point: pr prepares the page. lpr and lp deliver it. Modern Linux uses CUPS under the hood, so both lpr and lp work on the same system — pick whichever style you prefer.


a – pr command for printing

pr is used to prepare files for printing. It paginates, columnates, and adds headers — exactly what you need before sending text to a printer that expects formatted pages.

Common options:

OptionPurpose
-l NSet page length to N lines
-NFormat in N columns
-w NSet page width to N
-o NLeft margin offset of N
-fUse form feeds between pages
-h HEADERUse HEADER instead of the filename
-tOmit headers and footers
-dDouble-space the output
-nNumber lines

Examples:

# Format /etc in 4 columns, 70 characters wide, show top 10
$ ls /etc | pr -4 -w 70 | head -n 10


2024-01-15 10:00                    Page 1


adduser.conf    alternatives    apparmor       apport
apt             bash.bashrc     bash_completion  bindresvport.blacklist
binfmt.d        ca-certificates  calendar      cron.d
cron.daily      cron.hourly     cron.monthly   cryptsetup-initramfs
dbus-1          debconf.conf    debian_version  default
deluser.conf    dhcp            dpkg           e2fsck.conf

# Same, with a custom header
$ ls /etc | pr -4 -w 70 -h "etc directory" | head -n 10


2024-01-15 10:00                etc directory                Page 1


adduser.conf    alternatives    apparmor       apport
apt             bash.bashrc     bash_completion  bindresvport.blacklist
binfmt.d        ca-certificates  calendar      cron.d
cron.daily      cron.hourly     cron.monthly   cryptsetup-initramfs
dbus-1          debconf.conf    debian_version  default
deluser.conf    dhcp            dpkg           e2fsck.conf

# Without headers, ready for a pipeline
$ ls /etc | pr -4 -w 70 -t | head -n 5
adduser.conf    alternatives    apparmor       apport
apt             bash.bashrc     bash_completion  bindresvport.blacklist
binfmt.d        ca-certificates  calendar      cron.d
cron.daily      cron.hourly     cron.monthly   cryptsetup-initramfs
dbus-1          debconf.conf    debian_version  default

# Send directly to the printer
$ ls /etc | pr -4 -w 70 | lpr

Combining pr with lpr:

# Format and print
$ ls /etc | pr -4 -h "etc directory" | lpr -P canon

# Double-spaced document
$ cat report.txt | pr -d | lpr

# Numbered and formatted
$ cat script.sh | pr -n -h "My Script" | lpr

Common pr recipes for printing:

CommandEffect
pr file.txtAdd header + page numbers
pr -h "Title" file.txtCustom header
pr -l 60 file.txt60-line pages
pr -2 file.txt2 columns
pr -d file.txtDouble-space
pr -n file.txtNumber lines
pr -o 5 file.txt5-character left margin

Tip: pr -t removes the headers — useful for pipelines, but when printing you usually want the headers so you know what page you’re on.


b – lpr command – Berkeley Style

lpr sends files to a printer. It’s part of CUPS (Common UNIX Printing System), which is widely used on Linux. The Berkeley style is short and terse — think “line printer.”

Common options:

OptionPurpose
-rDelete files after printing
-P PRINTERSpecify the printer name
-# NPrint N copies
-o OPTIONPass a printing option
-C NAMEJob class/name
-J NAMEJob name
-T TITLEJob title
-mMail when done
-HHold the job

Examples:

# Print multiple files to the default printer
$ lpr file1.txt file2.txt

# Print 5 copies to a specific printer
$ lpr -P canon -# 5 file1.txt

# Pipe content to a printer
$ cat file1.txt | lpr -P canon -# 1

# Use options for media and page ranges
$ lpr -P canon -o media=A4 -o page-ranges=1-5 file1.txt

# Duplex printing
$ lpr -P canon -o sides=two-sided-long-edge file1.txt

# Landscape orientation
$ lpr -P canon -o landscape file1.txt

# Print in grayscale
$ lpr -P canon -o ColorModel=Gray file1.txt

# Print and delete the file
$ lpr -r file1.txt

# Hold the job (print later with lprm)
$ lpr -H file1.txt

# Multiple copies with custom job name
$ lpr -P canon -# 3 -J "Monthly Report" report.pdf

Common -o printing options:

OptionEffect
media=A4A4 paper
media=LetterUS Letter
page-ranges=1-5Pages 1–5
sides=two-sided-long-edgeDuplex (long edge)
sides=two-sided-short-edgeDuplex (short edge)
landscapeLandscape orientation
fit-to-pageScale to fit
number-up=22 pages per sheet
ColorModel=GrayGrayscale
job-priority=50Set priority

Checking printer status:

# List available printers
$ lpstat -a
canon accepting requests since Mon 15 Jan 2024 10:00:00 AM UTC
hp accepting requests since Mon 15 Jan 2024 09:00:00 AM UTC

# Detailed printer info
$ lpstat -p -d
printer canon is idle.  enabled since Mon 15 Jan 2024 10:00:00 AM UTC
printer hp is idle.  enabled since Mon 15 Jan 2024 09:00:00 AM UTC
system default destination: canon

# Show the print queue
$ lpq
canon is ready
no entries

# Cancel a job
$ lprm JOB_ID

c – lp – System V Style

lp is like lpr. Both send files to the printer. lp is also part of CUPS (Common UNIX Printing System). It provides more advanced options than lpr in some cases — and it’s the System V-style command.

Common options:

OptionPurpose
-d PRINTERSelect the printer
-n NNumber of copies
-o landscapeLandscape orientation
-P PAGESSpecify pages (e.g., 2,4,6)
-t TITLEJob title
-mMail when done
-HHold the job

Examples:

# Print to the default printer
$ lp file1.txt
request id is canon-1234 (1 file(s))

# Print to a specific printer
$ lp -d canon file1.txt
request id is canon-1234 (1 file(s))

# Print 3 copies
$ lp -d canon -n 3 file1.txt
request id is canon-1235 (1 file(s))

# Landscape orientation
$ lp -d canon -o landscape file1.txt

# Specific page ranges
$ lp -d canon -P 2,4,6 file1.txt

# Page range with a hyphen
$ lp -d canon -P 1-5 file1.txt

# Print multiple files
$ lp file1.txt file2.txt file3.txt

# Pipe content
$ cat file1.txt | lp -d canon

# Duplex + page range
$ lp -d canon -o sides=two-sided-long-edge -P 1-10 report.pdf

# Job title
$ lp -d canon -t "Monthly Report" report.pdf

# Mail when done
$ lp -d canon -m report.pdf

lp vs lpr:

Aspectlprlp
StyleBerkeleySystem V
Copies-# N-n N
Printer-P name-d name
Pages-o page-ranges=N-M-P N,M or -P N-M
Orientation-o landscape-o landscape
Media-o media=A4-o media=A4
Delete after-r(not standard)
OutputJob ID to stderrJob ID to stdout

lp output tells you the job ID:

$ lp -d canon file1.txt
request id is canon-1234 (1 file(s))

# Use that ID to check or cancel
$ lpq -P canon
canon is ready and printing
Rank    Owner   Job     File(s)                         Total Size
active  kronos  1234    file1.txt                       1024 bytes

$ lprm -P canon 1234
# Cancels the job

Managing print jobs:

CommandPurpose
lpstat -aList accepting printers
lpstat -pPrinter status
lpstat -dShow default printer
lpstat -oShow all jobs
lpqShow queue
lprm JOBCancel a job
cancel JOBCancel (System V style)
lpadminConfigure printers

Complete Example Session

# ============================================
# PART 1: FORMAT WITH PR
# ============================================

# Show /etc in 4 columns, 70 chars wide, top 10 lines
$ ls /etc | pr -4 -w 70 | head -n 10


2024-01-15 10:00                    Page 1


adduser.conf    alternatives    apparmor       apport
apt             bash.bashrc     bash_completion  bindresvport.blacklist
binfmt.d        ca-certificates  calendar      cron.d
cron.daily      cron.hourly     cron.monthly   cryptsetup-initramfs
dbus-1          debconf.conf    debian_version  default
deluser.conf    dhcp            dpkg           e2fsck.conf

# Same with a custom header
$ ls /etc | pr -4 -w 70 -h "etc directory" | head -n 10


2024-01-15 10:00                etc directory                Page 1


adduser.conf    alternatives    apparmor       apport
apt             bash.bashrc     bash_completion  bindresvport.blacklist
...

# ============================================
# PART 2: CHECK PRINTERS
# ============================================

$ lpstat -a
canon accepting requests since Mon 15 Jan 2024 10:00:00 AM UTC
hp accepting requests since Mon 15 Jan 2024 09:00:00 AM UTC

$ lpstat -d
system default destination: canon

$ lpstat -p
printer canon is idle.  enabled since Mon 15 Jan 2024 10:00:00 AM UTC
printer hp is idle.  enabled since Mon 15 Jan 2024 09:00:00 AM UTC

# ============================================
# PART 3: PRINT WITH LPR
# ============================================

# Multiple files
$ lpr file1.txt file2.txt

# Specific printer, 5 copies
$ lpr -P canon -# 5 file1.txt

# Pipe to printer
$ cat file1.txt | lpr -P canon -# 1

# Media and page ranges
$ lpr -P canon -o media=A4 -o page-ranges=1-5 file1.txt

# ============================================
# PART 4: PRINT WITH LP
# ============================================

# Default printer
$ lp file1.txt
request id is canon-1234 (1 file(s))

# Specific printer
$ lp -d canon file1.txt
request id is canon-1235 (1 file(s))

# Multiple copies
$ lp -d canon -n 3 file1.txt
request id is canon-1236 (1 file(s))

# Landscape
$ lp -d canon -o landscape file1.txt

# Page ranges
$ lp -d canon -P 2,4,6 file1.txt

# ============================================
# PART 5: COMBINE PR AND LPR
# ============================================

# Format /etc as 4 columns and print
$ ls /etc | pr -4 -h "etc directory" | lpr -P canon

# Print a numbered script
$ cat script.sh | pr -n -h "Script" | lpr

# Double-spaced document
$ cat report.txt | pr -d | lpr -P canon

# ============================================
# PART 6: CHECK AND CANCEL JOBS
# ============================================

$ lpq
canon is ready
Rank    Owner   Job     File(s)                         Total Size
active  kronos  1234    file1.txt                       1024 bytes
1st     kronos  1235    file2.txt                       2048 bytes

$ lprm 1234
# Cancels job 1234

$ cancel 1235
# Cancels job 1235 (System V style)

# ============================================
# PART 7: PRINT OPTIONS
# ============================================

# Duplex printing
$ lpr -P canon -o sides=two-sided-long-edge file1.txt

# 2 pages per sheet
$ lpr -P canon -o number-up=2 report.pdf

# Grayscale
$ lpr -P canon -o ColorModel=Gray photo.jpg

# Fit to page
$ lpr -P canon -o fit-to-page large-doc.pdf

Quick Reference

pr — Printing Format

OptionPurpose
-NN columns
-l NPage length N
-w NPage width N
-o NLeft margin offset
-h HEADERCustom header
-fForm feeds
-tNo headers
-dDouble-space
-nNumber lines

lpr — Berkeley

OptionPurpose
lpr FILEPrint file
lpr -P PRN FILESpecific printer
lpr -# N FILEN copies
lpr -r FILEDelete after printing
lpr -o OPT FILEPrint option
lpr -m FILEMail when done
lpr -H FILEHold job

lp — System V

OptionPurpose
lp FILEPrint file
lp -d PRN FILESpecific printer
lp -n N FILEN copies
lp -P 2,4,6 FILESpecific pages
lp -P 1-5 FILEPage range
lp -o landscape FILELandscape
lp -t TITLE FILEJob title
lp -m FILEMail when done
lp -H FILEHold job

Common -o Options

OptionEffect
media=A4A4 paper
media=LetterUS Letter
page-ranges=1-5Pages 1–5
sides=two-sided-long-edgeDuplex long edge
sides=two-sided-short-edgeDuplex short edge
landscapeLandscape
fit-to-pageScale to fit
number-up=22 pages per sheet
ColorModel=GrayGrayscale

Printer Management

CommandPurpose
lpstat -aList accepting printers
lpstat -pPrinter status
lpstat -dDefault printer
lpstat -oAll jobs
lpqShow queue
lprm JOBCancel job
cancel JOBCancel (SysV)
lpadminConfigure printers

lpr vs lp

Aspectlprlp
StyleBerkeleySystem V
Copies-# N-n N
Printer-P-d
Pages-o page-ranges-P
Delete after-r
Outputstderrstdout

Best Practices

Do This:

# Check available printers first
lpstat -a                             # ✅

# Use pr to format before printing
ls /etc | pr -4 | lpr                 # ✅

# Specify the printer explicitly
lpr -P canon file.txt                 # ✅

# Use lp for page ranges
lp -d canon -P 1-5 report.pdf         # ✅

# Cancel jobs by ID
lprm 1234                             # ✅

# Use -t with pr when piping
ls /etc | pr -4 -t | grep foo         # ✅

# Preview with head before printing
ls /etc | pr -4 -w 70 | head -n 10    # ✅

# Use -o for media and orientation
lpr -P canon -o media=A4 -o landscape file.txt  # ✅

Don’t Do This:

# Don't print without checking the printer
lpr file.txt                          # ⚠️  default may not exist

# Don't forget -P when multiple printers exist
lpr file.txt                          # ⚠️  goes to default

# Don't pipe to lpr without formatting
cat hugefile.txt | lpr                # ⚠️  unformatted output

# Don't use pr without -t in pipelines
ls | pr -4 | grep foo                 # ❌ headers pollute

# Don't confuse lpr and lp flags
lpr -d canon file.txt                 # ❌ -d is for lp, not lpr
lp -P canon file.txt                  # ❌ -P is for lpr, not lp

# Don't print without checking the queue
lpr big.pdf                           # ⚠️  check lpq first

# Don't forget to cancel stuck jobs
# Use lprm or cancel                   # ✅

Common Pitfalls

PitfallProblemSolution
No default printerlpr failslpstat -d, set default
Wrong flag for toollpr -dUse lpr -P
Wrong copies flaglpr -nUse lpr -#
pr headers in pipePollutes outputUse pr -t
CUPS not runningNothing printssystemctl start cups
Printer offlineJob stucklpstat -p to check
Job stuck in queueWon’t printlprm JOB or cancel JOB
Paper size mismatchCropped output-o media=A4

Real-World Examples

1. Format a Directory Listing and Print

$ ls /etc | pr -4 -h "etc directory" | lpr -P canon

2. Print Multiple Files

$ lpr -P canon file1.txt file2.txt file3.txt

3. Print 5 Copies

$ lpr -P canon -# 5 report.pdf
# or
$ lp -d canon -n 5 report.pdf

4. Print Pages 1–5 Only

$ lpr -P canon -o page-ranges=1-5 report.pdf
# or
$ lp -d canon -P 1-5 report.pdf

5. Print Specific Pages

$ lp -d canon -P 2,4,6 document.pdf

6. Duplex Printing

$ lpr -P canon -o sides=two-sided-long-edge report.pdf

7. Print Landscape

$ lpr -P canon -o landscape spreadsheet.pdf
# or
$ lp -d canon -o landscape spreadsheet.pdf

8. Print on A4

$ lpr -P canon -o media=A4 document.pdf

9. Print a Numbered Script

$ cat script.sh | pr -n -h "Script" | lpr -P canon

10. Double-Space a Document

$ cat essay.txt | pr -d | lpr -P canon

11. Check Printer Status

$ lpstat -a
canon accepting requests since Mon 15 Jan 2024 10:00:00 AM UTC

$ lpstat -p -d
printer canon is idle.  enabled since ...
system default destination: canon

12. Check the Queue

$ lpq
canon is ready
Rank    Owner   Job     File(s)                         Total Size
active  kronos  1234    report.pdf                      45678 bytes

13. Cancel a Job

$ lprm 1234
# or
$ cancel 1234

14. Hold a Job

$ lpr -H -P canon report.pdf
# Job is held — release with lprm -H or cupsenable

15. Print with a Job Title

$ lp -d canon -t "Monthly Report" report.pdf

16. Grayscale Printing

$ lpr -P canon -o ColorModel=Gray photo.jpg

17. 2 Pages Per Sheet

$ lpr -P canon -o number-up=2 document.pdf

18. Fit to Page

$ lpr -P canon -o fit-to-page large-document.pdf

19. Print and Delete Source

$ lpr -r tempfile.txt

20. Pipe Command Output to Printer

$ df -h | pr -h "Disk Usage" | lpr -P canon

Visual: The Printing Pipeline

┌──────────────────────────────────────────────┐
│           The printing pipeline              │
│                                              │
│  Source (file, ls, cat)                      │
│         │                                    │
│         ▼                                    │
│  ┌──────────────────┐                        │
│  │       pr         │  format for page       │
│  │  (columns,       │  (optional)            │
│  │   headers,       │                        │
│  │   page length)   │                        │
│  └────────┬─────────┘                        │
│           │                                  │
│           ▼                                  │
│  ┌──────────────────┐                        │
│  │   lpr or lp      │  send to printer       │
│  │  (printer,       │                        │
│  │   copies,        │                        │
│  │   options)       │                        │
│  └────────┬─────────┘                        │
│           │                                  │
│           ▼                                  │
│  ┌──────────────────┐                        │
│  │      CUPS        │  print system          │
│  │                  │                        │
│  └────────┬─────────┘                        │
│           │                                  │
│           ▼                                  │
│  ┌──────────────────┐                        │
│  │     Printer      │  🖨️                    │
│  └──────────────────┘                        │
│                                              │
└──────────────────────────────────────────────┘

Summary

CommandPurposeExample
pr -4 FILE4 columnspr -4 file.txt
pr -w N FILEWidth Npr -w 70 file.txt
pr -h H FILECustom headerpr -h "Title" file.txt
pr -l N FILEPage lengthpr -l 60 file.txt
pr -t FILENo headerspr -t file.txt
pr -d FILEDouble-spacepr -d file.txt
pr -n FILENumber linespr -n file.txt
lpr FILEPrint filelpr file1.txt
lpr -P PRN FILESpecific printerlpr -P canon file.txt
lpr -# N FILEN copieslpr -# 5 file.txt
lpr -r FILEDelete afterlpr -r file.txt
lpr -o OPT FILEPrint optionlpr -o media=A4 file.txt
lp FILEPrint filelp file1.txt
lp -d PRN FILESpecific printerlp -d canon file.txt
lp -n N FILEN copieslp -n 3 file.txt
lp -P PAGES FILEPageslp -P 2,4,6 file.txt
lp -o landscape FILELandscapelp -o landscape file.txt
lpstat -aList printerslpstat -a
lpstat -dDefault printerlpstat -d
lpqQueuelpq
lprm JOBCancel joblprm 1234
cancel JOBCancel (SysV)cancel 1234

Key takeaways:

  • pr formats text for the page — columns, headers, page length, double-spacing
  • lpr (Berkeley) and lp (System V) both send files to the printer via CUPS
  • lpr -P selects a printer; lp -d does the same
  • lpr -# N sets copies; lp -n N does the same
  • Use -o for media, orientation, duplex, page ranges, and other options
  • lp -P selects specific pages (2,4,6 or 1-5)
  • pr piping into lpr is the classic way to format + print
  • Use pr -t when you want columns but no headers in a pipeline
  • Check printers with lpstat -a, the queue with lpq, and cancel with lprm or cancel
  • Modern Linux uses CUPS — both lpr and lp work, so use whichever style feels natural

Remember: pr prepares, lpr/lp deliver. On modern Linux, CUPS handles the actual printing. Learn lpr -P canon -# 2 for copies and lp -d canon -P 1-5 for page ranges. Pipe through pr when you want columns or page numbers. Check lpstat -a before printing if you’re not sure what’s available. And when a job gets stuck, lprm or cancel is your escape hatch.


Stop using slow, ad-bloated tool sites! 🤮

🔎 Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)

⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free

🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!