Print man pages with fixed width

Use the MANWIDTH environment variable:

MANWIDTH=60 man apropos > apropos.txt

The manpage for man 2.7.4 says:

If $MANWIDTH is set, its value is used as the line length for which manual pages should be formatted. If it is not set, manual pages will be formatted with a line length appropriate to the current terminal (using the value of $COLUMNS, an ioctl(2) if available, or falling back to 80 characters if neither is available).

That is, it overrides both COLUMNS and the ioctl value. I prefer to not rely on modifying COLUMNS (although it does work here) since its value is updated dynamically every time the window size changes.

Using MANWIDTH instead of COLUMNS also allows you to make the change permanent by adding a line such as export MANWIDTH=60 to your shell startup file.


Try setting the COLUMNS environment variable. Works for me with man from mandb 2.7.0.2 on Debian with groff 1.22.3.

$ COLUMNS=60 man apropos | head
APROPOS(1)          Manual pager utils          APROPOS(1)



NAME
       apropos - search the manual page names and descrip‐
       tions

SYNOPSIS
       apropos [-dalv?V] [-e|-w|-r]  [-s  list]  [-m  sys‐

$ COLUMNS=70 man apropos | head
APROPOS(1)               Manual pager utils               APROPOS(1)



NAME
       apropos - search the manual page names and descriptions

SYNOPSIS
       apropos  [-dalv?V] [-e|-w|-r] [-s list] [-m system[,...]] [-M
       path] [-L locale] [-C file] keyword ...

With the version on Ubuntu 14.04, I need to write it:

COLUMNS=60 < /dev/null man apropos | head

There, man seems to disregard the COLUMNS environment variable if stdin is a terminal (it then queries the terminal device for the terminal width).

You can also try:

s=$(stty -g); stty cols 60; man apropos | head; stty "$s"

Which with zsh you can shorten to:

STTY='cols 60' man apropos | head

You could do it by invoking groff by hand as:

gzip -dcf "$(man -w apropos)" |
  groff -ekpstR -mtty-char -mandoc -Tutf8 -rLL=60n |
  col -bpx

Your can't find character with input code errors were because you used -Tascii instead of -Tutf8 and didn't use -k to pre-process the files with preconv.


You can use the fmt command, which as far as I know is present in any Linux distribution.

man apropos | fmt -w 70 

will wrap up lines at 70 characters.