36

Is there a way to search man pages case-insensitively? Using the '/' search feature matches exact case.

FazJaxton
  • 896
  • 8
    There is no such thing like “search in man page”. Actually it is search in the pager which displays the man page. Depends on the man implementation you use and the pager you prefer, but I have export MANPAGER='less -I'. – manatwork Nov 15 '13 at 15:58
  • 1
    @manatwork's point is that -I means --IGNORE-CASE, even if the pattern contains uppercase letters, see man less. – terdon Nov 15 '13 at 16:19

4 Answers4

36

When no other pager is specified, man uses less to display man pages.

The other answers that involve changing the pager command line are correct, but you can also type -i while less is running. From the less man page:

- Followed by one of the command line option letters (see OPTIONS below), this will change the setting of that option and print a message describing the new setting.

So typing -i while in less changes the setting in the same way that specifying it on the command line would. I got the hint that this would work from How do you do a case insensitive search using a pattern modifier using less, then found the explanation in the man page.

FazJaxton
  • 896
19

Only if you use caps, not if you just use lower case letters. For example, run man bash and try:

  • /invoc <== case insensitive
  • /Invoc <== case sensitive
  • /INVOC <== case sensitive

As @manatwork poited out in the comments, you can also control this behavior by adding export MANPAGER='less -I' to your ~/.profile. The MANPAGER variable defines which program is used with the man command. The -Imeans (from man less):

   -I or --IGNORE-CASE
          Like -i, but searches ignore case even if the  pattern  contains
          uppercase letters.

Other relevant options are (this one is usually on by default):

   -i or --ignore-case
          Causes searches to ignore case; that is, uppercase and lowercase
          are  considered identical.  This option is ignored if any upper‐
          case letters appear in the search pattern; in other words, if  a
          pattern  contains  uppercase  letters, then that search does not
          ignore case.

So, if you export MANPAGER="less -I"; man bash, you should be able to search for /iNvOc in a case-insensitive way.

terdon
  • 242,166
1

Since it comes up as the first result on Google, I want to also add that if you start using Most as your pager, your search will be case-insensitive by default. It also adds a few more capabilities like coloring man pages and backward search.

To install, use the package manager of your distribution and the package name is "most" everywhere (e.g.: apt install most). Then in the startup file of your shell, e.g., in ~/.bashrc add the environment variable:

export PAGER="most"

Don't forget to replace the shell process with a new one so that it can read it (e.g.: exec bash).

Also to make it case-sensitive (notice: opposite of what the OP has asked for, but the reason I came here :) ) use the -c option:

export PAGER="most -c"
aderchox
  • 691
1

Through the env variable LESS:

LESS=-I man less

You can also include the search string at once:

LESS=-I\ +/escape\ key man less

Or:

LESS='-I +/escape key' man less

Even more complex constructions:

LESS=+G?[+]cmd man less

+G - go to the end of the page
? - search backward
[+] - deprive the special meaning of the character +
That is, we are looking for '+cmd' from the end of the man less.

It is very convenient when you need to show a specific place in the manual instead of quoting:

LESS=-I\ +8?lesskey man less

+8? - Eighth match from the end

nezabudka
  • 2,428
  • 6
  • 15
  • This is the best answer IMHO. In your shell’s startup config file, do this: export LESS='--IGNORE-CASE'

    Or in Fish Shell, run: set -Ux LESS '--IGNORE-CASE'

    – Carl Winbäck Dec 13 '22 at 08:04