Explaining Print Management Commands in Linux With Examples

This lesson we’re going to talk about How you can manage CUPS printers from the command line.

Introduction

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.

lp Command

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

The lp command can send a particular file to your CUPS printer, the syntax is doing this as shown here.

Syntax: lp [options] [printer_name] [filename]

We run 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 command.

# lp -d HPLJ5 projectschedule.txtrequest 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 HPLJ5-2.

The print job is added to the print queue and then sent directly to the printer.

Now the lp utility can use some other options besides the -d option.

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

lpstat Command

In addition to the lp command you can also use another utility called lpstat at the command line.

The lpstat utility is used to display CUPS printer information and probably one of the most useful options you can use the lpstat -t.

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 -tscheduler is runningno system default destinationdevice for HPLJ5: parallel: /dev/lp0HPLJ5 accepting requests since Thu 20 2021 03:55:13 AM MDTprinter HPLJ5 is idle. enabled since Thu 20 2021 03:55:13 AM MDTPrinter 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 lpstat command.

cancel Command

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.

Syntax: cancel job_ID

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.

lpoptions Command

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.

Syntax: 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 .lpoptions.

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 .lpoptionsdefault 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 lpoptions command.

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 command.

# 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.

Syntax:

  • Enable a printer’s queue: cupsaccept printer_name
  • Disable a printer’s queue: cupsreject printer_name

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 -tscheduler is runningsystem default destination: HPLJ5device for HPLJ5: parallel: /dev/lp0HPLJ5 not accepting requests since Thu 20 2021 03:55:13 AM IST - Rejecting Jobsprinter HPLJ5 is idle. enabled since Thu 20 2021 03:55:13 AM ISTRejecting 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 cupsreject command.

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 cupsreject command.

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

So basically, cupsaccept and 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.

Syntax: cupsdisable printer_name

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 -tscheduler is runningsystem default destination: HPLJ5device for HPLJ5: parallel: /dev/lp0HPLJ5 accepting requests since Thu 20 2021 03:55:13 AM ISTprinter HPLJ5 is disabled since Thu 20 2021 03:55:13 AM ISTPaused

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 command.

You enter cupsenable followed by the name of the printer.

Syntax: cupsenable printer_name

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 lpq command.

# lpq

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

Conclusion

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.

Share this:
WhatsApp Channel Join Now
Telegram Channel Join Now
Instagram Channel Join Now

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.