find - walk a file hierarchy
The find
utility recursively descends the directory tree for each path listed, evaluating an expression in terms of each file in the tree. Basic usage:
find [options] path [expression]
Options
Here are some oprations:
Option | Description |
-E | Support extended (modern) regular expressions, followed by `-regex` and `-iregex` primaries. |
-s | Cause `find` to traverse the file hierarchies in lexicographical order. `find -s` and `find | sort` may give different results. |
Expression
Expression is composed of the primaries
and operands
.
PRIMARIES
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.
Primary | Description |
-ctime n[smhdw] | Compare the time of last change of file status information and the time `find` was started. |
-d n | True if the depth of the file relative to the starting point of the traverse is n. |
-empty | True if current file or directory is empty. |
-[i]name pattern | True if the last component of the pathname matches pattern. Special matching characters: [, ], *, ? |
-[i]regex pattern | True if the whole path of the file matches pattern using regular expression. |
-type [bdflps] | True if the file is of the specified type. b(block), d(directory), f(regular file), l(symbolic link), p(FIFO), s(socket) |
OPERATORS
The primaries may be combined using the following operators.
Operator | Description |
( expression ) | This evaluates to true if the parenthesized expression evaluates to true. |
! expression | This evaluates to true if the expression is false. |
-not expression | |
expression -and expression | This is the logical AND operator. |
expression -or expression | This is the logical OR operator. |
Examples
- Find the files that have not been changed for more than 7 days:
$ find /tmp/ -ctime +7d
- Find all files whose name ends with
1.txt
:$ find . -regex '.*/*1.txt'
- Find all files whose name ends with
.txt
but not symbolic links:$ find . -regex '.*/*.txt' -and -not -type l