I want to get man pages to stout. However, I have not managed a way to do that.

Pseudo-code about what I am trying to achieve

man man | lpr

How can you print a manual, such that you see first how many pages is going to be printed?

link|improve this question

feedback

4 Answers

up vote 2 down vote accepted
man -Tps man | lpr

This tells man to format the output as a postscript file which can be piped directly to a printer. See the man page for further -T (troff) formatting options.

To preview the output pipe it to a file and view it with gv or okular.

man -Tps man > manual.ps
gv manual.ps
link|improve this answer
Do you know how you can get the number of pages before you print the manual? – Masi Jun 2 '09 at 21:15
See my edits above, I can't think of a way to count the pages from the command line. – Sekenre Jun 2 '09 at 21:26
@sekenre: I get the following error message: dpaste.com/60058 – Masi Jun 26 '09 at 14:30
It seems that OS/X's man does not have the option T. – Masi Jun 26 '09 at 14:34
@Masi: Try using man -t python | lpr Your version has that option. – Sekenre Jun 27 '09 at 19:51
show 1 more comment
feedback

man ls | col -b | lpr -P my_printer

This prints the man page for "ls" formats it using "col" and then prints on the printer named "my_printer"

The formatting isn't required, but gets rid of special characters making it easier to read.

link|improve this answer
feedback

Newer versions of man (at least my version on openSuSE 11 :) ) automatically detect if output is a terminal or a pipe. If you want non-formatted man pages to stdout, try:

man man | cat

For manpages going to the printer, I like:

man man | a2ps --stdin='man(1)'
link|improve this answer
feedback

Answer to # of pages question above(need 50 rep to add comments):

man ls | wc -l | awk '{ print $1/60 }'

The default # of lines per page is 60, so if you aren't changing that, then just divide by 60 and round up. I forget how to make awk treat FP as INT so that it rounds for you.

link|improve this answer
@Josh: What is FP? – Masi Jun 26 '09 at 14:32
sorry for the late response. FP = floating point; INT = integer. It would be useful to have it translated into an INT if you were planning on using the output for another automated purpose(ie - piping a one liner or in a script). – Josh Jul 2 '09 at 5:33
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.