Sunday, February 17, 2008

Reading the manual

It amazes me that man isn't introduced sooner in most Linux and Unix tutorials and how-to's. It's one of the most important tools to know when learning Linux and Unix. Hopefully if you're reading this and using Linux, you're familiar with it, but if you're not, now is the time.

Practically every command in the Unix world has some documentation called a man page, short for manual page. This is easily accessible online reference documentation. It's not always the most user friendly, but it's the quickest way to see what the typical options for a command are. In order to use the man command, just type man followed by the name of the command you want information on.

$ man man
This will display the man page for the man command. It will first show you a one line description, followed by the synopsis, which is a sample of the command with it's available options. After that will be various sections that can include a longer description, usage examples, in depth descriptions of the options available, and other information about the command.

You may also see articles or references that show something like man(1) or passwd(5). Placing a parenthesized number after a command name is a Unix idiom for referring to a man page. The number refers to the "section" of the man pages (for example, section 1 is for executable commands, while section 5 is for file formats). This is important because there are some things that have more than one function. passwd is a good example. There is both a passwd command, used to change a user's password, and there's a file, /etc/passwd, that is used to store user login information. passwd(1) comtains information on the passwd command, while passwd(5) comtains information on the format of the /etc/passwd file. If you enter just man passwd, and there are multiple entries for a command, then man will try to make a best guess for which one you want. Alternately, you can specify a specific section like: man 5 passwd

If you are ever referred to a command, or hear mention of an unfamiliar command, the man page is the first place you should go to find out more information about it. Don't worry if they seem a little hard to read and understand at first, the more you use the man pages, the more useful they'll become.

No comments: