0

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?

4 Answers 4

2
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
6
  • Do you know how you can get the number of pages before you print the manual? Jun 2, 2009 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, 2009 at 21:26
  • @sekenre: I get the following error message: dpaste.com/60058 Jun 26, 2009 at 14:30
  • It seems that OS/X's man does not have the option T. Jun 26, 2009 at 14:34
  • @Masi: Try using man -t python | lpr Your version has that option.
    – Sekenre
    Jun 27, 2009 at 19:51
1

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.

1

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)'
1

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.

2
  • @Josh: What is FP? Jun 26, 2009 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, 2009 at 5:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .