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:


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

3 Answers 3


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.

  • 1
    Great, if you could upvote and accept my answer that'd be appreciated :)
    – Crypteya
    Feb 1, 2019 at 4:46

The result of the search - the man page source files on the system - can be passed back to man in local mode to read each page.

man -wK --regex 'Brace Expansion' | sort -u | xargs man -l -P cat | grep -inF 'Brace Expansion'

The regex used for the man command search is case-insensitive by default. The list of results from the search is sorted and any duplicates are removed. Then, it is passed back to man using xargs. By using the cat pager, each processed man page can be printed to the standard output. At that point, the data is a stream of plain text on which grep can operate.

The -l option of man is used to activate local mode, where it parses a file directly instead of parsing the system's MANPATH.

The -P cat option of man sets the pager to cat. This means the processed man page will be displayed using cat.

The -i option of grep is used for case-insensitive search. The -n option prints out line numbers (simply added for convenience). The -F option specifies that the pattern is a fixed string.


Taken your original question following command will show you all the lines containing "braces expansion" in the bash man pages:

for page in $( man -k bash | awk '{print $1}' ); do
    zgrep -i -n  'brace expansion' $(man -w $page) /dev/null

Firstly you got a list of man pages corresponding to "bash" in their description, thereafter you iterate through the retrieved list and searching for matching 'brace expansion' string. zgrep(1) will silently uncompress files for you ;)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .