Expressions to select files withfind
Last revision July 20, 2004
Additional topics:
|
You can use find "selection" expressions that only filter the files, but do not perform any actions on them. This is a way to search a directory tree to find files that match the expressions.
In the original find program, files in the directories specified in the dirlist that match these "selection" expressions are "selected", but nothing is done to them, not even printing their names on the terminal (standard output), unless an action expression is also given in combination. Many modern find programs, such as the one on pangea, will list the selected files to standard output as the default "action" expression.
Here are the most generally useful selection expressions. In all cases, the expression selects among the files passed to it from the previous expression (or from the original directory list, if it is the first expression). See the on-line manual entry for find for other lesser-used expressions.
-name filename
Selects the current file if the filename argument matches
the current filename (meaning just the last part of the complete pathname). The
filename argument can include
file-matching wildcard characters, such as the asterisk, but in that case
the entire filenam" must be placed within
quotes to avoid shell substitution. Examples:
find dirlist -name '*.f'
Selects files in the list of directories
dirlist
whose filenames end in .f
find dirlist -name test
Selects files in the list of directories
dirlist
whose filenames are exactly equal to
test.
-user accountname
Select the current file if it belongs to the Unix account named
accountname.
-mtime n
Selects the current file if its date of last modification corresponds to the integer
value of n as follows.
- If n is a simple positive integer, this expression selects files that are exactly n days old, that is, which were created or last modified exactly n days ago.
- If n is preceeded by a plus sign, for example, -mtime +5, this expression selects files that were last modified more than n days ago.
- If n is preceded by a minus sign, for example, -mtime -5, this expression selects files that were last modified less than n days ago, that is, which were created or modified within the last n days.
This expression counts full days only, from midnight to midnight. The current partial day is treated as part of the previous full day.