At some point you may want to export a manpage to a file. Using ‘man’ options, you can convert a manual page to PDF, plain text or GROFF, among other formats.

Table of Contents

Notes

In order to run the following commands, you need to have groff installed on your system (it’s probably already installed).

Export to GROFF

GROFF is the format language used to create manual pages. To export a manpage to a GROFF file, run:

man -t <page> > manpage.groff

For example:

man -t ls > ls.groff

Export to PDF

When using -T<device> you can export to other file formats (‘devices’). To export to a PDF file, run:

man -Tpdf <page> > manpage.pdf
# e.g.:
man -Tpdf ls > ls.pdf

Do not add a space between -T and the device name. If exporting to PDF does not work (error groff:fatal error: invalid device pdf'), try installing groff package. If it still doesn’t work, install groff-perl.

Export to HTML

Using the same syntax as above, you can also export a manpage to a HTML file.

man -Thtml <page> > manpage.html
# e.g.:
man -Thtml ls > ls.html

The HTML file will include an index (or ToC) at the beginning.

Export to text

Exporting a manpage to a plain text file (ASCII) is even quicker:

man -7 <page> > manpage.txt
# e.g.:
man -7 ls > ls.txt

You can use --ascii instead of -7.

If you have any suggestion, feel free to contact me via social media or email.