logo hsb.horse
← Back to snippets index

Snippets

Saving man Pages to Text Files

How to save man command output to a file on macOS/Linux. Use col -b to remove control characters and create readable text.

Published: Updated:

Sometimes you want to save man command output to a file for reading in an editor or sharing. Simple redirection mixes in control characters, so proper post-processing is needed.

Using col -b

Terminal window
man <command> | col -b > <filename>.txt

Example

Terminal window
man ls | col -b > ls_manual.txt

This creates plain text that won’t be garbled when opened in a regular text editor.

Why Plain Redirection Doesn’t Work

Terminal window
man ls > ls_bad.txt

Saving like this outputs control characters like backspaces (used by man for formatting like bold and underline, appearing as ^H, etc.) directly into the file. It becomes very hard to read in editors other than less.

col -b filters these out, leaving only the text as it appears.

Saving as PDF

For printing purposes or when you want PDF, go through PostScript.

macOS

Terminal window
man -t ls | pstopdf -i -o ls_manual.pdf

Linux

Terminal window
man -t ls > ls.ps
ps2pdf ls.ps ls_manual.pdf

The -t option outputs in PostScript format, which is then converted to PDF.

Summary of Options

MethodCommandUse Case
Plain textman …col -b
PDFman -t …pstopdf
HTMLman2htmlBrowser display

Personally, plain text is the most practical. Searching and processing is easy.