find to locate files" /> Using find to locate files | ITworld
  • find to locate files">
  • find to locate files" st_via="ITworld" st_username="ITworld">
  • find to locate files">
  • find to locate files">
  • find to locate files">

Using find to locate files

  • find to locate files">
  • find to locate files" st_via="ITworld" st_username="ITworld">
  • find to locate files">
  • find to locate files">
  • find to locate files">
Unix Insider |  Operating Systems

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 find goes
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
a file.

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
having four:

1 2 3 4
find starting where find which files do what

In more detail, the parts are:

  1. The find command itself (the word "find"), that is needed to
    start the program.
  2. The directory from which to start searching. This can be more
    than one directory, but you will usually use only one starting
    directory.
  3. 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.
  4. 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.

Locating files

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.

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Answers - Powered by ITworld

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question
randomness