This lesson we’re going to talk about How you can manage CUPS printers from the command line.
Now as you know you can use the CUPS web-based administration utility to manage the CUPS service running on a Linux system.
However, you can also use a variety of different command-line tools to manage CUPS as well.
In this lesson we’re going to review what these command-line tools are.
So, let’s begin by discussing How you can send a print job to a CUPS printer directly from the command line.
You can send a print job to a CUPS printer using the
lp command at the command line.
Send a print job to a CUPS printer
lp command can send a particular file to your CUPS printer, the syntax is doing this as shown here.
lp [options] [printer_name] [filename]
lp -d followed by the printer that you want to send the print job to and then the name of the file that you want to print.
An example is shown here where we send a file named
projectschedule.txt to a printer named HPLJ5 using the
# lp -d HPLJ5 projectschedule.txt request id is HPLJ5-2 (1 file(s))
Now notice that when we do this the print job is created and it’s assigned an ID number, in this case it’s
The print job is added to the print queue and then sent directly to the printer.
lp utility can use some other options besides the
Set the number of copies to Print
We can also use the
-n option with the command to specify how many copies of the print job we want to print.
I want to Print 5 copies for which I can run the following command.
# lp -n 5 projectschedule.txt
Send an email when the job is completed
We can use the
-m option to specify that
lp send a confirmation email message to the user that sent the print job when the print job is finished printing.
# lp -m projectschedule.txt
Set the print job priority
You can use the
-q option followed by number to set the priority of the print job.
For example, I want to give first priority to this print for which I have to run the following command.
# lp -q 1 projectschedule.txt
Print in Landscape format instead of Portrait
You can use the
-o landscape option to specify that the file be printed in Landscape format instead of Portrait format.
# lp -o landscape projectschedule.txt
Print on both sides of the paper
And if your printer supports duplex printing you can use the
-o sides=2 option to specify that we print on both sides of the paper.
# lp -o sides=2 projectschedule.txt
In addition to the
lp command you can also use another utility called
lpstat at the command line.
lpstat utility is used to display CUPS printer information and probably one of the most useful options you can use the
This will cause
lpstat to display all information about all cups printers on the system.
The example shown here, I ran
lpstat and we see that I have just one printer configured on the system his name is HPLJ5.
# lpstat -t scheduler is running no system default destination device for HPLJ5: parallel: /dev/lp0 HPLJ5 accepting requests since Thu 20 2021 03:55:13 AM MDT printer HPLJ5 is idle. enabled since Thu 20 2021 03:55:13 AM MDT Printer is now online
And you can see that it’s connected with a Parallel Port connection, we can also see how long it’s been up it tells us it’s been accepting requests since
Thu 20 2021 03:55:13 AM IST.
We also see what its status is, we see that it’s currently idle meaning that it’s not actually processing any print jobs and we also see that it is online and waiting it’s available to take print jobs.
In addition, if this printer were not idle but we were actively processing print jobs, A list of all the pending print jobs in the queue would also be listed in the output of the
Now if you have a print job pending that print job is in the print queue and you realize that you do not want that job to actually print you can use the
cancel command to kill that print job.
Now in order to do this you first have to have the print jobs job ID number and you could use the
lpstat command to find out what that job ID number is.
Once you know it you just enter
cancel and in this case, we’re cancelling the HPLJ5-4 print job.
# cancel HPLJ5-4
When I do it kills the job, it stops it from printing and removes the the print job file from the print queue.
Now if I have more than one CUPS printer defined then I can use the
lpoptions command to specify which printer is going to be the default printer for my system.
lpoptions [options] [printer]
And this is done using the
-d option followed by the name of the printer that you want to be the default printer.
Set default Printer in Linux
For example, if I want to set the HPLJ5 printer as my default printer I would enter the following command.
# lpoptions -d HPLJ5
This will set the default printer for all users on the same system.
Now be aware that individual users can override this default printer setting however to do this they create a hidden file in their home directory named
Remember that the dot(
.) at the beginning of file name indicates that this is a hidden file and then within that file they add directive
default SPACE(Press Space Bar on Keyboard) and then the name of the printer that they want to be their default printer.
Here is an example.
# vi .lpoptions default HPLJ2
For example, let’s say I had two printers connected to the system one is HPLJ5 and the others HPLJ2.
By creating this file in my home directory and putting this text in there then my default printer will always be HPLJ2 no matter what the system administrator entered with the
View your printers configuration settings
In addition, you can also use the
lpoptions command to view your printers configuration settings.
To do this you use the
-l option with the
# lpoptions -l HPLJ2
How to enable or disable the print queue
Now in addition to the
lpoptions command there are other commands that you can use to either enable or disable a printers print queue.
You can use the
cupsaccept command to enable a print queue and you can use the
cupsreject command to disable a print queue.
- Enable a printer’s queue:
- Disable a printer’s queue:
Disable the print queue
In this example, I use the
cupsreject HPLJ5 command to disable the HPLJ5 printers print queue.
# cupsreject HPLJ5
If we look at the output of the
lpstat command beneath it we see that HPLJ5 is not accepting request and tells us when basically the
cupsreject command was run it tells us that it’s rejecting jobs.
# lpstat -t scheduler is running system default destination: HPLJ5 device for HPLJ5: parallel: /dev/lp0 HPLJ5 not accepting requests since Thu 20 2021 03:55:13 AM IST - Rejecting Jobs printer HPLJ5 is idle. enabled since Thu 20 2021 03:55:13 AM IST Rejecting Jobs
Now understand that if we use the
cupsreject command the printer itself will continue processing all queued print jobs will it ever happen to be in the queue at the time we ran the
Even though it will continue processing any queued print jobs the CUPS daemon will not allow any new jobs to enter the queue.
So, if we want to work on the printer and we use the the printer and we use the
cupsreject command we’ll have to wait for all the pending jobs to finish before we can take it offline.
Now if you want you could use the
-hold parameter with the
This will tell the printer to stop printing after the current job is complete instead of going through every single job in the print queue.
Enable the print queue
When I’m done working on the printer, I can re-enable it by entering
cupsaccept followed by the name of the printer at the shell prompt and you’ll start processing the queue again.
# cupsaccept HPLJ5
cupsreject enable or disable the print queue itself but not the printer.
How to enable or disable the printer itself
Now we can accomplish this same task from a different perspective using different commands.
For example, if we wanted to disable the printer itself but not the print queue, we would use a different command.
Disable the printer
We use the
cupsdisable command instead of the
cupsreject command, the syntax is the same we enter
cupsdisable followed by the name of the printer.
An example of that is shown right here.
# cupsdisable HPLJ5
Now when I run this command the print queue itself associate with the HPLJ5 printer will continue to accept new jobs but none of them will actually be sent to the physical printer.
They’ll just be queued up waiting for you to do whatever it is you need to do.
You can see this in the output of the
lpstat command notice down here it tells us that the status of the printer is paused.
# lpstat -t scheduler is running system default destination: HPLJ5 device for HPLJ5: parallel: /dev/lp0 HPLJ5 accepting requests since Thu 20 2021 03:55:13 AM IST printer HPLJ5 is disabled since Thu 20 2021 03:55:13 AM IST Paused
It’s the print queue itself is still accepting requests but the printer is disabled.
Enable the printer
None of the jobs being sent to the print queue will actually be printed until you are enabling the printer using the
cupsenable followed by the name of the printer.
So to enable a printer type the following command.
# cupsenable HPLJ5
Releases pending jobs for printing
And you typically use the
--release option with the
cupsenable command to release all pending jobs in the queue to be printed.
# cupsenable --release HPLJ5
Manage print jobs using Line Printer Daemon(lpd) commands
Now you can also use Line Printer Daemon(lpd) commands to manage print jobs on the system, these are called lpd(Line Printer Daemon) commands.
Now by far CUPS is the preferred printing system for modern Linux distributions, however many years ago the preferred printing system was the Line Printer Daemon(lpd).
Now most of the lpd commands have a functionality that’s similar to that offered by a CUPS command.
The key thing to remember is that most of these lpd commands still work with the CUPS daemon even though they were designed to work with the lpd daemon.
Send a file to the Printer for Printing
For example to send a file to the printer you use this command here,
lpr -P (Capital P) followed by the name of the printer followed by the name of the file that you want to print.
# lpr -P HPLJ5
Query the status of the Printer
You can query the status of the printer using the
lpc status command.
# lpc status
View a list of pending Print Jobs
You can view a list of pending print jobs in the print queue by entering the
Delete a pending job from the Print Queue
And you can delete a pending job from the print queue using the
lprm command followed by the job number of the print job that you want to get rid of.
Here is an example.
# lprm HPLJ5-4
I hope you have learned something from this article.
I have tried my best to include all the Print Management Commands.
Now I’d like to hear your thoughts.
Was this guide useful to you?
Or maybe you have some queries.
Have I not included any command in this guide?
Leave a comment below.
2 thoughts on “Explaining Print Management Commands in Linux With Examples”
I just want to say thank you for this great forum. I found a solution here on edumotivation.com for my issue.
Thank you so much.