October 12, 2001, 11:19 AM — The
find command is one of the most powerful tools available to a
Unix system administrator, but its command syntax is awkward and
often poorly explained. A typically cryptic description of
something like this:
find path-list expression
After chasing through the man pages you find that an expression can
be either a criteria for selecting a file or an action to perform on
It is possible to simplify the
find syntax. The
find command will
search from a starting directory down through subdirectories,
locating files that match your specified search criteria. Find will
then execute a command on the found file.
Though the man pages are technically correct in stating that the
find command has only three parts, it is useful to think of it as
|find||starting where||find which files||do what|
In more detail, the parts are:
findcommand itself (the word "
find"), that is needed to
start the program.
- The directory from which to start searching. This can be more
than one directory, but you will usually use only one starting
- Which files to find. The search criteria can be specified by
file name, size, type, and many other categories which I will discuss
in a moment.
- The last part of the command contains what to do with the file
when found. There is almost no limit to what you can do to a file.
This portion of the command may include any Unix command. When used
as a file locator, this part of the command usually specifies that
the file path, name, and other information are to be printed on the
screen or to a file.
The following is an example of a
find command that will locate all
files named "minutes.txt." The search starts at your own home
directory and works its way down through subdirectories. On each
'hit' it prints the file name of the file found.