Wednesday, August 17, 2011

Man Pages on Linux

Man pages are manual pages about programs, utilities and functions usually with their names. They can be seen by "man" command. Man pages are very useful and easier to access than the searching web or other documentation materials. In most Linux distributions they are located at /usr/share/man directory includes directories for each level with level number suffix.

        ls /usr/share/man

When you install your Linux system GNUX/Linux programs and utilities related manpages are installed by default. You can check this with your package manager; below is command for debian based distributions:

        aptitude search manpages

Most probably you already have manpages package, if you don't have you can install and test it for basic "ls" command as below:

        aptitude install manpages
        man ls

There are other man pages about C library, Posix standard libraries and kernel sources functions. You can install these man pages with your package manager except kernel man pages. You have to use kernel source codes to generate man pages for kernel functions. Lets check C and Posix man pages:

        aptitude install manpages-dev manpages-posix manpages-posix-dev

You can test installation for fopen() libc function and socket() posix function as below:

        man fopen
        man pthread_create

Sometimes there can be a command or tool with name of library functions. For examples there is a standard C library function exit() and also there is a built-in exit command. You can also check open, login, time etc. To see all man pages about a keyword you can use -a option with man:

        man -a time

There are also man pages for standard c++ library elements. In order to get those manual pages we should install libstdc++ document packages which suitable with your c++ version.

       aptitude install libstdc++6-4.4-doc

Let's see manual of map template and string class in c++:

       man map
       man -a string

For kernel man pages, you should have kernel source codes. If you do not have, check your kernel version with "uname -r" command and download from site. Usually kernel sources located under /usr/src directory. Untar kernel source package into /usr/src. Then enter top directory and use make to create and install kernel man pages to your system.

        sudo tar xjvf linux-2.6.32.tar.bz2 -C /usr/src/
        cd /usr/src/linux-2.6.32
        make help
        sudo make mandocs
        sudo make installmandocs

At this point, kernel man pages should be created and installed to your system by make from kernel source codes. Kernel man pages level is 9 and mostly located on /usr/local/share/man/man9/ directory. Now time to test, for example you can check kernel side print function as below:

        man printk

By the way, you can update your man pages index caches as command below:

        sudo mandb -c

Now you are completely ready to develop on Linux :)

1 comment: