Print from command line

Mainly there are two default commands:

lpr and lp

man lpr gives the output:

lpr submits files for printing. Files named on the command line are sent to the named printer (or the default destination if no destination is specified). If no files are listed on the command-line, lpr reads the print file from the standard input.

man lp gives the output:

lp submits files for printing or alters a pending job. Use a filename of "-" to force printing from the standard input.

so easily use the command:

lp /path-to-file-to-print

Or

lpr /path-to-file-to-print

You can use lp

For example:

man firefox | lp -d printername

This will print the man page from firefox to the specified printer


If you have them installed, another pair of options worth knowing about are

  • enscript

and

  • a2ps

These are useful for providing numbered pages with headings and optional line-numbers. You can also use then to print booklet style (e.g. two pages on each side of a sheet)

I use these with Postscript-capable printers but I believe that Ubuntu's print system can rasterize PS for any supported printer.


You may want to find out how the printer is accessed first - lpstatwill give you that information. If you compare its output across both systems, you can probably tell whether the printer in question has been configured on both of them. lpstat -p -d lists all printers with their status and tells which one has been set as default printer.

You can simply pipe your output to the lp or lpr command then. You may want to insert a filter for pretty-printing or pagination though. There's a good summary of tools at the debian manual "Highlighting and formatting plain text data", but I'm usually just using sed to highlight prompts and other stuff before sending everything through a2ps


To print a .txt file in a use :

command | lpr -P printername -p ( periority from 1 to 100 )

Example :

ls -l | lpr -P printername -p 1