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?
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).
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?
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.
man -k.
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.
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
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/
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
to jump to a single section and open the manpage there:
m()
{
PAGER="cat" man "$1"|grep --color=auto ^\\w|sed '1d;$d'
echo
read -p"enter section here> " -r
LESS="+/^${REPLY}" man "$1"
}
m grep
$ m grep
NAME
SYNOPSIS
DESCRIPTION
OPTIONS
REGULAR EXPRESSIONS
EXIT STATUS
ENVIRONMENT
NOTES
COPYRIGHT
BUGS
EXAMPLE
SEE ALSO
enter section here>
to have it a bit more interactively... this will open a dialog(1) TUI you can navigate in: (only tested on ubuntu)
ms() {
dpkg -s dialog &>/dev/null || { echo "Needs 'dialog' package which is not installed on this system!" && return; }
[[ $# -lt 1 ]] && echo 'Man page name consisting of a single word expected but not given.' && return
MANPAGE=$1
[[ -n $2 ]] && DEFAULTCHOICE=$2 || DEFAULTCHOICE='0'
man "${MANPAGE}" > /dev/null 2>&1 || { echo "${MANPAGE}" man page not present on this system!; return; }
mapfile -t OUTLINE < <(PAGER="cat" man "${MANPAGE}" | grep ^\\w | grep -v -e AUTHORS -e COPYRIGHT | sed '1d;$d')
RESULTSIZE="${#OUTLINE[*]}"
# shellcheck disable=SC2046
CHOICE=$(
dialog --colors --keep-tite --default-item "$DEFAULTCHOICE" --menu "$(
echo -n \\Zb\\Z3 "${MANPAGE}" | tr '[:lower:]' '[:upper:]'
) man page" $(( RESULTSIZE + 8 )) 55 "${RESULTSIZE}" $(
COUNT=0
for i in $( seq 0 $(( ${#OUTLINE[@]} - 1 )) )
do
echo -n "${COUNT}"
# shellcheck disable=SC2001
echo -n " $( echo "${OUTLINE[i]}" | sed 's/ /\_/g' ) "
(( COUNT++ ))
done
) 2>&1 >/dev/tty || echo CANCEL
)
[[ "$CHOICE" =~ "CANCEL" ]] && return
# shellcheck disable=SC2001
MANPAGER="less +/^$( echo "${OUTLINE[$CHOICE]}" | sed 's/ /\\ /g' )" man "${MANPAGE}"
m "${MANPAGE}" "${CHOICE}"
}
ms grep
man manand not about an overview over all sections within a particular manpage. i will leave my answer in here anyway, which answers the latter question. unix.stackexchange.com/a/731856/21880