CLI Magic: One-liners

Newcomers to Linux often feel overwhelmed by the number of commands at their disposal. Frustration sets in when they know what they wish to accomplish, but they do not have any idea what command(s) they can use to get the job done. This week’s CLI Magic — written by Jim Westbrook — helps clear away some of that excess one-liner at a time.

Fortunately, Linux provides a couple of utilitites which use a database of the man pages to point them to an appropriate command or provide a hint of what a command does. These are apropos and whatis respectively. An example may be the best illustration of their use. First one for apropos:

~/> apropos music
SDL::Music (3pm) – a perl extension
tse3play (1) – play/convert music files (MIDI or TSE3MDL) using
the TSE3 sequencer engine library

The output results are not particularly useful if what the user desires is to learn how to play a music CD on his system. The next logical step is to call apropos again, this time looking for the string “CD” instead of music. Alas, the result of this request returns 76 lines which is almost as overwhelming as the full list of commands in /bin. What the user needs is a way to limit the results to only those items that include the word “play” in the description. Thankfully, Linux provides just such a tool — grep.

Let’s take a quick side trip to an example of the whatis command:

~/> whatis grep
grep (1) – print lines matching a pattern

At first glance this doesn’t tell the newbie much. He needs to understand the meaning of the word pattern in the result. It is significant to note that grep can match either a literal string or a regular expression as its passed parameter. For now, let’s use the literal string form as it is much easier for most folks to understand. In this instance, the pattern is the sequence of characters passed to grep as a parameter.

Full Article at Linux.com

Article Written by