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.

No comments: