How to search through a man page?

I often want to search through a man page, however I am forced to either do:

man <package> | grep <search>

Or:

man <package> > file.txt

But there must be an easier way than this to do this, so how can I search through a man page while in it instead of having to send its contents to a file, or use grep to print the necessary matching contents to standard output?


Solution 1:

While you can pipe man's output just fine, know that you can search within man as well. man uses less as the pager by default, and within less, you can:

  • press / and enter the text you wanted to search for
  • press n to go the next search result and N to go the previous search result
  • press g to go to the top (since the search doesn't wrap around by default)

Also see:

  • Tricks and tips for finding information in man pages

Solution 2:

This will work if you specify which man page you want. For example, if you want to look up any information to do with "version" on the ls command, you could type:

man ls | grep version

which will return the matches of "version" from the ls man pages.

Solution 3:

You can read man pages in emacs, with ESCxm a n, and leave the opened man page in an invisible, "buried" buffer for later re-use.