man
command to view the manual page, aka a
"man
page" for the command/utility. If you want to convert the man page to
a HyperText Markup
Language (HTML) document, you can use the
groff
text formatting utility. You can find man pages beneath the
/user/share/man
directory in subdirectories named manx
where x is a number, e.g. man1
, man2
,
etc. You can use the find
command to locate the appropriate directory and file. E.g., if a system was
functioning as an Apache web server and I wished to find the file associated
with the man page for
apachectl, I could use the command below:$ find /usr/share/man -name apachectl\* /usr/share/man/man8/apachectl.8.gz $
Once you have the location, you can pipe the contents of the file into
the groff command. E.g.,
under OS X, if you wanted to view the documentation for Apple's
AppleScript
scripting language osascript
utility, you can find the man page on an OS X system at
/usr/share/man/man1/osascript.1
. To format it as HTML,
you can pipe the contents of the file into groff
as
shown below:
$ cat /usr/share/man/man1/osascript.1 | groff -mandoc -Thtml >man_osascript.html
The above example creates an HTML file
man_osascript.html by using the -T
option to specify the type
of formatting desired, in this case HTML - you can put a space between the
-T
and HTML
, if you wish. Other
options for the -T
parameter are listed in the groff man page.
Some files in the man directories may be in compressed .gz format.
You can use the
gunzip command to extract them to
standard output (stdout) and then pipe them to groff
- be
sure to include -c
, --to-stdout
or
--stdout
option so the original file will be left intact.
$ ls /usr/share/man/man8/cups* /usr/share/man/man8/cups-deviced.8.gz /usr/share/man/man8/cupsd-helper.8.gz /usr/share/man/man8/cups-driverd.8.gz /usr/share/man/man8/cupsd-logs.8.gz /usr/share/man/man8/cups-exec.8.gz /usr/share/man/man8/cupsd.8.gz /usr/share/man/man8/cups-lpd.8.gz /usr/share/man/man8/cupsdisable.8.gz /usr/share/man/man8/cups-snmp.8.gz /usr/share/man/man8/cupsenable.8.gz /usr/share/man/man8/cupsaccept.8.gz /usr/share/man/man8/cupsfilter.8.gz /usr/share/man/man8/cupsaddsmb.8.gz /usr/share/man/man8/cupsreject.8.gz /usr/share/man/man8/cupsctl.8.gz $ gunzip --to-stdout /usr/share/man/man8/cupsfilter.8.gz | groff -mandoc -Thtml >man_cupsfilter.html
If you want to produce a
Portable Document Format (PDF) file for the man page, you can produce
an HTML document from it using groff and then convert it to PDF with
the cupsfilter command
found on OS X and Linux systems. E.g., to produce an
man_osascript.pdf file, I could issue the
command cupsfilter man_osascript.html > man_osascript.pdf
as
shown below:
$ cupsfilter man_osascript.html > man_osascript.pdf DEBUG: argv[0]="cupsfilter" DEBUG: argv[1]="1" DEBUG: argv[2]="jasmith1" DEBUG: argv[3]="man_osascript.html" DEBUG: argv[4]="1" DEBUG: argv[5]="" DEBUG: argv[6]="man_osascript.html" DEBUG: envp[0]="<CFProcessPath>" DEBUG: envp[1]="CONTENT_TYPE=text/html" DEBUG: envp[2]="CUPS_DATADIR=/usr/share/cups" DEBUG: envp[3]="CUPS_FONTPATH=/usr/share/cups/fonts" DEBUG: envp[4]="CUPS_SERVERBIN=/usr/libexec/cups" DEBUG: envp[5]="CUPS_SERVERROOT=/private/etc/cups" DEBUG: envp[6]="LANG=en_US.UTF8" DEBUG: envp[7]="PATH=/usr/libexec/cups/filter:/usr/bin:/usr/sbin:/bin:/usr/bin" DEBUG: envp[8]="PPD=/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/Generic.ppd" DEBUG: envp[9]="PRINTER_INFO=cupsfilter" DEBUG: envp[10]="PRINTER_LOCATION=Unknown" DEBUG: envp[11]="PRINTER=cupsfilter" DEBUG: envp[12]="RIP_MAX_CACHE=128m" DEBUG: envp[13]="USER=jasmith1" DEBUG: envp[14]="CHARSET=utf-8" DEBUG: envp[15]="FINAL_CONTENT_TYPE=application/pdf" INFO: xhtmltopdf (PID 15591) started. DEBUG: Page = 612x792; 17,19 to 595,773 Feb 8 16:41:37 GSSLA15122293 cupsfilter[15591] <Warning>: CGSConnectionByID: 0 is not a valid connection ID. Feb 8 16:41:37 GSSLA15122293 cupsfilter[15591] <Warning>: Invalid Connection ID 0 DEBUG: Loading "file:///Users/jasmith1/Documents/man_osascript.html" DEBUG: Waiting for HTML file to load, 10% DEBUG: Page title="osascript man page" DEBUG: Bounds of document are [0.0 0.0 564.0 2112.0] DEBUG: Starting page 1: [0.0 0.0 578.8 745.0] DEBUG: Starting page 2: [0.0 745.0 578.8 752.0] DEBUG: Starting page 3: [0.0 1497.0 578.8 754.8] INFO: xhtmltopdf (PID 15591) exited with no errors. $
The cupsfilter utility can be used to convert any HTML file to PDF.
Another alternative to viewing documentation for a command or utility
from a command line interface (CLI) on an OS X or Linux system is to use the
info
utility, which reads info documentation files as opposed to the
man page files used by the man
command. The GNU Project
distributes most of its manuals in the Info format - see Info
at www.gnu.org. E.g., to view
documentation for the osascript
program on a OS X
system, you can use info osascript
. You can use the command below
to produce an output text file,
info_osascript.txt, containing the
documentation.
$ info osascript --output=info_osascript.txt info: Writing node (*manpages*)osascript... info: Done.
References: