You open your document, you click print, you wait. You close the document, open a new one, click print, and wait… and so on. But printing really shouldn’t be that dull. We can send bulk emails with little effort; why can’t we bulk print with the same ease?

Well, if you’re using Linux, it turns out you can. Via the terminal you can issue various Linux printer commands that basically make printing far more agreeable. A host of other terminal-based printing tricks are available on Linux.

1. Display a List of Installed Printers

If you have multiple printers on your network, it’s likely that not all of them are set up on Linux.

To check for the printers installed on your computer, open a terminal and use

        lpstat -p
    
Display a list of printers

Of course, you have other options. You can check from the Printers settings screen, but that takes longer. As with most of these Linux command line printer instructions, typing is faster than moving and clicking the mouse through a series of menus.

To see installed printers on the desktop interface, open Settings > Printers.

2. Find the Printer’s IP Address

In order to print to a network printer, you need its IP address. While you could go to the printer itself and check the device settings, it’s just as easy from your Linux PC.

Open a terminal and enter:

        lpinfo -v | grep -P '://'
    

This will return the printer name, TCP route (learn more about that in our guide to TCP ports), and IP address.

Printer details in the Linux terminal

For a wider look for a network printer, you can also use

        avahi-browse --all -t -r
    

Rather than specifically find your PC, however, this command will find everything on your network that your Linux computer can access. You’ll need to scroll through the list of results to find a specific IP address. It’s a longer solution, albeit one that has uses beyond printing.

In most distros it isn’t possible to see a printer’s IP address from the desktop environment.

Printing a single document on Linux is easy enough. Simply open the PDF or other file format, then click the Print option in the menu.

The key thing about printing on Linux is that if you’re using the desktop environment, you do need to open the file. Things are different in the terminal, however.

Here, use

        cat '/PATH_TO_DOCUMENT/DOCUMENT_NAME.EXT' | lpr
    

Alternative print commands are also available:

        lpr '/PATH_TO_DOCUMENT/DOCUMENT_NAME.EXT'
    

So to demonstrate, if I want to print the PDF low-fodmap_-_breakfast.pdf I use the cat or lpr command and the document's file path:

        lpr ‘/home/atomickarma/low-fodmap_-_breakfast.pdf'
    

Use single quotes to ensure the file path and filename are recognized correctly if printing a document from a different directory. If the document is in the current directory--that is, the same directory where the terminal is open--you won't need quotes.

You don’t even need to open the terminal in the same directory as the file you need to print. As long as you have the absolute file path to the document or image, it will print.

Beware: some documents will not print in this way. For example, while you can print a DOC or DOCX file from your Linux office software, it is not possible to do so from the terminal. But you can use these commands to print ODT files and PDFs.

4. How to Batch Print With a Linux Command

One of the most powerful printing options on Linux is available from the command line.

Attempting to select multiple documents and printing them on the desktop environment typically ends with a single print job. To batch print—that is, to print multiple documents in the same job—you need to use a terminal command.

The lpr command is enough here. All you need to do is follow it with the file paths of the files you wish to print. E.g.

        lpr '/home/atomickarma/high street west.pdf' '/home/atomickarma/Indian-spiced chicken and potato tray bake recipe.pdf'
    

You can even streamline this further. Start by opening a window of all the documents, then open a terminal window. In the terminal, enter lp, then drag the files to the terminal.

Hit Enter, then wait for batch printing to complete.

With multiple printers on your network, you may have a specific device reserved for documents, another for images.

To send a file directly to a named printer, first double-check the printer’s name using the lpstat command:

        lpstat -p -d
    

With that done and the name correctly noted, send a document to that named printer. For example, to print a PDF to my Epson printer, I use:

        lp -d EPSON_XP_4100_Series '/home/atomickarma/low-fodmap_-_breakfast.pdf'
    

You can combine printing to a specific printer with batch printing:

Batch printing in Linux

It’s that easy, and as before, the file can be dragged into the terminal to save you from typing the full file path and filename.

6. Printer Command to Clear a Linux Print Queue

What if you have too many pages printing on Linux and need to clear the queue? Perhaps one of the pages has an error, or a series of print commands duplicates a specific document that should only be printed once.

Before proceeding, ensure that you have a printer set as the default. Otherwise, you should know the name of the printer if several are available on your network. This ensures the command to clear the print queue is sent to the correct device.

The easiest way to tackle this is to send a command to clear the print queue. To clear the entire queue, use:

        lprm -
    

You can also clear the current job with just

        lprm
    

Note that when lprm is used on a networked environment, you will be prompted for your password to cancel a print job.

7. Cancel a Specific Print Job from the Linux Command Line

If you have a specific print job that needs canceling, you’ll first need to find its job ID. You can find this by viewing the print queue with

        lpq
    
Query Linux printer

You can then use the lprm command to cancel that specific job.

So, if the lpq command returned a Job ID of 285, you would enter

        lprm 285
    

Printing on the job typically halts in a couple of seconds, although this depends on the length of the document.

Save Time: Manage Your Printer With Linux Terminal Commands

While the desktop interface is efficient enough on Linux, it isn’t as flexible as controlling your printers from the terminal. With job canceling, batch printing, and general printer management options all available, printer commands in the terminal are worth knowing.

Indeed, it’s worth knowing how to print from any device, just in case.