Controlling print jobs with shell commands
Print Center
Use shell commands to start and manage print jobs without too much clicking, while easily avoiding problems with specific file formats.
If you want to print PDF files, you would normally open them individually with a PDF viewer such as Okular or Atril and start printing from there. For starters, this takes up some of your valuable time, and there is a risk of overlooking and omitting some files. Compared to this, printing at the command line often only involves a single line of input if you are working with specific file formats, more specifically Postscript and PDF.
Printing with lpr
You can use the lp
and lpr
commands to print one or multiple files. The calls are the same for sending a print command to the default printer: lp FILE
and lpr FILE
. If you want to output the job to a specific device, you need to pass in the job name using the -d
parameter (for lp
) or -P
(for lpr
). A call via a pipe also works: echo "Hi!" | lpr
or echo "Hi!" | lp
put your output directly onto paper. You can request multiple printouts by stipulating -n NUMBER
(for lp
) or -# NUMBER
(for lpr
).
A print job for multiple files in a single command combines the pages into a single print job for both lp
and lpr
. This can cause problems in the case of printer malfunctions, for example, if the printer breaks down and pages are swallowed up due to a paper jam. Besides this, you only see the name of the last file to be printed in alphabetic order in the print job query. Although the lpq
command displays the complete queue, this can also lead to problems in practical terms if you have large-scale combined print jobs. It takes some effort to identify a file that has not been printed due to a printer error and to start a reprint. Starting the jobs individually offers you a better overview. A small for
construct (Listing 1) helps here. Figure 1 illustrates the difference between the two methods of starting print jobs.
[...]
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.