How to Search Man Pages at the Command Line
Command line users are undoubtedly familiar with man pages, or manual pages, that contain details, help, and documentation to specified commands and functions. Referencing a man page can be essential when trying to learn proper syntax or how a command works, but with how large some manual pages are it can be a real drag to scroll through the entire man page to try and find a relevant portion. Additionally sometimes you just don’t know exactly which manual page you should look for relevant data for. Fortunately there are two search tools to search man pages and quickly find and access exactly what you’re looking for, whether finding and matching a string or search term in a currently active man page or by searching all manual pages for a match.
Searching man pages works the same in just about any unix based command line, whether it’s Mac OS, Linux, BSD, or whatever else. Here’s how it works:
How to Search All Man Pages for a String Match
If you want to find something about a general command, function, or feature, but you aren’t certain which man page the data will be in, or perhaps you just want to find all references to something, you an use a broad string match to search every single manual page on the computer for all matches:
man -K "String"
Note the flag is a capital -K, the string can be anything. For example, to find all manual pages that contain the string “eraseDisk” you’d use the syntax:
man -K "eraseDisk"
/usr/share/man/man3/Common Crypto.3cc? [ynq] n
/usr/share/man/man8/diskutil.8? [ynq] y
Hitting return will immediately start searching all manual pages found in /usr/share/man/* and when a match is found reports back, offering the matching manual page to you which you can accept with ‘y’ or dismiss with ‘n’ (or quit with ‘q’)
If you’re a Terminal.app user on the Mac, you’ll find the -K flag is similar to using the right-click search Man Index trick we discussed here, except it’s done entirely from the command line and requires no mouse or cursor interaction.
Search in Current Manual Page for Matches
Once you’re in a manual page, you may want to search within the currently open man page for a string match as well. That’s done with / like so:
/ search term
Let’s say we’re in the man page for launchd and you want to find matches for “LaunchAgents” within that manual page. Once you’re in man for launchd (man launchd) you’d use the following:
Any matches to the syntax in the current man page will be highlighted. You can then navigate between matches with n and shift+n.
The three tricks to remember to search once you’re within a man page are:
- / search string – find matches to “search string” in current man page”
- n – go to next match
- shift + n – go to prior match
Remember these tips the next time you’re sorting through manual pages at the command line. And for those who use Terminal app, remember you can also search and launch manual pages from the Terminal Help menu directly, which would then allow you to use the aforementioned string search to look within a help doc to get further details.
Know of some other manual page search tricks? Let us know in the comments.