How to save man pages from Terminal

One would expect it should be easy to save a man page from terminal for review, and it is, but it doesn’t work the way you expect.

I would expect that “man col > col.txt” should save a nice text file in the home directory, but the results are strange:

COL(1)              BSD General Commands Manual            COL(1)

NNAAMMEE
ccooll — filter reverse line feeds from input

SSYYNNOOPPSSIISS
ccooll [--bbffhhppxx] [--ll _n_u_m]

DDEESSCCRRIIPPTTIIOONN
The ccooll utility filters out reverse (and half reverse) line feeds so that
the output is in the correct order with only forward and half forward
line feeds, and replaces white-space characters with tabs where possible.

Similarly, trying to open the man pages using “man col | open -f” dutifully opens the mangled file in TextEdit.

The repeated characters are fossil behaviors from the days when bolding was accomplished by repeatedly backspacing and overprinting characters.  The col utility is the workaround for this behavior. The man for col says:

The col utility filters out reverse (and half reverse) line feeds so that
the output is in the correct order with only forward and half forward
line feeds, and replaces white-space characters with tabs where possible.

And we need to use the -b option :
-b      Do not output any backspaces, printing only the last character
written to each column position.

So to redirect the man file to a text file, use

man col | col -b > col.txt

which pipes ( | ) the man pages to the col utility, without backspaces, and then redirects it to a text file.  To open the man for col in TextEdit, use

man col | col -b | open -f

(The -f option for open sends to the default text editor.)

If you want the man pages as PDF, try:

man -t [your_command_name_here] | open -f -a Preview

This provides a nice looking output that respects the bolding.  The -t option for man formats the output as PostScript; the -a option for open lets you specify the application (Preview).

Leave a Reply