Introduction
This tutorial demonstrates how to effectively manage print jobs on a Linux system using the lprm
command. As a systemadmin, understanding how to control the print queue is essential. Here, you'll discover how to remove specific print jobs, or clear the entire queue, using lprm
. We will also cover how to use the lpq
command to inspect the print queue.
This lab provides hands-on experience with: An Introduction to the lprm
Command, Removing a Specific Print Job, and Clearing All Print Jobs. The lprm
command is a core Linux utility, readily available without requiring additional installation, enabling seamless system administration.
Introduction to the lprm Command
This section introduces the lprm
command, a vital tool for any systemadmin to manage print jobs within a Linux environment. With lprm
, you can selectively remove print jobs or completely empty the print queue, providing full control over printing resources.
Let's begin by examining the current state of the print queue using the lpq
command:
sudo lpq
Example output:
Rank Owner Job File(s) Total Size
active labex 1 document.pdf 1234 bytes
1st labex 2 report.txt 4567 bytes
The output reveals two print jobs in the queue, each identified by a unique job ID, in this case, 1 and 2. These IDs are crucial for targeting specific print jobs with the lprm
command.
To remove a particular print job, execute the lprm
command followed by the relevant job ID. For instance, to delete job 1, you would run:
sudo lprm 1
Example output:
job "1" dequeued
This command effectively removes the print job associated with ID 1 from the queue, freeing up resources and preventing unnecessary printing.
Alternatively, to remove all print jobs at once, you can use the lprm -
command. This action requires root privileges and should be used with caution:
sudo lprm -
Example output:
job "2" dequeued
This will clear all pending print jobs from the queue, providing a clean slate for future printing tasks. Note that in this example Job 1 was removed from the previous step.
Removing a Specific Print Job
This part details the process of removing a specific print job from the queue using the lprm
command. Master this technique to efficiently manage print resources and prevent unwanted prints.
Start by verifying the print queue's contents with the lpq
command:
sudo lpq
Example output:
Rank Owner Job File(s) Total Size
active labex 1 document.pdf 1234 bytes
1st labex 2 report.txt 4567 bytes
To specifically remove the print job with ID 2, execute the following command:
sudo lprm 2
Example output:
job "2" dequeued
This command isolates and removes the print job identified as ID 2, without affecting other jobs in the queue.
To confirm the removal, re-check the print queue using lpq
:
sudo lpq
Example output:
Rank Owner Job File(s) Total Size
active labex 1 document.pdf 1234 bytes
The output confirms that the print job with ID 2 has been successfully removed, leaving only the remaining jobs in the queue. This illustrates the precision of the lprm
command.
Removing All Print Jobs
This section demonstrates how to use the lprm
command to completely clear the print queue of all pending print jobs. This is particularly useful for systemadmin tasks such as troubleshooting printing issues or managing shared printing resources.
Begin by examining the current contents of the print queue using the lpq
command:
sudo lpq
Example output:
Rank Owner Job File(s) Total Size
active labex 1 document.pdf 1234 bytes
1st labex 2 report.txt 4567 bytes
To remove all jobs from the print queue, use the following command:
sudo lprm -
Example output:
job "1" dequeued
job "2" dequeued
This action will remove every print job currently waiting in the queue.
Verify the queue is empty by using the lpq
command again:
sudo lpq
Example output:
no entries
The "no entries" output confirms that the print queue is now completely empty, with all previous print jobs removed. The system is now ready for new printing tasks.
Summary
This lab provided a comprehensive guide on using the lprm
command to manage the print queue on a Linux system. Starting with an introduction to lprm
and using lpq
to view the queue, you learned how to remove specific print jobs by their ID and how to clear the entire queue using the lprm -
command. These skills are invaluable for any systemadmin managing printing resources.
Key takeaways from this lab include:
- The
lprm
command is the primary tool for managing print jobs in the queue. - Use
lprm
followed by the job ID to remove a single, specific print job. - The
lprm -
command clears all print jobs from the queue at once.