How to effectively use the man pages?

I am looking forward to mastering linux. I have been repeatedly told to refer to man pages when you are in doubt.

Though I am very comfortable with the commandline, I find it very difficult to quickly and efficiently use man to find help with commands. Hence I end up googling up how to get things done. It is even more painful when the system I am using does not have internet access and I have to walk back to my office to get help from the internet.

How does one master man pages? What are the most common tricks that can be used to quickly get whatever you want from the man page? What are the most commonly used keyboard shortcuts?


Solution 1:

Manual pages are essentially glorified help files. Their goal is to explain what programs do, and how to alter what they do through command-line flags and arguments.

If you look at the SYNOPSIS and OPTIONS sections of manpages, you will typically be able to understand enough about what your program does.

Don't allow the "technical" wording of manpages to throw you off -- they were typically written by developers in a developer mindset. The more you read/use them, the better you'll get and the more you'll develop your own tricks to using man.

If you press the h key in man, you can get a lot of useful keyboard shortcuts (and general help) that will make your browsing (hopefully) faster. They're similar to the keystrokes for less, so it's essentially a 2-for-1.

And, you can always refer to the manpage for man (man man) to get a quick rundown of man. You can't break man too badly, so just feel free to experiment and try out things.

Solution 2:

I recommend using apropos to help in searching the man files on the system more efficiently.

apropos can either search for everything with a word that matches in it, or you can look for specific by using the -e switch.

Examples below:

terrance@terrance-Linux:~$ apropos reboot
grub-reboot (8)      - set the default boot entry for GRUB, for the next boot...
halt (8)             - Halt, power-off or reboot the machine
poweroff (8)         - Halt, power-off or reboot the machine
reboot (2)           - reboot or enable/disable Ctrl-Alt-Del
reboot (8)           - Halt, power-off or reboot the machine
rescan-scsi-bus.sh (8) - script for adding and removing SCSI devices without ...
shutdown (8)         - Halt, power-off or reboot the machine
systemd-reboot.service (8) - System shutdown logic

or...

terrance@terrance-Linux:~$ apropos -e reboot
halt (8)             - Halt, power-off or reboot the machine
poweroff (8)         - Halt, power-off or reboot the machine
reboot (2)           - reboot or enable/disable Ctrl-Alt-Del
reboot (8)           - Halt, power-off or reboot the machine
shutdown (8)         - Halt, power-off or reboot the machine

As you can see above that I got two different lists of commands resulting from searching for the reboot command. The number in the ( ) is the section number. The command reboot listed with 2 different numbers. Any of the lines where it is not duplicated, only need to do man <command>, no need for the section number.

To open to the section, it would be the following command:

man 2 reboot

Which will return this man page:

REBOOT(2)                  Linux Programmer's Manual                 REBOOT(2)

NAME
       reboot - reboot or enable/disable Ctrl-Alt-Del

SYNOPSIS
       /* For libc4 and libc5 the library call and the system call
          are identical, and since kernel version 2.1.30 there are
          symbolic names LINUX_REBOOT_* for the constants and a
          fourth argument to the call: */

       #include <unistd.h>
       #include <linux/reboot.h>

       int reboot(int magic, int magic2, int cmd, void *arg);

       /* Under glibc and most alternative libc's (including uclibc, dietlibc,
          musl and a few others), some of the constants involved have gotten
          symbolic names RB_*, and the library call is a 1-argument
          wrapper around the 3-argument system call: */

       #include <unistd.h>

or

man 8 reboot

which will return this man page:

HALT(8)                              halt                              HALT(8)

NAME
       halt, poweroff, reboot - Halt, power-off or reboot the machine

SYNOPSIS
       halt [OPTIONS...]

       poweroff [OPTIONS...]

       reboot [OPTIONS...]

DESCRIPTION
       halt, poweroff, reboot may be used to halt, power-off or reboot the
       machine.

OPTIONS
       The following options are understood:

       --help
           Print a short help text and exit.

       --halt

Truncated above examples for space.


Hope this helps!

Solution 3:

One can also use man -k (or apropos) to find man pages that match text in the short description section of a manual, for example:

apropos directory

..will find all the man pages with "directory" in the short description section of the manual.