Printing from the command line
Any command output can be sent to the default printer simply by piping it to lp or lpr.
This will almost certainly result in very small margins (test close to the edges of the paper) and 10 characters per inch, 6 lines per inch, in portrait mode.
Sometimes you want to change these, which you can do by supplying options to the lp command, for example
ls -l | lp -o landscape
Each option you supply has to be prefixed by its own -o. Here are some reminders of some useful ones:
Option | Meaning | Example |
---|---|---|
portrait | Print with the short side of the paper at the top | |
landscape | Print with the long side of the paper at the top | |
cpi=N | Set the number of characters per inch to N | cpi=15 |
lpi=N | Set the number of lines per inch to N | lpi=8 |
page-left=N | Set the left margin to N points (1/72 inch) | page-left=36 |
page-right=N | Set the right margin to N points (1/72 inch) | page-right=36 |
page-top=N | Set the top margin to N points (1/72 inch) | page-top=48 |
page-bottom=N | Set the bottom margin to N points (1/72 inch) | page-bottom=48 |
columns=N | Set the number of columns per page to N | columns=2 |
number-up=N | Scale down and print N output pages on each paper page | number-up=4 |
So, if you wanted to print a file listing in landscape mode with three columns across the page, ½" margins all round, at 12 characters per inch and 8 lines per inch, you could use:
ls | lp -o landscape -o columns=3 -o page-left=36 -o page-right=36 -o page-top=36 -o page-bottom=36 -o lpi=8 -o cpi=12
Go up
Return to main index.