How to print from the Linux command line
Printing documents from the Linux command line is easy. You use the lp command to request printing and lpq to see which print jobs are in the queue. But things get a little more complicated when you want to print on both sides or use portrait mode. And there are many other things you might want to do - such as printing multiple copies of documents or canceling print jobs. Take a look at some options for printing documents from the Linux command line!
Show printer settings
To view printer settings from the command line, use the lpoptions command . The output will look like this:
$ lpoptions 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
Note how many settings are listed.
NOTE : In the output below, some lines are reconnected to make this output more readable.
$ 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
With the -v option , the lpinfo command will list drivers and related information.
$ 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
The lpoptions command will display the default printer settings. Use the -p option to specify one of the available printers.
$ lpoptions -p LaserJet
The lpstat -p command displays the status of the printer and the lpstat -p -d command also lists available printers.
$ 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 commands
To print documents on the default printer, simply use the lp command followed by the name of the file you want to print. If the file name includes whitespace (very rare on Linux systems), put the name in quotation marks or start typing the file name and press the Tab key to mark the file name separately (as in the second example below ).
$ lp "never leave home angry" $ lp never leave home angry
The lpq command displays the print queue.
$ lpq Color-LaserJet-CP2025dn is ready and printing Rank Owner Job File(s) Total Size active shs 234 agenda 2048 bytes
With the -n option , the lp command allows you to specify the number of copies of the document you want to print.
$ lp -n 11 agenda
To cancel a print job, you can use cancel or lprm. If you don't act quickly, you can see this:
$ cancel 229 cancel: cancel-job failed: Job #229 is already completed - can't cancel.
Duplexing
To print in duplex mode, you can issue a lp command with the sides option , so that the machine knows which side to print on both sides of the paper and which paper will flip. This setting is the same as other 2-sided printing.
$ lp -o sides=two-sided-long-edge Notes.pdf
If you want all your documents to be printed in duplex mode, you can change the lp settings, using the lpoptions command to change the settings for the sides.
$ lpoptions -o sides=two-sided-short-edge
To return to single-sided printing, you will use the following command:
$ lpoptions -o sides=one-sided
Print in landscape mode
To print in landscape mode, you will use the option equal to the lp command.
$ lp -o landscape penguin.jpg
CUPS
The printing system used on Linux operating systems is a standard, open source printing system called CUPS, short for Common Unix Printing System . CUPS allows a computer to act as a print server.
You should read it
- How to use the Linux command line on Android with Termux
- 12 things Linux is easier to do in the command line than graphical software
- How to copy (and paste) files and folders from the Linux command line
- How to check whether a Linux PC is 64-bit or 32-bit by command line
- 5 reasons why people love the Linux command line
- How to manage Linux services using Systemd
- How to use the which command in Linux
- How to find the MAC address using the command line in Linux
- 14 interesting Linux commands in Terminal
- How to schedule Linux commands with 'at'
- How to check internet speed with the command line in Linux
- Basic Linux commands everyone needs to know
Maybe you are interested
Printer loses letters and letters - Fixing the error is not difficult
4 creative ways to use a scanning printer
Top 5 best printers in 2024
Fix printer errors with blurred text and blurred lines
How to share a printer via Lan network - So that 2 or more computers can print at the same time
The printer cannot display default settings and what you need to do