Showing posts with label manpages. Show all posts
Showing posts with label manpages. Show all posts

Sunday, November 18, 2012

Colorful Man Pages


    Manual pages are the most important documentation sources for developers. They are not useful only for linux commands but also for c/c++ functions and structures ever for kernel source codes'. In almost every linux distribution, pager is linked to "less" by default so that when an application needs to show output page to page on terminal, "less" is used. However "less" does not give a colorful output.

    If you want to see pages colorful which makes more readable, you can use "most" for that. Link your "pager" to the "most" instead of "less".

   Check your current pager:


        kays@debian:~$ update-alternatives --display pager
        pager - auto mode
          link currently points to /bin/less
        /bin/less - priority 77
          slave pager.1.gz: /usr/share/man/man1/less.1.gz
        /bin/more - priority 50
          slave pager.1.gz: /usr/share/man/man1/more.1.gz
        /usr/bin/pg - priority 10
          slave pager.1.gz: /usr/share/man/man1/pg.1.gz
        /usr/bin/w3m - priority 25
          slave pager.1.gz: /usr/share/man/man1/w3m.1.gz
        Current 'best' version is '/bin/less'.

   "less" is current pager. Install "most" package and make it your default pager as below:

        kays@debian:~$ sudo aptitude install most
        kays@debian:~$ sudo update-alternatives --install /usr/bin/pager pager /usr/bin/most 99

   You can use "--config" options as below by doing interactively:

        kays@debian:~$ sudo update-alternatives --config pager

   Now test your pager. Below is "socket" function manual page.

man socket


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 kernel.org 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 :)