Chapter 5. Command Line Utilities

Table of Contents
5.1. grep: General Regular Expression Parser
5.2. find: find files according to certain criteria
5.3. crontab: reporting or editing your crontab file
5.4. at: schedule a command, but only once
5.5. tar: Tape ARchiver
5.6. bzip2 and gzip: data compression programs
5.7. Many, many more...

The purpose of this chapter is to introduce a small number of command line tools which may prove useful for everyday use. Of course, you may skip this chapter if you only intend to use a graphical environment, but a quick glance may change your opinion :-)

There is not really any organization in this chapter. Utilities are listed as they come, from the most commonly used to the most arcane. Each command will be illustrated by an example, but it is left as an exercise to you to find more useful uses of them.

5.1. grep: General Regular Expression Parser

Okay, the name is not very intuitive, neither is its acronym, but its use is simple: looking for a pattern given as an argument in one or more files. Its syntax is:

grep [options] <pattern> [one or more file(s)]

If several files are mentioned, their name will precede each matching line displayed in the result. Use the -h option to prevent the display of these names; use the -l option to get nothing but the matching filenames. The pattern is a regular expression, even though most of the time it consists of a simple word. The most frequently used options are the following:

Here's an example of how to use it:

$ cat my_father
Hello dad
Hi daddy
So long dad

  # Search for the string "hi", no matter the case
$ grep -i hi my_father
Hi daddy

  # Search for "dad" as a whole word, and print the 
  #   line number in front of each match
$ grep -nw dad my_father
1:Hello dad
3:So long dad

  # We want all lines not beginning with "H" to match
$ grep -v "^H" my_father
So long dad
$

In case you want to use grep in a pipe, you don't have to specify the filename as, by default, it takes its input from the standard input. Similarly, by default, it prints the results on the standard output, so you can pipe the output of a grep to yet another program without fear. Example:

$ cat /usr/share/doc/HOWTO/Parallel-Processing-HOWTO | \
  grep -n thread | less

Tux on Star from MandrakeSoft Linux is a registered trademark of Linus Torvalds. All other trademarks and copyrights are the property of their respective owners.
Unless otherwise stated, all the content of these pages and all images are Copyright MandrakeSoft S.A. and MandrakeSoft Inc. 2001.
http://www.mandrakelinux.com/