Summary

The Linux lp command lets you print from a terminal window.

Why Print From the Command Line?

Of course, there are text-based user interface (TUI) applications that support printing, too.

Terminal window showing the manual page for the Mutt email client on Linux

These run inside a terminal window, and allow you to send content to your printer.

But still, I expect the majority of printing comes from inside GUI applications.

The printing we’re talking about here is best used with text files.

A Canon printer with a scanner.

Andrew Martonik / How-To Geek

Installing lp

Most distributions include lp and the other printer-related commands straight out of the box.

If you do need to install them, these are the commands youll need.

One of these is lpstat, which can find out information about your printer.

Installing the cups suite of applications on Ubuntu.

Used without any command line options, lpstat displays the print queue.

The -p (printers) option lists the configured printers, and their status such as idle or printing.

The -d (default) option shows the default printer.

Installing the cups suite of applications on Fedora.

Just because you have only one printer, that doesnt make it the default.

The lpoptions command lists the options that your printer supports.

If no printer is specified, the default printer is described.

Installing the cups suite of applications on Manjaro.

Note that the name to use can be found using the lpstat -p output.

To make the output from the lpoptions command more readable, you could pass it through the column command.

The printers that are able to use each protocol are displayed.

Using the lpstat command with no paramters in a Linux terminal window.

Now that we know about our printer, we can send print jobs to it.

We can take a quick peek at the print queue with lpq.

Were starting with an empty print queue.

Using lpstat with the -p option in a Linux terminal window, to get the printer details.

To send a job, we use the lp command, followed by the name of the file.

Tab expansion automatically escapes spaces for you.

Note that you dont see 15 entries in the print queue.

Using lpstat with the -d option in a Linux terminal window, to get the default printer.

The job is sent to the printer once, with instructions to print it 15 times.

To conserve paper, and if your printer supports it, you’re able to print double-sided.

you could choose to have the pages turned on their long or short edges.

Using lpoptions in a Linux terminal window, to get the details of the printer.

Lets print something double-sided, with the pages turning on their long edge.

Selecting landscape or portrait is just as easy.

We use the -o (options) option once more, and specify either portrait or landscape.

Using lpoptions with the -p option in a Linux terminal window, to get the details of a specific printer.

There are many other options you could use with the -o (options) option.

Check out the man page if youre interested.

You might find some of the options useful.

Piping the output from lpoptions throughthe column command to get a columnar display.

you might find this in the output of the lpq command.

The command we need is cancel, followed by the job number.

you’re free to cancel multiple jobs are once.

Using lpinfo with the -v option to see which printers are accessible by which protocols.

Weve now emptied the print queue.

Using lpq to display the print queue in a Linux terminal window.

Using lp in a Linux terminal window to send a file to the printer.

Using lpq to inspect the print queue with an active print job, in a Linux terminal window.

Adding another job to the print queue, and using lpq to inspect the queue, ina Linux terminal window.

Adding a third job to the print queue, and using lpq to inspect the queue, in a Linux terminal window.

Using lp with the -n option to print a document multiple times, ina Linux terminal window.

Using lp with the sides option in a Linux terminal window, to print a document double-sided.

Using lp with the landscape option, in a Linux terminal window.

Using the cancel command to cancel a print job, in a Linux terminal window.

Using the cancel command to cancel multiple print jobs, in a Linux terminal window.