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.

Wednesday, February 13, 2008

Finding the command you need

Often times you'll know what you want to do, and you may even know that there's a command out there to do what you want. But maybe you don't know, or can't remember, what the command is. This is where apropos (or man -k) comes in. apropos is a tool for searching through the names and descriptions of the man pages installed on a system.

Let's say that you're working on a system, and you need to edit a text file. You're pretty sure that vi is installed, because it's the text editor that is installed on almost every single Unix box there is, but it's not the easiest text editor to use for newbies. So, you figure that if you search the man pages for 'editor', maybe you can find some alternatives. You might end up with something like the following:
$ apropos editor
bvedit (1) - visual editor for binary files
bvi (1) - visual editor for binary files
bview (1) - visual editor for binary files
cle (1) - Command Line Editor
ed (1) - text editor
ex (1) - Vi IMproved, a programmers text editor
nano (1) - Nano's ANOther editor, an enhanced free Pico clone
sed (1) - stream editor for filtering and transforming text
vi (1) - Vi IMproved, a programmers text editor
view (1) - Vi IMproved, a programmers text editor
vim (1) - Vi IMproved, a programmers text editor

From this list, I see nano showed up, which is one of the easiest to use editors frequently found on Linux machines. I can now make use of that to edit my file.

Any time you need to do something, but don't know whether there's a command that might help, give apropos a shot. Try running it on a few words related to what you're trying to do, and see if something comes up.

Note: man -k is generally an equivalent to the apropos command. Both will do the same thing, and return the same information.

Welcome to Linux/Unix Tips, Tricks, and Tools.


More and more people are installing and using Linux at home, many of them for the first time. Although a modern Linux installation can be used entirely from the GUI, there are some things which are much easier or more convenient from a command line. There are also a great many useful tools that new users don't even know are available to them.

This blog will consist of a series of relatively short entries, each of which contains a tip, trick, or tool that many people using Linux and Unix for the first time may not be familiar with. If you are new to Linux or Unix, then this will be a great way to gradually build up your skills and learn some of the secrets of the Unix gurus.

If there is a particular command or tool that you've heard mention of, but you're not sure what it is, how it's used, or why it's used, feel free to let me know. I'll try to work it into the queue to post about.