It initiates a search from a desired starting location and then recursively traverses the nodes (directories) of a hierarchical structure (typically a tree).
find can traverse and search through different file systems of partitions belonging to one or more storage devices mounted under the starting directory.
find appeared in Version 5 Unix as part of the Programmer's Workbench project, and was written by Dick Haight alongside cpio,[2] which were designed to be used together.
find is capable of interpreting wildcards internally and commands must be quoted carefully in order to control shell globbing.
Expression elements are separated by the command-line argument boundary, usually represented as whitespace in shell syntax.
Commonly-used primaries include: If the expression uses none of -print0, -print, -exec, or -ok, find defaults to performing -print if the conditions test as true.
Operators are listed in order of decreasing precedence: This command searches the current working directory tree for files whose names start with fileA_ or fileB_.
The POSIX standard requires that The find utility shall detect infinite loops; that is, entering a previously visited directory that is an ancestor of the last file encountered.
When it detects an infinite loop, find shall write a diagnostic message to standard error and shall either recover its position in the hierarchy or terminate.
my* is enclosed in single quotes (apostrophes) as otherwise the shell would replace it with the list of files in the current working directory starting with my...
The previous examples created listings of results because, by default, find executes the -print action.
(Note that early versions of the find command had no default action at all; therefore the resulting list of files would be discarded, to the bewilderment of users.)
More complex filenames including characters special to the shell may need to be enclosed in single quotes.
This searches every directory except the subdirectory tree excluded_path (full path including the leading /) that is pruned by the -prune action, for a regular file whose name is myfile.
The -ls operator prints extended information, and the example finds any regular file whose name ends with either 'jsp' or 'java'.
Note that the command itself should not be quoted; otherwise you get error messages like which means that find is trying to run a file called 'echo "mv ./3bfn rel071204"' and failing.
GNU grep can be used on its own to perform this task: Example of search for "LOG" in jsmith's home directory tree: Example of search for the string "ERROR" in all XML files in the current working directory tree: The double quotes (" ") surrounding the search string and single quotes (' ') surrounding the braces are optional in this example, but needed to allow spaces and some other special characters in the string.