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
- User sends print job
- CUPS processes the job
- Job enters print queue
- Printer receives and processes job
- 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 |
Print Queue Management
Using lpstat
Monitor printer status with lpstat:
lpstat [options]
Common lpstat Options:
Option | Description |
---|---|
-a | Show queue status |
-d | Display default printer |
-p | Show printer status |
-s | Display summary |
Using lpq
Check print queue status:
lpq [options]
Example output:
$ lpq
printer is ready
Rank Owner Job File(s) Total Size
active user 603 memo.txt 1024 bytes
Print Job Control
Using lprm and cancel
Remove print jobs using either command:
lprm [job_id]
cancel [job_id]
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
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.
Q: How can I check my default printer? A: Use the command
lpstat -d
Q: Can I print multiple copies of a file? A: Yes, use
lpr -# number
orlp -n number
Q: How do I print in landscape mode? A: Use
lp -o landscape filename
Q: How can I clear all print jobs? A: Use
cancel -a
orlprm -
to remove all your print jobs
References
- The Common Unix Printing System (CUPS)
- Berkeley Printing System Documentation
- 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! 🚀
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