Open Any man Page in Preview and Save as PDF

Sep 27, 2010 - 6 Comments

terminal 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!

man page preview

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:

Related articles:

Posted by: Manish Patel in Command Line, Mac OS X, Tips & Tricks

6 Comments

» Comments RSS Feed

  1. CraigMC says:

    Better still to register this as a function that can be called from the command line.

    Add this to the bottom of ~/.profile and you can just type a simple command to open the given man page in Preview:

    #Open Man page in Preview
    pman () {
    man -t “${1}” | open -f -a /Applications/Preview.app
    }

    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

    etc.

    Enjoy
    CraigMC

    PS got this from commandlinefu.com after some google searching

    • Philip says:

      Actually you have to remove the quotes “” from “${1}”, so that it reads ${1} otherwise the quotes will be taken as part of the argument and you will get – No manual entry for “ls”

  2. Vic says:

    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.

    Thanks a bunch.

  3. Barry Kelly says:

    If you really need the things in pdf form, and you have ghostscript (and thus ps2pdf) installed, you can skip the middleman with man -t ipconfig | ps2pdf – ipconfig.pdf

  4. […] that man pages can also be read on the go by saving them as a PDF and opening them with iBooks app on the iPad or iPhone. stLight.options({ […]

  5. dm says:

    thanks, good thing!

    but it can be a bit short – without full path to Preview.app
    like this:
    man -t wget | open -f -a Preview

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates