1 .TH FIND 1 \" -*- nroff -*-
3 find \- search for files in a directory hierarchy
9 documents the GNU version of
12 searches the directory tree rooted at each given file name by
13 evaluating the given expression from left to right, according to the
14 rules of precedence (see section OPERATORS), until the outcome is
15 known (the left hand side is false for \fIand\fR operations, true for
16 \fIor\fR), at which point
18 moves on to the next file name.
20 The first argument that begins with `\-', `(', `)', `,', or `!' is taken
21 to be the beginning of the expression; any arguments before it are
22 paths to search, and any arguments after it are the rest of the
23 expression. If no paths are given, the current directory is used. If
24 no expression is given, the expression `\-print' is used (but you
25 should probably consider using `\-print0' instead, anyway).
29 The expression is made up of options (which affect overall operation
30 rather than the processing of a specific file, and always return true),
31 tests (which return a true or false value), and actions (which have side
32 effects and return a true or false value), all separated by operators.
33 \-and is assumed where the operator is omitted. If the expression contains
34 no actions other than \-prune, \-print is performed on all files
35 for which the expression is true.
38 All options always return true. They always take effect, rather than
39 being processed only when their place in the expression is reached.
40 Therefore, for clarity, it is best to place them at the beginning of
43 Measure times (for \-amin, \-atime, \-cmin, \-ctime, \-mmin, and \-mtime)
44 from the beginning of today rather than from 24 hours ago.
46 Process each directory's contents before the directory itself.
48 Dereference symbolic links. Implies \-noleaf.
49 .IP "\-help, \-\-help"
50 Print a summary of the command-line usage of
53 .IP "\-maxdepth \fIlevels\fR"
54 Descend at most \fIlevels\fR (a non-negative integer) levels of
55 directories below the command line arguments. `\-maxdepth 0' means
56 only apply the tests and actions to the command line arguments.
57 .IP "\-mindepth \fIlevels\fR"
58 Do not apply any tests or actions at levels less than \fIlevels\fR (a
59 non-negative integer). `\-mindepth 1' means process all files except
60 the command line arguments.
62 Don't descend directories on other filesystems. An alternate name for
63 \-xdev, for compatibility with some other versions of
66 Do not optimize by assuming that directories contain 2 fewer
67 subdirectories than their hard link count. This option is needed when
68 searching filesystems that do not follow the Unix directory-link
69 convention, such as CD-ROM or MS-DOS filesystems or AFS volume mount
70 points. Each directory on a normal Unix filesystem has at least 2
71 hard links: its name and its `.' entry. Additionally, its
72 subdirectories (if any) each have a `..' entry linked to that
75 is examining a directory, after it has statted 2 fewer subdirectories
76 than the directory's link count, it knows that the rest of the entries
77 in the directory are non-directories (`leaf' files in the directory
78 tree). If only the files' names need to be examined, there is no need
79 to stat them; this gives a significant increase in search speed.
80 .IP "\-version, \-\-version"
81 Print the \fBfind\fR version number and exit.
83 Don't descend directories on other filesystems.
86 Numeric arguments can be specified as
97 File was last accessed \fIn\fR minutes ago.
98 .IP "\-anewer \fIfile\fR"
99 File was last accessed more recently than \fIfile\fR was modified.
100 \-anewer is affected by \-follow only if \-follow comes before
101 \-anewer on the command line.
102 .IP "\-atime \fIn\fR"
103 File was last accessed \fIn\fR*24 hours ago.
105 File's status was last changed \fIn\fR minutes ago.
106 .IP "\-cnewer \fIfile\fR"
107 File's status was last changed more recently than \fIfile\fR was modified.
108 \-cnewer is affected by \-follow only if \-follow comes before
109 \-cnewer on the command line.
110 .IP "\-ctime \fIn\fR"
111 File's status was last changed \fIn\fR*24 hours ago.
113 File is empty and is either a regular file or a directory.
116 .IP "\-fstype \fItype\fR"
117 File is on a filesystem of type \fItype\fR. The valid filesystem
118 types vary among different versions of Unix; an incomplete list of
119 filesystem types that are accepted on some version of Unix or another
120 is: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K. You can use \-printf
121 with the %F directive to see the types of your filesystems.
123 File's numeric group ID is \fIn\fR.
124 .IP "\-group \fIgname\fR"
125 File belongs to group \fIgname\fR (numeric group ID allowed).
126 .IP "\-ilname \fIpattern\fR"
127 Like \-lname, but the match is case insensitive.
128 .IP "\-iname \fIpattern\fR"
129 Like \-name, but the match is case insensitive. For example, the
130 patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo',
131 `fOo', etc. In these patterns, unlike filename expansion by the
132 shell, an initial '.' can be matched by '*'. That is,
134 will match the file `.foobar'.
137 File has inode number \fIn\fR.
138 .IP "\-ipath \fIpattern\fR"
139 Behaves in the same way as \-iwholename. This option is deprecated,
140 so please do not use it.
141 .IP "\-iregex \fIpattern\fR"
142 Like \-regex, but the match is case insensitive.
143 .IP "\-iwholename \fIpattern\fR"
144 Like \-wholename, but the match is case insensitive.
145 .IP "\-links \fIn\fR"
146 File has \fIn\fR links.
147 .IP "\-lname \fIpattern\fR"
148 File is a symbolic link whose contents match shell pattern
149 \fIpattern\fR. The metacharacters do not treat `/' or `.' specially.
151 File's data was last modified \fIn\fR minutes ago.
152 .IP "\-mtime \fIn\fR"
153 File's data was last modified \fIn\fR*24 hours ago.
154 .IP "\-name \fIpattern\fR"
155 Base of file name (the path with the leading directories removed)
156 matches shell pattern \fIpattern\fR. The metacharacters (`*', `?',
157 and `[]') match a `.' at the start of the base name (this is a change
158 in findutils-4.2.2; see section STANDARDS CONFORMANCE below). To ignore a
159 directory and the files under it, use \-prune; see an example in the
160 description of \-wholename. Braces are not recognised as being
161 special, despite the fact that some shells including Bash ibmue braces
162 with a special meaning in shell patterns. The filename matching is
163 performed with the use of the
166 .IP "\-newer \fIfile\fR"
167 File was modified more recently than \fIfile\fR.
168 \-newer is affected by \-follow only if \-follow comes before
169 \-newer on the command line.
171 No user corresponds to file's numeric user ID.
173 No group corresponds to file's numeric group ID.
174 .IP "\-path \fIpattern\fR"
175 See \-wholename. The predicate \-path is also supported by HP-UX
177 .IP "\-perm \fImode\fR"
178 File's permission bits are exactly \fImode\fR (octal or symbolic).
179 Symbolic modes use mode 0 as a point of departure.
180 .IP "\-perm \-\fImode\fR"
181 All of the permission bits \fImode\fR are set for the file.
182 .IP "\-perm +\fImode\fR"
183 Any of the permission bits \fImode\fR are set for the file.
184 .IP "\-regex \fIpattern\fR"
185 File name matches regular expression \fIpattern\fR. This is a match
186 on the whole path, not a search. For example, to match a file named
187 `./fubar3', you can use the regular expression `.*bar.' or `.*b.*3',
188 but not `b.*r3'. The regular expressions understood by
190 follow the conventions for the
192 system library function where this is present (i.e. on systems using
193 the GNU C Library). On other systems, the implementation within
194 Gnulib is used; by default, Gnulib provides "basic" regular
196 .IP "\-size \fIn\fR[cwbkMG]"
197 File uses \fIn\fP units of space. The following suffixes
201 for 512-byte blocks (this is the default if no suffix is used)
207 for Kilobytes (units of 1024 bytes)
209 for Megabytes (units of 1048576 bytes)
211 for Gigabytes (units of 1073741824 bytes)
214 The size does not count indirect blocks, but it does count blocks in
215 sparse files that are not actually allocated. Bear in mind that the
216 `%k' and `%b' format specifiers of \-printf handle sparse files
217 differently. The `b' suffix always denotes 512-byte blocks and never
218 1 Kilobyte blocks, which is different to the behaviour of \-ls.
223 File is of type \fIc\fR:
226 block (buffered) special
228 character (unbuffered) special
243 File's numeric user ID is \fIn\fR.
245 File was last accessed \fIn\fR days after its status was last changed.
246 .IP "\-user \fIuname\fR"
247 File is owned by user \fIuname\fR (numeric user ID allowed).
248 .IP "\-wholename \fIpattern\fR"
249 File name matches shell pattern \fIpattern\fR. The metacharacters do
250 not treat `/' or `.' specially; so, for example,
253 find . \-wholename './sr*sc'
256 will print an entry for a directory called './src/misc' (if one
257 exists). To ignore a whole directory tree, use \-prune rather than
258 checking every file in the tree. For example, to skip the
259 directory `src/emacs' and all files and directories under it, and
260 print the names of the other files found, do something like this:
263 find . \-wholename './src/emacs' -prune -o -print
266 .IP "\-xtype \fIc\fR"
267 The same as \-type unless the file is a symbolic link. For symbolic
268 links: if \-follow has not been given, true if the file is a link to a
269 file of type \fIc\fR; if \-follow has been given, true if \fIc\fR is
270 `l'. In other words, for symbolic links, \-xtype checks the type of
271 the file that \-type does not check.
273 .IP "\-exec \fIcommand\fR ;"
274 Execute \fIcommand\fR; true if 0 status is returned. All following
277 are taken to be arguments to the command until an argument consisting
278 of `;' is encountered. The string `{}' is replaced by the current
279 file name being processed everywhere it occurs in the arguments to the
280 command, not just in arguments where it is alone, as in some versions
283 Both of these constructions might need to be escaped (with a `\e') or
284 quoted to protect them from expansion by the shell. See the
286 section for examples of the use of the `-exec' option.
288 executed in the starting directory.
290 .IP "\-fls \fIfile\fR"
291 True; like \-ls but write to \fIfile\fR like \-fprint.
292 The output file is always created, even if the predicate is never matched.
293 .IP "\-fprint \fIfile\fR"
294 True; print the full file name into file \fIfile\fR. If \fIfile\fR
295 does not exist when \fBfind\fR is run, it is created; if it does
296 exist, it is truncated. The file names ``/dev/stdout'' and
297 ``/dev/stderr'' are handled specially; they refer to the standard
298 output and standard error output, respectively.
299 The output file is always created, even if the predicate is never matched.
300 .IP "\-fprint0 \fIfile\fR"
301 True; like \-print0 but write to \fIfile\fR like \-fprint.
302 The output file is always created, even if the predicate is never matched.
303 .IP "\-fprintf \fIfile\fR \fIformat\fR"
304 True; like \-printf but write to \fIfile\fR like \-fprint.
305 The output file is always created, even if the predicate is never matched.
306 .IP "\-ok \fIcommand\fR ;"
307 Like \-exec but ask the user first (on the standard input); if the
308 response does not start with `y' or `Y', do not run the command, and
311 True; print the full file name on the standard output, followed by a
312 newline. If you are piping the output of
314 into another program and there is the faintest possibility that the files
315 which you are searching for might contain a newline, then you should
316 seriously consider using the `\-print0' option instead of `\-print'.
319 True; print the full file name on the standard output, followed by a
320 null character (instead of the newline character that `-print' uses).
321 This allows file names that contain newlines or other types of white
322 space to be correctly interpreted by programs that process the
323 \fBfind\fR output. This option corresponds to the `\-0' option of
325 .IP "\-printf \fIformat\fR"
326 True; print \fIformat\fR on the standard output, interpreting `\e'
327 escapes and `%' directives. Field widths and precisions can be
328 specified as with the `printf' C function. Unlike \-print, \-printf
329 does not add a newline at the end of the string. The escapes and
337 Stop printing from this format immediately and flush the output.
351 A literal backslash (`\e').
353 The character whose ASCII code is NNN (octal).
355 A `\e' character followed by any other character is treated as an
356 ordinary character, so they both are printed.
358 A literal percent sign.
360 File's last access time in the format returned by the C `ctime' function.
362 File's last access time in the format specified by \fIk\fR, which is
363 either `@' or a directive for the C `strftime' function. The possible
364 values for \fIk\fR are listed below; some of them might not be
365 available on all systems, due to differences in `strftime' between
369 seconds since Jan. 1, 1970, 00:00 GMT.
385 time, 12-hour (hh:mm:ss [AP]M)
389 time, 24-hour (hh:mm:ss)
391 locale's time representation (H:M:S)
393 time zone (e.g., EDT), or nothing if no time zone is determinable
397 locale's abbreviated weekday name (Sun..Sat)
399 locale's full weekday name, variable length (Sunday..Saturday)
401 locale's abbreviated month name (Jan..Dec)
403 locale's full month name, variable length (January..December)
405 locale's date and time (Sat Nov 04 12:02:33 EST 1989)
407 day of month (01..31)
413 day of year (001..366)
417 week number of year with Sunday as first day of week (00..53)
421 week number of year with Monday as first day of week (00..53)
423 locale's date representation (mm/dd/yy)
425 last two digits of year (00..99)
430 File's size in 512-byte blocks (rounded up).
432 File's last status change time in the format returned by the C `ctime'
435 File's last status change time in the format specified by \fIk\fR,
436 which is the same as for %A.
438 File's depth in the directory tree; 0 means the file is a command line
441 File's name with any leading directories removed (only the last element).
443 Type of the filesystem the file is on; this value can be used for
446 File's group name, or numeric group ID if the group has no name.
448 File's numeric group ID.
450 Leading directories of file's name (all but the last element).
452 Command line argument under which file was found.
454 File's inode number (in decimal).
456 The amount of disk space used for this file in 1K blocks (rounded
457 up). This is different from %s/1024 if the file is a sparse file.
459 Object of symbolic link (empty string if file is not a symbolic link).
461 File's permission bits (in octal).
463 Number of hard links to file.
467 File's name with the name of the command line argument under which
468 it was found removed.
470 File's size in bytes.
472 File's last modification time in the format returned by the C `ctime'
475 File's last modification time in the format specified by \fIk\fR,
476 which is the same as for %A.
478 File's user name, or numeric user ID if the user has no name.
480 File's numeric user ID.
482 A `%' character followed by any other character is discarded (but the
483 other character is printed).
486 If \-depth is not given, true; do not descend the current directory.
488 If \-depth is given, false; no effect.
490 True; list current file in `ls \-dils' format on standard output.
491 The block counts are of 1K blocks, unless the environment variable
492 POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
493 .IP \-ignore_readdir_race
494 Normally, \fBfind\fR will emit an error message when it fails to stat a file.
495 If you give this option and a file is deleted between the time \fBfind\fR
496 reads the name of the file from the directory and the time it tries to stat
497 the file, nno error message will be issued. This also applies to files
498 or directories whose names are given on the command line. This option takes
499 effect at the time the command line is read, which means that you cannot search
500 one part of the filesystem with this option on and part of it with this option
501 off (if you need to do that, you will need to issue two \fBfind\fR commands
502 instead, one with the option and one without it).
503 .IP \-noignore_readdir_race
504 Turns off the effect of \-ignore_readdir_race.
507 Listed in order of decreasing precedence:
511 True if \fIexpr\fR is false.
512 .IP "\-not \fIexpr\fR"
513 Same as ! \fIexpr\fR.
514 .IP "\fIexpr1 expr2\fR"
515 And (implied); \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
516 .IP "\fIexpr1\fR \-a \fIexpr2\fR"
517 Same as \fIexpr1 expr2\fR.
518 .IP "\fIexpr1\fR \-and \fIexpr2\fR"
519 Same as \fIexpr1 expr2\fR.
520 .IP "\fIexpr1\fR \-o \fIexpr2\fR"
521 Or; \fIexpr2\fR is not evaluated if \fIexpr1\fR is true.
522 .IP "\fIexpr1\fR \-or \fIexpr2\fR"
523 Same as \fIexpr1\fR \-o \fIexpr2\fR.
524 .IP "\fIexpr1\fR , \fIexpr2\fR"
525 List; both \fIexpr1\fR and \fIexpr2\fR are always evaluated.
526 The value of \fIexpr1\fR is discarded; the value of the list is the
527 value of \fIexpr2\fR.
529 .SH "STANDARDS CONFORMANCE"
530 The following options are specified in the POSIX standard
531 (IEEE Std 1003.1, 2003 Edition):
533 This option is supported, but POSIX conformance depends on the
534 POSIX conformance of the system's
536 library function. As of findutils-4.2.2, shell metacharacters
537 ('*'. '?' or '[]' for example) will match a leading '.', because
538 IEEE interpretation 126 requires this. This is a change from
539 previous versions of findutils.
541 Supported. POSIX specifies `b', `c', `d', `l', `p', `f' and `s'.
542 GNU find also supports `D', representing a Door, where the OS provides these.
545 Supported. Interpretation of the response is not locale-dependent
546 (see ENVIRONMENT VARIABLES).
548 .IP "Other predicates"
569 The POSIX standard specifies parentheses `(', `)', negation `!' and the
570 `and' and `or' operators (`-a', `-o').
572 All other options, predicates, expressions and so forth are extensions
573 beyond the POSIX standard. Many of these extensions are not unique to
575 .SH "ENVIRONMENT VARIABLES"
577 Determines the block size used by `-ls'.
579 Provides a default value for the internationalization variables that
582 If set to a non-empty string value, override the values of all the
583 other internationalization variables.
585 The POSIX standard specifies that this variable affects the pattern
586 matching to be used for the `-name' option. GNU find uses the
588 library function, and so support for `LC_COLLATE' depends on the
591 POSIX also specifies that the `LC_COLLATE' environment
592 variable affects the interpretation of the user's response to the
593 query issued by `-ok', but this is not the case for GNU find.
595 This variable affects the treatment of character classes used with
596 the `-name' option, if the system's
598 library function supports this. It has no effect on the behaviour
599 of the `-ok' expression.
601 Determines the locale to be used for internationalised messages.
603 Determines the location of the internationalisation message catalogues.
605 Affects the directores which are searched to find the executables
606 invoked by `-exec' and `-ok'.
609 .B find /tmp -name core -type f -print | xargs /bin/rm -f
614 in or below the directory
616 and delete them. Note that this will work incorrectly if there are
617 any filenames containing newlines or spaces.
619 .B find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
624 in or below the directory
626 and delete them, processing filenames in such a way that file or
627 directory names containing spaces or newlines are correctly handled.
630 .B cut -d: -f1 < /etc/passwd | sort | xargs echo
633 Generates a compact listing of all the users on the system.
637 .B find . -type f -exec file '{}' \e\;
640 Runs `file' on every file in or below the current directory. Notice
641 that the braces are enclosed in single quote marks to protect them
642 from interpretation as shell script punctuation. The semicolon is
643 similarly protected by the use of a backslash, though ';' could have
644 been used in that case also.
649 exits with status 0 if all files are processed successfully, greater
650 than 0 if errors occur.
652 \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1), \fBxargs\fP(1)
653 \fBFinding Files\fP (on-line in Info, or printed)
656 The best way to report a bug is to use the form at
657 http://savannah.gnu.org/bugs/?group=findutils.
658 The reason for this is that you will then be able to track progress in
659 fixing the problem. Other comments about \fBfind\fP(1) and about
660 the findutils package in general can be sent to the
662 mailing list. To join the list, send email to
663 .IR bug-findutils-request@gnu.org .