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 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'
May be interested
- How to send email using the command line in Linuxin this article, i will show you how to use the linux command to send mail with a script. in addition, it is the sending of attachments from the command line.
- Instructions for using find command in Linuxthe find command is one of the most important and handy commands on a linux system. as its name suggests, the command can find files on a linux pc based on a variety of conditions and variables you set.
- How to use the which command in Linuxthe which command in linux determines the executable binary, which will execute when you issue a command to the shell. if you have different versions of the same program on your computer, you can use which to find out which shell will use.
- The dd command in Linux, How to use the dd commanddd is a command line utility for unix-like and unix operating systems, with the main purpose of converting and copying files.
- How to Manage Users in Linuxunlike windows, as a unix-like system, linux was conceived of as a multi-user system from its inception. the following sections deal with user management through the linux command line. type adduser -d /home/users/ into the command line.
- 5 free websites and online games to learn about the Linux command linelinux is popular for its reliability and many practical applications. if you want to know more about linux, here are 5 websites that will help you learn it interactively.
- 20+ essential Linux security commandshere are some of the most important security commands for everyday work on linux systems. if you're interested in security issues on your linux system, don't ignore these helpful security commands.
- Search for files and directories in Linux using the command line interfaceyou can use the graphical file management utility to find files in linux like nautilus in gnome, dolphin in kde and thunar in xfce. however, there are several ways to use the command line to find files in any linux desktop management utility.
- How to use the stat command on Linuxthe linux stat command shows you more details than the ls command. the following article will show you how to use the stat command in linux. like ls, the stat command has many options. this makes it a great candidate for the use of alias.
- 14 interesting Linux commands in Terminalterminal is a very powerful tool, but it can become 'interesting' through a few bash commands that quantrimang will introduce to you later. let's follow up and find out because some commands are quite useful.