3

I often need to search or print a man page. Executing the man [-a index] name command invokes a readonly navigable viewer of name[(index)]. For example, the command below displays open(1).

man  open

The command below displays open(n).

man  -a  n  open

Is there a way to use the Terminal application to involve a viewer where I can search and/or print a man page?

2 Answers 2

2

Typing just the command name in Terminal and then right-click on it and select Open man Page, displays it in a fully scrollable and searchable Terminal window, which is much better then typing e.g. man bash. You can also use the key combination P to print the contents.


As a side note, here is a function I added to my .bash_profile file to create a PDF of each BSD command I'd check the manual page for:

manp () 
{ 
    docDir="$HOME/Documents/BSD Commands"
    [[ ! -d $docDir ]] && mkdir -p "$docDir"
    if [[ ! -f $docDir/$1.pdf ]]; then
        man -t "$1" | pstopdf -i -o "$docDir/$1.pdf"
        open "$docDir/$1.pdf"
    else
        open "$docDir/$1.pdf"
    fi
}

So, in Terminal, typing e.g. manp bash instead of man bash a PDF gets created, if it hasn't already been, and then opened by the app registered to handle PDF documents. The default is Preview, however on my system it's set to use [Skim][1], as its search functionality is better then Preview and as a matter of fact will find the search string when Preview just will not.

Note that the first time the function is used it will enumerate some fonts in the output in Terminal, however this is a one time enumeration of the fonts.

4
man -t yourcommand | open -fa "Preview"

where yourcommand is the one you want the man page of. You can then use any of the normal search functionality in Preview and print the document as a normal PDF.

4
  • I think this should have been posted as an answer to my original question: Can man pages be converted to html and/or pdf format? Feb 14, 2018 at 19:45
  • @David Okay will move answer and tailor this one to be specific to searching; I never saw that question but seems there's quite a lot of overlap with that question though, and user's posted their answer there too?
    – grg
    Feb 14, 2018 at 19:49
  • I preferred user3439894 answer to the original question, Right clicking on the text certainly is the easiest to use. The problem was it did not fit the original question. So, I posted this question and asked user3439894 (in a now deleted comment) to post an answer here. I then accepted user3439894's answer. Feb 14, 2018 at 19:58
  • @David Thanks for the backstory, that makes more sense!
    – grg
    Feb 14, 2018 at 20:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .