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:
| Option | Purpose |
|---|---|
-l N | Set page length to N lines |
-N | Format in N columns |
-w N | Set page width to N |
-o N | Left margin offset of N |
-f | Use form feeds between pages |
-h HEADER | Use HEADER instead of the filename |
-t | Omit headers and footers |
-d | Double-space the output |
-n | Number 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:
| Command | Effect |
|---|---|
pr file.txt | Add header + page numbers |
pr -h "Title" file.txt | Custom header |
pr -l 60 file.txt | 60-line pages |
pr -2 file.txt | 2 columns |
pr -d file.txt | Double-space |
pr -n file.txt | Number lines |
pr -o 5 file.txt | 5-character left margin |
Tip:
pr -tremoves 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:
| Option | Purpose |
|---|---|
-r | Delete files after printing |
-P PRINTER | Specify the printer name |
-# N | Print N copies |
-o OPTION | Pass a printing option |
-C NAME | Job class/name |
-J NAME | Job name |
-T TITLE | Job title |
-m | Mail when done |
-H | Hold 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:
| Option | Effect |
|---|---|
media=A4 | A4 paper |
media=Letter | US Letter |
page-ranges=1-5 | Pages 1–5 |
sides=two-sided-long-edge | Duplex (long edge) |
sides=two-sided-short-edge | Duplex (short edge) |
landscape | Landscape orientation |
fit-to-page | Scale to fit |
number-up=2 | 2 pages per sheet |
ColorModel=Gray | Grayscale |
job-priority=50 | Set 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:
| Option | Purpose |
|---|---|
-d PRINTER | Select the printer |
-n N | Number of copies |
-o landscape | Landscape orientation |
-P PAGES | Specify pages (e.g., 2,4,6) |
-t TITLE | Job title |
-m | Mail when done |
-H | Hold 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:
| Aspect | lpr | lp |
|---|---|---|
| Style | Berkeley | System 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) |
| Output | Job ID to stderr | Job 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:
| Command | Purpose |
|---|---|
lpstat -a | List accepting printers |
lpstat -p | Printer status |
lpstat -d | Show default printer |
lpstat -o | Show all jobs |
lpq | Show queue |
lprm JOB | Cancel a job |
cancel JOB | Cancel (System V style) |
lpadmin | Configure 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
| Option | Purpose |
|---|---|
-N | N columns |
-l N | Page length N |
-w N | Page width N |
-o N | Left margin offset |
-h HEADER | Custom header |
-f | Form feeds |
-t | No headers |
-d | Double-space |
-n | Number lines |
lpr — Berkeley
| Option | Purpose |
|---|---|
lpr FILE | Print file |
lpr -P PRN FILE | Specific printer |
lpr -# N FILE | N copies |
lpr -r FILE | Delete after printing |
lpr -o OPT FILE | Print option |
lpr -m FILE | Mail when done |
lpr -H FILE | Hold job |
lp — System V
| Option | Purpose |
|---|---|
lp FILE | Print file |
lp -d PRN FILE | Specific printer |
lp -n N FILE | N copies |
lp -P 2,4,6 FILE | Specific pages |
lp -P 1-5 FILE | Page range |
lp -o landscape FILE | Landscape |
lp -t TITLE FILE | Job title |
lp -m FILE | Mail when done |
lp -H FILE | Hold job |
Common -o Options
| Option | Effect |
|---|---|
media=A4 | A4 paper |
media=Letter | US Letter |
page-ranges=1-5 | Pages 1–5 |
sides=two-sided-long-edge | Duplex long edge |
sides=two-sided-short-edge | Duplex short edge |
landscape | Landscape |
fit-to-page | Scale to fit |
number-up=2 | 2 pages per sheet |
ColorModel=Gray | Grayscale |
Printer Management
| Command | Purpose |
|---|---|
lpstat -a | List accepting printers |
lpstat -p | Printer status |
lpstat -d | Default printer |
lpstat -o | All jobs |
lpq | Show queue |
lprm JOB | Cancel job |
cancel JOB | Cancel (SysV) |
lpadmin | Configure printers |
lpr vs lp
| Aspect | lpr | lp |
|---|---|---|
| Style | Berkeley | System V |
| Copies | -# N | -n N |
| Printer | -P | -d |
| Pages | -o page-ranges | -P |
| Delete after | -r | — |
| Output | stderr | stdout |
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
| Pitfall | Problem | Solution |
|---|---|---|
| No default printer | lpr fails | lpstat -d, set default |
| Wrong flag for tool | lpr -d | Use lpr -P |
| Wrong copies flag | lpr -n | Use lpr -# |
pr headers in pipe | Pollutes output | Use pr -t |
| CUPS not running | Nothing prints | systemctl start cups |
| Printer offline | Job stuck | lpstat -p to check |
| Job stuck in queue | Won’t print | lprm JOB or cancel JOB |
| Paper size mismatch | Cropped 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
| Command | Purpose | Example |
|---|---|---|
pr -4 FILE | 4 columns | pr -4 file.txt |
pr -w N FILE | Width N | pr -w 70 file.txt |
pr -h H FILE | Custom header | pr -h "Title" file.txt |
pr -l N FILE | Page length | pr -l 60 file.txt |
pr -t FILE | No headers | pr -t file.txt |
pr -d FILE | Double-space | pr -d file.txt |
pr -n FILE | Number lines | pr -n file.txt |
lpr FILE | Print file | lpr file1.txt |
lpr -P PRN FILE | Specific printer | lpr -P canon file.txt |
lpr -# N FILE | N copies | lpr -# 5 file.txt |
lpr -r FILE | Delete after | lpr -r file.txt |
lpr -o OPT FILE | Print option | lpr -o media=A4 file.txt |
lp FILE | Print file | lp file1.txt |
lp -d PRN FILE | Specific printer | lp -d canon file.txt |
lp -n N FILE | N copies | lp -n 3 file.txt |
lp -P PAGES FILE | Pages | lp -P 2,4,6 file.txt |
lp -o landscape FILE | Landscape | lp -o landscape file.txt |
lpstat -a | List printers | lpstat -a |
lpstat -d | Default printer | lpstat -d |
lpq | Queue | lpq |
lprm JOB | Cancel job | lprm 1234 |
cancel JOB | Cancel (SysV) | cancel 1234 |
Key takeaways:
prformats text for the page — columns, headers, page length, double-spacinglpr(Berkeley) andlp(System V) both send files to the printer via CUPSlpr -Pselects a printer;lp -ddoes the samelpr -# Nsets copies;lp -n Ndoes the same- Use
-ofor media, orientation, duplex, page ranges, and other options lp -Pselects specific pages (2,4,6or1-5)prpiping intolpris the classic way to format + print- Use
pr -twhen you want columns but no headers in a pipeline - Check printers with
lpstat -a, the queue withlpq, and cancel withlprmorcancel - Modern Linux uses CUPS — both
lprandlpwork, 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!