Related
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Weve now emptied the print queue.