7

I am thinking about the man page sections 1 = user commands, 2 = system calls etc.

Is there a way, a command that will tell me what sections are available to read besides running something like man 1 gedit, man 2 gedit, man 3 gedit etc?

6

One option:

apropos fork

to limit to exact word:

apropos -e fork

Alternatively, as apropos uses regex by default:

apropos "^fork$"

Alternatively use man -k instead of apropos.

Check out man pages for apropos and man for more details.

| improve this answer | |
  • BTW, if you are using Cygwin, you may not find much output with man -k. – smwikipedia Jul 22 '19 at 1:29
  • I don't understand it. If I use man fork, I see a man page for the syscall fork (manpage FORK(2)). If I use apropos "^fork$", I get nothing appropriate. If I use apropos fork, I get a listing with commands like pearlfork(1), spfd(1) and others, but not exaclty fork. By the way, I came to this answer trying to listman pages for cc, and I was having the same results (getting a man page for man cc, but not listing any man pages for exactly cc with man -k cc). Btw, I'm on Mac OS X, not sure if it is relevant. – Rafael Eyng Jan 5 at 13:31
11

With the man from man-db at least:

$ man -f open
open (2)             - open and possibly create a file
open (1)             - start a program on a new virtual terminal (VT).
open (3tcl)          - Open a file-based or command pipeline channel
open (3perl)         - perl pragma to set default PerlIO layers for input and output

Same as:

$ whatis open
open (2)             - open and possibly create a file
open (1)             - start a program on a new virtual terminal (VT).
open (3tcl)          - Open a file-based or command pipeline channel
open (3perl)         - perl pragma to set default PerlIO layers for input and output

Or to get the paths of the man pages:

$ man -wa open
/usr/share/man/man1/openvt.1.gz
/usr/share/man/man3/open.3tcl.gz
/usr/share/man/man2/open.2.gz
/usr/share/man/man3/open.3perl.gz

To read all the man pages on a given topic, man -a is very common.

Note however that some implementations run one instance of the pager for each man page (you need to quit the pager to get to the next man page and there's no coming back), while some others pass the man pages as separate arguments to a single pager invocation (and you use :n, :p for instance with the less pager to navigate through the pages).

| improve this answer | |
  • man -wa open was the only useful one in Mac OS X. How to open an specific man page, though? I mean, I know I can do man 3 open, but how to diferentiate between /usr/share/man/man3/open.3tcl.gz and /usr/share/man/man3/open.3perl.gz in your example? And why does it even make sense to have two entries for man 3 open? – Rafael Eyng Jan 5 at 13:36
2

If you're man is from the "man-db" package, you can invoke this to see the "intro" page for each section of the manual:

man -a intro

If you know the location of the man pages database, this will list all of the section directories (man1, man2, man3, etc):

(cd /usr/share/man; ls -d man*)

Also if using man from the man-db package, you can see the location of the man pages database(s) by invoking man -w (this option also exists on FreeBSD man, but I don't have it installed so I don't know if it gives the same output). For example, on Debian 8 (jessie):

$ man -w
/usr/local/man:/usr/local/share/man:/usr/share/man

Using man -w, a simple script to list all of the section numbers available in all of the man database directories would be:

#!/bin/sh
IFS=":$IFS"
for i in $(man -w)
do
    (
        cd "$i"
        for j in man*
        do
            if [ -d "$j" ]
            then
                echo "${j#man}"
            fi
        done
    )
done | sort -u
| improve this answer | |
  • "If you're man is from the "man-db" package" -> how do I know wheter it is or not? – Rafael Eyng Dec 11 '19 at 21:30
2

I use my package manager to do this kind of stuff.

On Archlinux:

pacman -Ql gedit | grep /man/

RH/Fedora:

dnf repoquery -l gedit | grep /man/

Debian/Ubuntu/...

dpkg-query -L gedit | grep /man/
| improve this answer | |
1

The following command should list all available man page sections for a given command:

find /usr/share/man -name "<command>.*.gz" | egrep -o '[0-9]' | sort -u
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.