Printing from the Linux command line

If you wish to print from a Linux command line, you’ll have many options available to you apart from just the popular line printer (LP) command. However, the LP command is the most popular, where you can use the LP command to request print and the lpq to see any print tasks on the queue. Although this can be straight forward, it is necessary to know how to tweak you print formats, orientation mode, canceling a print task or even do a double-sided printing.

Here are ways you do more than just simple printing:

How To View Linux command line Printer Settings

If you want to display the settings for your printer from the command line, just use the command:

  • Lpoptions

You should get an output similar to this:

CODE:

copies=1 device-uri=dnssd://HP%20Color%20LaserJet%20CP2025dn%20(F47468)._pdl-datastream._tcp.local/ finishings=3 job-cancel-after=10800 job-hold-until=no-hold job-priority=50 job-sheets=none,none marker-change-time=1553023232 marker-colors=#000000,#00FFFF,#FF00FF,#FFFF00 marker-levels=18,62,62,63 marker-names='Black\ Cartridge\ HP\ CC530A,Cyan\ Cartridge\ HP\ CC531A,Magenta\ Cartridge\ HP\ CC533A,Yellow\ Cartridge\ HP\ CC532A' marker-types=toner,toner,toner,toner number-up=1 printer-commands=none printer-info='HP Color LaserJet CP2025dn (F47468)' printer-is-accepting-jobs=true printer-is-shared=true printer-is-temporary=false printer-location printer-make-and-model='HP Color LaserJet cp2025dn pcl3, hpcups 3.18.7' printer-state=3 printer-state-change-time=1553023232 printer-state-reasons=none printer-type=167964 printer-uri-supported=ipp://localhost/printers/Color-LaserJet-CP2025dn sides=one-sided

If you find the output to be complex or hard to read, try turning the blanks into carriage returns.

This output is likely to be a little more human-friendly if you turn its blanks into carriage returns. In the second output below, I tried to reconnect some of the lines to make the code more human-friendly.

CODE:

$ lpoptions | tr " " '\n'
copies=1
device-uri=dnssd://HP%20Color%20LaserJet%20CP2025dn%20(F47468)._pdl-datastream._tcp.local/
finishings=3
job-cancel-after=10800
job-hold-until=no-hold
job-priority=50
job-sheets=none,none
marker-change-time=1553023232
marker-colors=#000000,#00FFFF,#FF00FF,#FFFF00
marker-levels=18,62,62,63
marker-names='Black\ Cartridge\ HP\ CC530A,
Cyan\ Cartridge\ HP\ CC531A,
Magenta\ Cartridge\ HP\ CC533A,
Yellow\ Cartridge\ HP\ CC532A'
marker-types=toner,toner,toner,toner
number-up=1
printer-commands=none
printer-info='HP Color LaserJet CP2025dn (F47468)'
printer-is-accepting-jobs=true
printer-is-shared=true
printer-is-temporary=false
printer-location
printer-make-and-model='HP Color LaserJet cp2025dn pcl3, hpcups 3.18.7'
printer-state=3
printer-state-change-time=1553023232
printer-state-reasons=none
printer-type=167964
printer-uri-supported=ipp://localhost/printers/Color-LaserJet-CP2025dn
sides=one-sided

Using the lpinfo –v option will have your device list all drivers and information related to them:

CODE:

$ lpinfo -v
network ipp
network https
network socket
network beh
direct hp
network lpd
file cups-brf:/
network ipps
network http
direct hpfax
network dnssd://HP%20Color%20LaserJet%20CP2025dn%20(F47468)._pdl-datastream._tcp.local/  <== printer
network socket://192.168.0.23															 <== printer IP

While the lpoption command will mainly display the settings of your default printer, you can use lpoptions –p command to select a specific available printer from your connected devices.

CODE:

$ lpoptions -p LaserJet

Another useful command is the lpstat –p. This command can be used to view the current status of your printer. One can also choose to combine the –p and –d to form “lpstat -p –d” which displays both the status and the list of available printers on the system as well.

CODE:

$ lpstat -p -d
printer Color-LaserJet-CP2025dn is idle. enabled since Tue 19 Mar 2019 05:07:45 PM EDT
system default destination: Color-LaserJet-CP2025dn

Useful Linux command line

The quickest way to execute the Print command is by typing in the LP command followed by the file name of the document you want to print. This will automatically print to the default printer. Note that in case your file name contains blanks, simply put the name in quotations. Alternatively, you can start typing the file name then hit TAB key to autocomplete. Check out the example below:

CODE:

$ lp "never leave home angry"
$ lp never\ leave\ home\ angry

After you execute the above commands, you should expect your printer to start printing. In case you have more than one document printing, feel free to check the printing queue by using the command:

  • lpq

Another useful command option is the lp-n that allows you to select the number of copies you want to print. Even once the command is sent, you can cancel the print task using the lprm command. Note that the cancel command also does the same thing as the lprm one. If you see the ‘cancel 229’ message, it means that you have delayed and the command or print task cannot be canceled.

CODE:

$ lpq
Color-LaserJet-CP2025dn is ready and printing
Rank    Owner   Job     File(s)                         Total Size
active  shs     234     agenda                          2048 bytes

Two-sided printing

Printing on two sides is fairly easy, and you can do this by using the sides option in the lp command. This will not only allow you to print on both sides but also help you select on which edge you’d like to flip the page. Take a look at the example below of a typical two-sided printing protocol:

CODE:

$ lp -o sides=two-sided-long-edge Notes.pdf

You can also make all documents print in two-sided mode by changing the print settings using the lpoptions command.

CODE:

$ lpoptions -o sides=two-sided-short-edge

If you want to go back to the previous single sided print setting  use:

CODE:

$ lpoptions -o sides=one-sided
Printing in landscape mode

Although portrait mode is most likely your default printing orientation; you can always make the switch to landscape using the lp command line as follows:

CODE:

$ lp -o landscape penguin.jpg

CUPS

CUPS is the printing system used on Linux-based operating systems that allow your device to behave like a print server. The name CUPS originally stood for Common Unix Printing System.

Leave a Comment

Your email address will not be published. Required fields are marked *