In this episode, I want to look at how we can use the man command to view manual pages for various commands, configuration files, and system libraries. So, what is the man command and how do we use it? Well, lets run man at the terminal without any options or arguments.
You will see that is says, what man page to do you want? So, lets say we wanted to look at the manual page for the ls command, lets type man ls, and here we are presented with the manual page for the ls command.
You will notice down at the bottom there is some text highlighted, if you need to access the help page, you can hit the letter h, or if you want to quit, hit q, you can also navigate around these manual pages by using the up and down arrow keys, or just page up and page down.
That is the man command in the nutshell, but I wanted to show you a couple other features too. Lets take a look at the manual page for the man command, by running man man. The one thing I wanted to highlight is that there are different manual pages for user and admin commands, configuration files, and system libraries, amongst other things. This is talked about down here, and each of these different types of man pages are identified by a given section number.
So, for example, section 1 covers common user land commands, things like ls, and the man commands. If you are going to be programming something, sections 2 and 3 might come in handy, as they cover system, and library calls. Section 5 talks about configuration files, and section 8, is for sysadmin type commands. The reason I wanted to highlight man page sections is because you could look at a manual page, and not know that there is actually additional information available, just under a different section.
Lets scroll down at bit and look at the examples, we already covered this example, where we looked at the ls manual page. One helpful option, is using the dash k switch to search man page descriptions. This can be really useful for finding manual pages.
Lets say we wanted to search all man page descriptions for anything about the passwd command. Lets run man dash k passwd, and we are returned a listing of the results matching our query.
man -k passwd
You will notice part way down here, that we have several entries for the passwd command.
This first entry with the 1 beside it, denotes this is the manual for the section number 1. Lets jump back to the manual page for man command, where we talked about sections, for a minute. So, the 1 indicated in our search results means this is the manual page for section number 1, and section 1 deal with executable programs or shell commands. Jumping back to our search results, lets have a look at the passwd entry with the number 5 beside it, where is says the password file. Again, lets quickly jump back to the manual page for man command, where we talked about sections. Section number 5 talks about file formats and conventions, basically, the syntax of configuration files.
Okay, so now that we know what the search results mean, how do you use these different manual page sections in practice? Well, by default, when you run the man command, you are always given the first manual page section that exists.
Lets run man passwd, you will see we are given the manual page for the passwd command, which can be used to change a users password. You will also notice up in the left hand corner it says, passwd 1, this indicates, that it is the manual page section number 1. Lets quit and head back to the terminal.
So, you might be wondering how we view the different manual page sections? For example, the passwd configuration file manual page. Well, we just need to pass the section number to the man command. In the previous command, we just type man passwd, but we could have typed man 1 passwd, this tells man to give us section number 1 for the password command.
So, lets just replace the 1 here, with 5, to indicate to the man command that we want to manual page for section 5 of the passwd command. We are now given the password configuration file manual page. You will also notice, that in the upper left hand corner, it now says password 5, to indicate what section we are looking at.
man 1 passwd man 5 passwd
So, hopefully you know a little bit more about the man command, at least enough, that you can look up the various manual pages. The search function is also really handy, in that you might just type man passwd, and not know that there is actually a man page for the configuration file too. Keep and eye out for these handy manual page sections.