We often have to find a solution to a Linux problem quickly – if we do not have access to the internet, or we need to solve the problem in a very short time.
Let’s suppose you’ve just decided to opt out of your shared hosting and you’ve got your first VPS, connected to SSH, and you started configuring it. Below are the ways you can access all the documentation that your Linux distribution has.
Man command
It is probably the best known method by which we can read the manual of a command in Linux; regardless of distribution, the command man command_name shows us how to use it. And if you want to know what man can do, run:
$ man man
If we want to find out which manual page we look for, we run the command apropos along with the word you want; let’s suppose we want to find out more about passwd, and what manual page to open:
$ apropos passwd
The result will be: each page of the manual is accompanied by a brief description.
We can run man 5 passwd to find information about the /etc/passwd file, man 1 passwd to find out how to use the passwd command to change the password, etc.
Often we want to read the manual of a freshly installed command, but the command man does not show us anything except No manual entry for …. We just need to update the man pages database by running the command:
$ mandb
In a Linux distribution, all manual pages are stored in the /usr/share/man/ directory.
Info command
The Info Utility is used to find information about a particular Linux resource – for GNU/Linux documentation; in fact, a lot of documentation has migrated from man to info.
To find out about a command:
$ info command_name
Info command searches in the /usr/share/info directory:
$ ls /usr/share/info
Not all commands have related information in /usr/share/info; if, for example, we run the passwd info command, we will automatically open the man page of the passwd command.
‘Info’ has different information than ‘man’. Navigating inside Info is done using nodes (or sections). In some Info section, to move down one line, or forward, we will use the down arrow key; to go up or back, we will use the up arrow key. If we reached the end of a particular section, the cursor stops.
If we want to go one screen up or down, we will use the PageDown or PageUp keys. Instead of these keys, we can use Backspace or Delete – they offer, in addition to PageUp and PageDown, the advantage that, at the end of a node, it moves on to the next node. To get up to the first node, press the T key. Info command has many shortcuts and it’s almost impossible for someone who occasionally interacts with this message to remember all. Fortunately, simply pressing the H key (SHIFT + h) shows us all the available shortcuts.
If we just write simple the command info, we will see the main info directory containing all the available nodes.
Pressing the Q key, we exit the info tool.
‘Info’ is a particularly useful tool when I forget what it does, how to export or how to use a Linux resource.
The –help parameter
Almost every program can call some help information through the –help or -h parameter:
$ passwd –help
Usage: passwd [OPTION …] <accountName>
-k, –keep-tokens keep non-expired authentication tokens
-d, –delete delete the password for the named account (root only); also removes password
lock if any
-l, – lock the password for the named account (root only)
-u, –unlock unlock the password for the named account (root only)
-e, –expire expires the password for the named account (root only)
-f, –force force operation
-x, –maximum=DAYS maximum password lifetime (root only)
-n, –minimum=DAYS minimum password lifetime (root only)
-w, –warning=DAYS number of days warning users received before password expiration (root only)
-i, –inactive=DAYS number of days after password expiration when an account becomes disabled
(root only)
-S, –status report password status on the named account (root only)
–Stin read new tokens from stdin (root only)
The /usr/share/doc directory
Almost every Linux program comes with its own documentation; this is usually installed in the /usr/share/doc directory.
Other ways to seek help
The command locate – with its help, we can find out not only where a particular program is, but also where its documentation is. Remember that if the program is freshly installed, the updateb database update command must be run.
Command which – displays the absolute path to the executable of a specific program.
Whatis command – displays a man page description on a single line:
$ whatis passwd
passwd (1) – update user’s authentication tokens
openssl-passwd (1ssl) – compute password hashes
passwd (5) – password file
Whereis command – locates on the binary, the source, but also the path to the program’s manual page
$ whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
Let’s suppose that we are in an rpm distribution (Red Hat, Fedora, CentOS …). As most programs have been installed from rpm packets, we can use this command to find out the path to the command’s documentation in seconds (q-query, d-documentation);
$ rpm -qd command_name
Example:
$ rpm -qd passwd
/usr/share/doc/passwd/AUTHORS
/usr/share/doc/passwd/ChangeLog
/usr/share/doc/passwd/NEWS
/usr/share/man/ja/man1/passwd.1.gz
/usr/share/man/man1/passwd.1.gz
Let’s recap:
• Linux keeps the documentation in /usr/share/man, /usr/share/doc and /usr/share/info
• the main commands with which we can get help are: man […], info […] or the parameters […] -h, […] –help
• helpful commands: apropos, which, whatis, whereis, rpm -qd