How to search for a string from all the man pages

grepmanstring

What command would show all lines containing the string “brace expansion” (ignoring case) in the man pages for Bash?

I tried man -wK . | grep "[Bb]race [Ee]xpansion" I have got series of "couldn't break line" errors.

Then I tried to search using the command man -s1 -Kw --regex 'brace expansion' after reading the query in How to search a pattern containing hyphens inside man pages?

I got back:

/usr/share/man/man1/bash.1.gz 

I tried to print the file using cat and got all the weird symbols.

Best Answer

When you run the command man bash you are opening the documentation in the system's default pager (usually less). To skip to lines matching a particular pattern, you can type /<pattern>. For example, immediately after entering the man page type in:

/brace expansion

You should then be automatically taken to the first occurrence. From there you can press n to be taken to later occurrences.

Also the .gz file extension means that the file is compressed using gzip. You will not be able to read this file directly.