The man
command, is used to display a man page . It takes the name of the manual page to display, which is usually the same as the name of a command, or a function, or a special device… By default man
is case insensitive.
debian:~$ man # When no manual page is supplied # to man, it will display a similar # message: What manual page do you want? debian:~$ man echo # Display the echo command, # manual page, which is located # in: # /usr/share/man/man1/echo.1.gz debian:$ man -l /usr/share/man/man1/echo.1.gz # The -l option specify the # location of a manual page, # that should be opened. debian:~$ man random.3 # The section of the manual # where the man page is to # be found, can be also be # specified, by using # (man page name)[.section] # So this command will open # the random manual page, in # section 3 of the manual.
The location of where the manual, or a manual page is, can be gotten by using the -w
option.
debian:~$ man -w # display where electronically # the user manual is stored. /usr/local/man:/usr/local/share/man:/usr/share/man # /usr/local/man # /usr/local/share/man # /usr/share/man debian:~$ man -w echo # display where the echo # man page is stored. /usr/share/man/man1/echo.1.gz
man
can be provided with the name of more than one manual page, to search for, and to display. By default man
searches, in an exact manner.
When a pair of manual page names are provided, man
searches for a manual page, which is formed of the first name, joined to the second one by a hyphen, or an underscore. If such a page is not found, man
then will search separately, for a manual page, with the first, or the second provided names.
The subpage option is used, because sometimes some programs have subcommands, and this allows to provide manual pages, to these subcommands, in a manner similar to the way they are invoked. The man
command, subpage behaviour, can be disabled, by using the --no-subpages
option.
debian:~$ man -w update grub # Search for update grab man # pages. # By default man will join these # two words using either a hyphen # or an underscore, and it will try # to search for the manual page named # update-grub or update_grub . /usr/share/man/man8/update-grub.8.gz # The update-grub man page was found. # Since the -w option was used, man will # print the location of this man page. debian:~$ man ls pwd # if man does not find the manual # page ls-pwd or the manual page # ls_pwd, then it will search for # the manual pages ls , and pwd # and display them LS(1) User Commands LS(1) ... # First it will display the manual page, # of the ls command. --Man-- next: pwd(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ] # Next it will display the manual page, # of the pwd command, which can be viewed, # by pressing return, or it can be skipped # by using Ctrl-D, or the found manual pages # can be quit using Ctrl-C. debian:~$ man -w --no-subpages update grub # The subpage behaviour can be disabled, # by using the: # --no-subpages option. # In this case man will search for # the update manual page, and for # the grub manual page. # it didn't find any, hence it # displays: No manual entry for update No manual entry for grub
The -a
option can be used to display all the found manual pages, and not just the first one.
debian:~$ man -a random # The -a option, can be used to # display all the found manual # pages. # The first found random manual # page, is under section 3. RANDOM(3) Linux Programmer s Manual RANDOM(3) --Man-- next: random(4) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ] # after quitting the first manual # page, man will show the option # to view the other found manual # pages. # In this case, there is a random # manual page under section 4. # It can be viewed by pressing enter, # it can be skipped by using control + D # and to stop viewing the found manual # pages, control+ C can be used. --Man-- next: random(7) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ] # Another random man page, is found # under section 7 of the manual.
To search for manual pages, man
uses the mandb
database. The manual can have pages with the same name, under different sections, the manpath.config
file, is used by man
, to determine the search and display order, of the manual sections.
The -s
option of man
, can be used to override the sections search order, set in the manpath.config
file, and to specify the manual sections, under which search is to be performed.
debian:~$ cat /etc/manpath.config | grep '^SECTION' # print the manpath.config file, # and pipe the output to the grep # command, which searches for the # lines that begin with the word # SECTION, this outputs: SECTION 1 n l 8 3 2 3posix 3pm 3perl 3am 5 4 9 6 7 # The order under which the # sections of the manual pages # will be searched and displayed, # is as such: # 1 N L 8 3 2 3posix .... debian:~$ man random # man will display the random # manual page, under section 3 # of the manual, because # the default search and display # order is: # 1 n l 8 3 2 3posix 3pm 3perl 3am 5 4 9 6 7 RANDOM(3) Linux Programmer s Manual RANDOM(3) debian:~$ man -s 7,4,3 random # The -s option, sets the order under # which manual pages, are searched # and displayed to 7,4,3, hence # the man.7 manual page is displayed. RANDOM(7) Linux Programmer s Manual RANDOM(7) debian:~$ man -s 8 random # Only section 8 is to be searched # for the random man page. No manual entry for random
The --regex
and --wildcard
options, can be used with the man
command.
When --regex
is used, regular expression search is performed, and the page name token, can partially match, the description, or the name of a man page, in the mandb
database.
When --wildcard
is used, the page name token, can contain shell wildcards, as in ?
, the wildcards are expanded, and the token after expansion, must fully match the name of the page, or it must match the page description, on word boundaries.
If the --names-only
option is used with either --regex
or --wildcard
, then only the name in the mandb
database is matched, as explained earlier.
debian:~$ man --regex ls # since --regex is used, regular # expression search is used, and # ls can partially match the name # or the description fields, in the # mandb database. LS(1) User Commands LS(1) # The first found manual page, is # the ls manual page. --Man-- next: systemd-cgls(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ] # Once the ls.1 manual page, is quit, # the man command will display other # found manual pages, which can be # viewed, or skipped, or man can be # exited. --Man-- next: md5sum.textutils(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ] --Man-- next: gvfs-ls(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ] ^C # quit man using Ctrl-C debian:~$ man -w --wildcard --no-subpages tune who # The --wildcard option is used, # hence the tokens are expanded, # if they contain any wildcards, # and the gotten tokens must # fully match the name, or match # on word boundary the description, # fields in the mandb database. # The -w option is used, hence the # location of the man pages is to # be displayed. # The --no-subpages option is used, # hence tune and who are treated # separately, and not as tune-who # or tune_who. /usr/share/man/man2/adjtimex.2.gz /usr/share/man/man2/bdflush.2.gz /usr/share/man/man1/who.1.gz /usr/share/man/man1/bsd-from.1.gz /usr/share/man/man1/w.procps.1.gz debian:~$ man --regex --names-only -w 'seek' # Since the --names-only option # is used, only manual pages names, # containing the token seek, are # searched for in the mandb database. /usr/share/man/man3/fseek.3.gz /usr/share/man/man3/fseeko.3.gz /usr/share/man/man3/lseek64.3.gz /usr/share/man/man3/seekdir.3.gz /usr/share/man/man2/llseek.2.gz /usr/share/man/man2/lseek.2.gz debian:~$ man --wildcard --no-subpages --names-only -w 'seek' '?seek' # Search using --wildcard, only # the names in the mandb database, # and do not use the subpages # options. # The search is done for the tokens # 'seek' or '?seek'. # The tokens after expansion must # fully match the name in the mandb # database. # The expansion of the token seek is # seek, and the expansion of the token # ?seek is one character followed # by seek. No manual entry for seek /usr/share/man/man3/fseek.3.gz /usr/share/man/man2/lseek.2.gz # No manual entries were found for # the seek token, whereas for the # ?seek token, two matches were # found.
The -K
option, can be used to search the manual pages source code, and not the formatted output, for a string.
--regex
can be used with the -K
option, to allow to perform regular expression search, of the non formatted manual pages, source files.
If what is desirable is that for the string, or regular expression, to be searched in a case sensitive way, then the -I
option can be used. By default search is performed, in a case insensitive manner.
debian:~$ man -K -s 1 'Display the name and percentage reduction for each file compressed.' # use the -K option to search for # the string: # 'Display the name ...' # Limit the search to section 1. # Search is performed in a case # insensitive manner. ZNEW(1) General Commands Manual ZNEW(1) # Only one result is found, and # is displayed. debian:~$ man -K -s 1 'mplies' # Use the -K option to search for # the string 'mplies', which is # to be found in the source code, # of manual pages, stored under # the section 1 of the manual. BASH(1) General Commands Manual BASH(1) # man will display the found # results, the first found manual # page is the bash manual page. --Man-- next: groff(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ] # The next one, is the one of groff, # which can be either viewed or skiped, # or the man program can be exited. debian:~$ man -K -s 1 'EXIT OPEN' # use the -K option, to search # the source code of section 1 # manual pages, for the string # 'EXIT OPEN' # in a case insensitive manner. No manual entry for exit open debian:~$ man -K --regex -s 1 'EXIT.*OPEN' # use the -k option with --regex, # to perform a regular expression # search, for 'EXIT.*OPEN', in a # case insensitive manner. # The search is limited to section # 1 of the manual. APLAY(1) General Commands Manual APLAY(1) # The next found manual page, is the # one of arecord, which can be viewed # or skipped or quit. --Man-- next: arecord(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ] debian:~$ man -K --regex -I -s 1 'EXIT.*OPEN' # use the -K option with --regex, # to perform a regular expression # search, for 'EXIT.*OPEN'. # The search is done in a case # sensitive manner, since -I is # used, and only the section 1 of # the manual, is searched in. No manual entry for EXIT.*OPEN
When the -f
option is used with man
, man
acts as whatis , meaning it can be used to display a short description of a command, or of a function call…
debian:~$ man -f ls # use man with the -f option, # to display the description # of the ls command. ls (1) - list directory contents
The -k
option can be used to make man
work as apropos , meaning to search for a token, and display its description.
debian:~$ man -k -s 2 'rename$' # Use man with the -k option, # to search the name and description # fields, of the mandb database, # for the rename$ token, using # regular expression. # Only section 2 of the manual is # searched, and a description, # of what is found is displayed. rename (2) - change the name or location of a file