find

find [-d | -s ] [pathname ...] expression

The find command recursively descends the directory tree for each pathname listed, evaluating an expression (composed of the Primaries and Operands listed in the following sections) in terms of each file in the tree.

The find command supports the following options:

Option

Description

-d

Cause find to perform a depth-first traversal, that is directories are visited in post-order and all entries in a directory will be acted on before the directory itself. By default, find visits directories in pre-order, that is before their contents.

-s

Cause find to traverse the file hierarchies in lexicographical order, that is alphabetical order within each directory.

Notes:

  • The find -s and find | sort commands may give different results.

  • When the -d and -s options are not used, the find command traverses the directory in pre-order, that is the directories will be listed first followed by the files in that directory.

Note: For more information about using the find command, search http://www.freebsd.org/cgi/man.cgi by specifying find as the search keyword and selecting the FreeBSD 6.2-Release option from the release list.

Primaries

The following primaries are supported by the find command:

Primary

Description

-amin n

True if the difference between the file last access time and the time find was started, rounded up to the next full minute, is n minutes.

-anewer file

File was last accessed more recently than file was modified.

-atime n

If no units are specified, this primary evaluates to true if the difference between the file last access time and the time find was started, rounded up to the next full 24-hour period, is n 24-hour periods.

-cmin n

True if the difference between the time of last change of file status information and the time find was started, rounded up to the next full minute, is n minutes.

-cnewer file

True if the current file has been changed more recently than the changed time of the file named by the pathname file.

-ctime n

If no units are specified, this primary evaluates to true if the difference between the time of last change of file status information and the time find was started, rounded up to the next full 24-hour period, is n 24-hour periods.

-delete

Deletes the files specified as an argument to the delete option.

-depth

Always true. This option is similar to the -d option.

-empty

True if the current file or directory is empty.

-exec utility [argument ...] {} +

The primary evaluates as true if the invoked utility returns a zero value as exit status.

-iname pattern

This option is similar to -name , but the match is case insensitive.

-links n

True if the file has n links.

-ls

This primary always evaluates to true. The following information for the current file is written to standard output; inode number, size in 512-byte blocks, file permissions, number of hard link, size in bytes, last modification time, and pathname.

-maxdepth n

Always true; descend at most n directory levels below the command line arguments. If any -maxdepth primary is specified, it applies to the entire expression even if it would not normally be evaluated. -maxdepth 0 limits the whole search to the command line arguments.

-mindepth n

Always true; do not apply any tests or actions at levels less than n . If any -mindepth primary is specified, it applies to the entire expression even if it would not normally be evaluated. -mindepth 1 processes all but the command line arguments.

-mtime n

If no units are specified, this primary evaluates to true if the difference between the file last modification time and the time find was started, rounded up to the next full 24-hour period, is n 24-hour periods.

-name pattern

True if the last component of the pathname being examined matches pattern . Special shell pattern matching characters [ , ] , * , and ? may be used as part of pattern . These characters may be matched explicitly by escaping them with a backslash ( \ ).

-newer file

True if the current file has a more recent last modification time than file .

-path pattern

True if the pathname being examined matches pattern . Special shell pattern matching characters [ , ] , * , and ? may be used as part of pattern . These characters may be matched explicitly by escaping them with a backslash ( \ ). Slashes ( / ) are treated as normal characters and do not have to be matched explicitly.

-print

This primary always evaluates to true. It prints the pathname of the current file to standard output. If none of -exec , -ls , -print0 , or -ok is specified, the given expression shall be effectively replaced by ( given expression ) -print .

-print0

This primary always evaluates to true. It prints the pathname of the current file to standard output, followed by an ASCII NUL character (character code 0).

-printx

This primary always evaluates to true. It prints the pathname of the current file to standard output in a new line.

-prune

This primary always evaluates to true. It causes find to not descend into the current file. Note, the -prune primary has no effect if the -d option was specified.

-size n[c]

True if the file's size, rounded up, in 512-byte blocks is n . If n is followed by a c , then the primary is true if the file's size is n bytes (characters).

-type t

True if the file is of the specified type. Possible file types are as follows:

  • b: Block special

  • c: Character special

  • d: Directory

  • f: Regular file

  • p: FIFO

  • s: Socket

All primaries which take a numeric argument allow the number to be preceded by a plus sign ( + ) or a minus sign ( - ). A preceding plus sign means more than n , a preceding minus sign means less than n and neither means exactly n .

Note: The following primaries are not supported by the Symbian version of the find command:

  • -exec exe {} \;

  • -fstype

  • -group

  • -inum

  • -iregex

  • -nouser

  • -nogroup

  • -perm,

  • -user

Operators

The primaries may be combined using the following operators. The operators are listed in order of decreasing precedence.

Operator

Description

( expression )

This evaluates to true if the parenthesized expression evaluates to true.

! expression

This is the unary NOT operator. It evaluates to true if the expression is false.

expression -and expression

The -and operator is the logical AND operator. As it is implied by the juxtaposition of two expressions it does not have to be specified. The expression evaluates to true if both expressions are true. The second expression is not evaluated if the first expression is false.

expression -or expression

The -or operator is the logical OR operator. The expression evaluates to true if either the first or the second expression is true. The second expression is not evaluated if the first expression is true.

All operands and primaries must be separate arguments to find . Primaries which themselves take arguments expect each argument to be a separate argument to find .

Copyright notice

For information about documentation copyrights associated with the find command, see http://www.freebsd.org/copyright/freebsd-doc-license.html .

The FreeBSD Documentation License

Copyright 1994-2006 The FreeBSD Project. All rights reserved.

Redistribution and use in source (SGML DocBook) and 'compiled' forms (SGML, HTML, PDF, PostScript, RTF and so forth) with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code (SGML DocBook) must retain the above copyright notice, this list of conditions and the following disclaimer as the first lines of this file unmodified.

  2. Redistributions in compiled form (transformed to other DTDs, converted to PDF, PostScript, RTF and other formats) must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS DOCUMENTATION IS PROVIDED BY THE FREEBSD DOCUMENTATION PROJECT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD DOCUMENTATION PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.