Home > Documentation, Mac administration, Mac OS X, macOS, Unix > Exporting Unix man pages to plain text files

Exporting Unix man pages to plain text files

While working with different versions of Mac OS X and macOS, it’s often been useful to me to be able to export the contents of a particular command line utility’s Unix man page to a plain text file. Man pages are the built-in documentation method available in Unix-based systems, so Apple documents how to use the various command line tools used by the operating system using this documentation method.

Exporting to a plain text file allows me to compare macOS Sierra’s man page for a particular command line utilty to a exported copy of the same utility’s man page from OS X El Capitan and see where changes to the man page have been made. This comparison is made by using diff, or other file comparison tools like Kaleidoscope, which helps me quickly spot where Apple has made changes to their documentation.

To export man pages to a plain text file, I use the col command line utility to read the contents of the man page in using stdin, then export out to a plain text file using stdout As an example, here’s how to use col to export the diskutil man page to a new plain text file named diskutil.txt:

man diskutil | col -bx > /path/to/diskutil.txt

In this case, col‘s -b and -x functions are used to make sure that the formatting for the diskutil man page remains intact when exported to the plain text file.

  1. Dials Mavis
    July 13, 2016 at 3:40 am

    Another great function I’ve learnt is piping man pages to a PDF document.
    The below function can be copied into your .bashrc or .bash_profile so you can run `manp ` and a PDF will open.
    manp ()
    man -t $* | open -f -a /Applications/Preview.app/

    Credit goes to Tony Williams (a.k.a. Honest Puck) for this wonderful snippet.

    • July 13, 2016 at 4:16 am

      Well, I didn’t write it. I just can’t remember back the many years to know where I stole it from. You know, great artists steal.🙂

  2. Joss Brown
    July 13, 2016 at 8:55 am

    Great information, thank you! I have one question. Like everyone I have several paths, incl. /usr/local/bin, and sometimes I have two versions of a program, e.g. tar, one in /usr/bin (standard macOS BSD version), one in /usr/local/bin, the GNU version. My plan would be to call both man pages, but that isn’t possible due to the settings in /etc/manpaths where I put /usr/local/share/man in first place. I know you can do it by typing

    export MANPATH=/usr/share/man:$PATH && man tar | col -bx > /path/to/tar.txt

    to export the BSD instead of the GNU man page.

    So now the question: is there any better way to do it than by always exporting the path? (Because once you do that, you’re stuck with that path for the current shell, and you’d have to export again.)

    • July 13, 2016 at 2:57 pm

      You could do some hackery with `man -a` to output both / all man pages it finds.

      • Joss Brown
        July 13, 2016 at 11:02 pm

        Thank you, Ryan! Hitting q just loads the next man page. Wonderful.

  3. Maurits
    July 13, 2016 at 9:09 pm

    For easy reading of man pages in Safari (with good looks, and linking to related man pages, and search function) I can recommend Bwana from Bruji.com (https://www.bruji.com/bwana/)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: