Command Line – How to Search Through a Man Page

command linegrepmanpagepipe

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?

Best Answer

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: