Complete Guide to Linux Printing Commands: From Basic to Advanced

Master Linux printing commands: Learn how to print, format, and manage print jobs using pr, lpr, a2ps, lpstat, lpq, and lprm. Perfect for Linux beginners!
code
linux
Author

Steven P. Sanderson II, MPH

Published

January 31, 2025

Keywords

Programming

Author’s Note: As I continue my journey learning Linux, I’m excited to share these printing commands with fellow beginners. We’ll explore these tools together, making the learning process more engaging and relatable.

Introduction

Printing in Linux might seem daunting at first, but with the right commands, you can master everything from basic printing to advanced print job management. This comprehensive guide will walk you through the essential printing commands in Linux, including pr, lpr, a2ps, lpstat, lpq, and lprm.

Understanding the Linux Printing System

CUPS: The Foundation

The Common Unix Printing System (CUPS) forms the backbone of printing in Linux. It handles:

  • Print driver management
  • Print job scheduling
  • Queue management
  • File format conversion

Basic Printing Workflow

  1. User sends print job
  2. CUPS processes the job
  3. Job enters print queue
  4. Printer receives and processes job
  5. Physical printing occurs

Essential Print Commands

The lpr Command (Berkeley Style)

lpr [options] [file]

Common lpr Options:

Option Description
-# number Set number of copies
-p Print with headers (pretty print)
-P printer Specify printer name
-r Delete files after printing

The lp Command (System V Style)

lp [options] [file]

Common lp Options:

Option Description
-d printer Set destination printer
-n number Set number of copies
-o landscape Set landscape orientation
-o fitplot Scale to fit page

Formatting Print Output

The pr Command

The pr command helps format text files for printing, offering various layout options.

pr [options] [file]

Key pr Options:

Option Description
+first[:last] Print specific page range
-columns Organize in columns
-d Double-space output
-h “header” Custom header text
-n Number lines

The a2ps Command

a2ps (“Anything to PostScript”) is a versatile formatting tool that enhances output appearance.

a2ps [options] [file]

Important a2ps Options:

Option Description
–columns number Set column count
-B Remove page headers
-r Landscape orientation
-M name Specify media type

Your Turn!

Let’s try some basic printing commands:

Create a text file:

echo "Hello, Linux Printing!" > test.txt

Format and print it:

Click here for Solution!
pr -h "My First Linux Print" test.txt | lpr

Check the print queue:

lpq 123

Quick Takeaways

  • Use lpr or lp for basic printing
  • Format output with pr or a2ps
  • Monitor queues with lpq and lpstat
  • Cancel jobs with lprm or cancel
  • CUPS manages the entire printing system

FAQs

  1. Q: What’s the difference between lpr and lp? A: They’re similar commands from different Unix traditions (Berkeley vs. System V), with slightly different option syntax.

  2. Q: How can I check my default printer? A: Use the command lpstat -d

  3. Q: Can I print multiple copies of a file? A: Yes, use lpr -# number or lp -n number

  4. Q: How do I print in landscape mode? A: Use lp -o landscape filename

  5. Q: How can I clear all print jobs? A: Use cancel -a or lprm - to remove all your print jobs

References

  1. The Common Unix Printing System (CUPS)
  2. Berkeley Printing System Documentation
  3. System V Printing System

Found this guide helpful? Share it with fellow Linux users and let me know your thoughts in the comments below!

Would you like me to proceed with creating custom image prompts for the article?


Happy Coding! 🚀

Printing in Linux

You can connect with me at any one of the below:

Telegram Channel here: https://t.me/steveondata

LinkedIn Network here: https://www.linkedin.com/in/spsanderson/

Mastadon Social here: https://mstdn.social/@stevensanderson

RStats Network here: https://rstats.me/@spsanderson

GitHub Network here: https://github.com/spsanderson

Bluesky Network here: https://bsky.app/profile/spsanderson.com

My Book: Extending Excel with Python and R here: https://packt.link/oTyZJ