Open Any man Page in Preview and Save as PDF

If you’re tired of looking over a man (manual) page within the Terminal, you can use a nifty command sequence to launch any specified man page into the Preview app of Mac OS X. This is done by piping the standard man output into the open command and Preview.

Launching the man Page into Preview

The exact syntax to use for this purpose is as follows:

man -t [COMMAND GOES HERE] | open -f -a /Applications/Preview.app

For example, this is using the trick to open the manual page for ‘ipconfig’ into Preview:

man -t ipconfig | open -f -a /Applications/Preview.app

You can do this with any page, just replace ‘ipconfig’ with any other command or known man page you’d like to read within Preview and it’ll work the same.

And yes, this is opening the manual page in Preview.app, the image editing and viewer app bundled with every version of Mac OS X… that may sound confusing and a bit weird to send a command line man document into an image editing app, but this is where things get particularly cool… you can export it as a PDF!

Essentially what you’re doing here is converting the manual page from a terminal text file into a PDF document.

Saving the man Page as PDF

Once the man page is opened within the Preview app, you can then use Preview to “Save As” and then create a PDF file of the man page for later viewing. All you need to do is pull down the File menu and choose “Save As” or “Export As PDF” to save the file to where ever you want, now you have the entire manual document stored in a scannable PDF file that is easy to read on another device.

I find myself using this little trick frequently and then saving the PDF to view on my iPad, a particularly useful trick if you’re deep in the weeds of learning a specific command or the proper usages of some terminal syntax. It’s also just helpful to open on an ipad or iPhone and use it as a secondary screen for while you’re at the terminal.

If you’re not from a unix background, a ‘man page’ is nothing more than a manual, and they’re really helpful when you’re trying to sort out syntax of various command line features and utilities. You can access them for any command in the terminal by simply typing “man (command)”.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Note: After editing this file you need to reload it for the new function to work. Either quit/restart terminal, or type source ~/.profile (or . ~/.profile if you want to be geeky) and the command will be registered.

To call the function, just type pman _function_name
so
pman ls
pman fstab

I spend about 50 minutes a day on trains and usually just tinker with my iPad since it’s the WiFi model and can’t access the web. I must say I never thought of this, but what a great way to read manuals on the iPad and put that commute to work since my company pays overtime for work related learning.