To search man pages in the macOS Terminal, use the man -k command followed by a keyword, or press / inside an open man page to search within that page. This guide covers both methods, plus how to search by section, use regular expressions, and handle common issues.
What Are Man Pages?
Man pages (short for manual pages) are the built-in documentation for Unix-like operating systems, including macOS. They describe commands, system calls, configuration files, and library functions. Each page is organized into sections (1-9) covering different topics, such as user commands (section 1), system calls (section 2), and file formats (section 5).
In macOS, man pages are stored in /usr/share/man and are accessed via the man command. They are essential for developers, system administrators, and anyone using the Terminal, as they provide authoritative reference material without needing an internet connection.
Basic Search: man -k
The most common way to search man pages is using the -k option, which performs a keyword search across all man page names and descriptions. The syntax is:
man -k keyword
For example, to find all man pages related to “copy”, you would run:
man -k copy
This returns a list of pages that match, such as cp(1), rsync(1), and ditto(1). The number in parentheses indicates the man page section.
You can also use apropos, which is equivalent to man -k. Both search the same database and produce identical results.
Searching Within a Man Page
Once you have opened a man page with man command, you can search for text within that page. Press / to enter search mode, type your query, and press Enter. The page will jump to the first match. Use n to go to the next match and N to go back to the previous one.
For example, if you are reading man grep and want to find the option for case-insensitive search, press /, type ignore-case, and press Enter. The page will scroll to the relevant section.
Using man -f for Exact Name Matches
If you know the exact name of a command or file, use man -f (or whatis) to get a one-line summary. This is faster than opening the full page and is useful for quickly confirming what a command does.
man -f ls
This outputs something like ls(1) - list directory contents. It is a quick way to verify the purpose of a command without reading the entire manual.
Advanced Search with Regular Expressions
For more precise searches, you can use regular expressions with man -k by enclosing the pattern in quotes. For instance, to find all pages related to “network” or “networking”, you could run:
man -k 'net'
This matches any description containing “net”, including “network”, “netstat”, etc. You can also use anchors: man -k '^net' matches only descriptions starting with “net”.
Be careful with special characters; use \ to escape them if needed. For example, to search for a literal period, use man -k '\\.'.
Searching by Section
Man pages are organized into sections, and you can limit your search to a specific section using the -s option. For example, to search only in section 2 (system calls), run:
man -k -s 2 read
This returns only system calls related to “read”, such as read(2) and readv(2). This is helpful when you are looking for a programming interface rather than a user command.
Common Problems and Fixes
If man -k returns “nothing appropriate”, it may mean the man page index is outdated. You can rebuild it with:
sudo /usr/libexec/makewhatis
If you get “command not found” for man, ensure Xcode Command Line Tools are installed. Run xcode-select --install and follow the prompts.
Another issue is that man -k only searches the name and description, not the full text. To search the full text of all man pages, you can use grep on the raw files:
grep -r "pattern" /usr/share/man
This is slower but finds matches inside the pages.
Alternatives to man -k
Third-party tools like tldr provide simplified, example-based documentation. You can install it with brew install tldr (requires Homebrew). It is not a replacement for man pages but is useful for quick reference.
For GUI-based browsing, you can open man pages in the macOS Help Viewer with man -H command, which renders the page in a more readable format.
Frequently Asked Questions
How do I search man pages for a specific option?
Open the man page (man command) and press / followed by the option name, then Enter. For example, to find the -r option in man cp, type /-r and press Enter. Use n and N to cycle through matches.
What is the difference between man -k and apropos?
There is no difference; apropos is an alias for man -k. Both search the man page database for keywords in names and descriptions.
Can I search man pages for a command I only partially remember?
Yes, use man -k with a partial name. For example, man -k 'zip' finds all pages with “zip” in the name or description, including zip(1), unzip(1), and gzip(1).
Why does man -k return nothing for a known command?
This usually happens if the man page index is outdated. Run sudo /usr/libexec/makewhatis to rebuild it. If the command is not installed, its man page will not be present.
How do I search man pages in a specific section?
Use the -s option with man -k, for example man -k -s 3 printf to search only section 3 (library functions).
Is there a way to search full text of all man pages?
Yes, use grep -r "pattern" /usr/share/man. This searches the raw man page files, which may be compressed. Use zgrep if the files are gzipped (they often are on macOS).
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Data Center Location Questions for AI Workloads
- How to Choose an Amplifier for Magico A3 Speakers
- How to Ban a Player from Your FiveM Server
- Pokemon Go Friend Codes: How to Add & Use Them33.33 XP/day
- Google Algorithm Change: Original Reporting Boost
- Create Folder for Selected Item on Mac: Full Guide