The grep Command

Learn about the grep utility in detail.

We'll cover the following...

Using grep

The GNU utilities have one more searching tool besides find, called grep. This utility checks file contents when searching.

How to choose the proper utility for searching

Use find for searching a file or directory by its name, path, or metadata. Metadata is extra information about an object. Examples of the file metadata are size, time of creation, last modification, and permissions. Use the grep utility to find a file when we know nothing about it except its contents.

The following example shows us how to choose the right utility for searching. Let’s suppose that we are looking for a documentation file. We know that it contains the phrase “free software”. If we apply the find utility, the searching algorithm looks like this:

  1. Call find to list all the files with the
...