TechNeate.com iPhoneate.com QueComico.com MiamiGlobalRadio.com

How to search manual (Man) pages using the command line

by menorah / August 28, 2016 2:59 PM EDT

Referring to a man page can be essential when learning syntax or how a command works, but with how large some man pages can be, it can be a real hassle to scroll through the entire page to find a relevant section. Furthermore, sometimes you simply don't know exactly which page to look on for the necessary information. Fortunately, there are two tools for searching man pages and quickly finding and accessing exactly what you're looking for.

What is Man:

Many of the Terminal commands you're familiar with come from manual (or Man) pages, and these pages are the command-line equivalent of a help system. In fact, Man itself is a command, whose function is to format and display this documentation.

How to search all Man command pages for a string match

If you want to find information about a general command, function, or feature, but you're not sure which Man page has what you need, or perhaps you want to find all references to something, you can use this command:

Man -K "term to search for"

Where it says "search term", you must enter the term you want to find. For example, to find all man pages containing the string "eraseDisk", use the following syntax:

Man -K "eraseDisk"

It will give you the following result:

Man -K "eraseDisk" /usr/share/man/man3/Common Crypto.3cc? [ynq] n /usr/share/man/man8/diskutil.8? [ynq] and

Press the return key and it will immediately start searching for all man pages in /usr/share/man/* and when a match is found, you will be shown a report offering the corresponding man page which you can accept with 'y' or decline with 'n' (or exit with 'q')

Search the current page for matches:

Once you're on a page, you might want to search within it for a matching string. This is done with /:

/ «search term»

Example for the launchd manual:

/LaunchAgents

Any syntax matches on the current page will be highlighted. You can then navigate between matches using Shift + n.

search-man-page-string-match-610x358

Three tricks to remember a search term when you're inside a manual page:

  • / «»search term»» – finds matches for a “search string” in the current Man page”
  • n – goes to the next match
  • Shift + n – goes to the previous match