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',
133 File has inode number \fIn\fR.
134 .IP "\-ipath \fIpattern\fR"
135 Like \-path, but the match is case insensitive.
136 .IP "\-iregex \fIpattern\fR"
137 Like \-regex, but the match is case insensitive.
138 .IP "\-links \fIn\fR"
139 File has \fIn\fR links.
140 .IP "\-lname \fIpattern\fR"
141 File is a symbolic link whose contents match shell pattern
142 \fIpattern\fR. The metacharacters do not treat `/' or `.' specially.
144 File's data was last modified \fIn\fR minutes ago.
145 .IP "\-mtime \fIn\fR"
146 File's data was last modified \fIn\fR*24 hours ago.
147 .IP "\-name \fIpattern\fR"
148 Base of file name (the path with the leading directories removed)
149 matches shell pattern \fIpattern\fR. The metacharacters (`*', `?',
150 and `[]') do not match a `.' at the start of the base name. To ignore
151 a directory and the files under it, use \-prune; see an example in the
152 description of \-path. Braces are not recognised as being special,
153 despite the fact that some shells including Bash ibmue braces with
154 a special meaning in shell patterns. The filename matching is
155 performed with the use of the
158 .IP "\-newer \fIfile\fR"
159 File was modified more recently than \fIfile\fR.
160 \-newer is affected by \-follow only if \-follow comes before
161 \-newer on the command line.
163 No user corresponds to file's numeric user ID.
165 No group corresponds to file's numeric group ID.
166 .IP "\-path \fIpattern\fR"
167 File name matches shell pattern \fIpattern\fR. The metacharacters do
168 not treat `/' or `.' specially; so, for example,
171 find . \-path './sr*sc'
174 will print an entry for a directory called './src/misc' (if one
175 exists). To ignore a whole directory tree, use \-prune rather than
176 checking every file in the tree. For example, to skip the
177 directory `src/emacs' and all files and directories under it, and
178 print the names of the other files found, do something like this:
181 find . \-path './src/emacs' -prune -o -print
184 .IP "\-perm \fImode\fR"
185 File's permission bits are exactly \fImode\fR (octal or symbolic).
186 Symbolic modes use mode 0 as a point of departure.
187 .IP "\-perm \-\fImode\fR"
188 All of the permission bits \fImode\fR are set for the file.
189 .IP "\-perm +\fImode\fR"
190 Any of the permission bits \fImode\fR are set for the file.
191 .IP "\-regex \fIpattern\fR"
192 File name matches regular expression \fIpattern\fR. This is a match
193 on the whole path, not a search. For example, to match a file named
194 `./fubar3', you can use the regular expression `.*bar.' or `.*b.*3',
195 but not `b.*r3'. The regular expressions understood by
197 follow the conventions for the
199 system library function where this is present (i.e. on systems using
200 the GNU C Library). On other systems, the implementation within
201 Gnulib is used; by default, Gnulib provides "basic" regular
203 .IP "\-size \fIn\fR[cwbkMG]"
204 File uses \fIn\fP units of space. The following suffixes
208 for 512-byte blocks (this is the default if no suffix is used)
214 for Kilobytes (units of 1024 bytes)
216 for Megabytes (units of 1048576 bytes)
218 for Gigabytes (units of 1073741824 bytes)
221 The size does not count indirect blocks, but it does count blocks in
222 sparse files that are not actually allocated. Bear in mind that the
223 `%k' and `%b' format specifiers of \-printf handle sparse files
224 differently. The `b' suffix always denotes 512-byte blocks and never
225 1 Kilobyte blocks, which is different to the behaviour of \-ls.
230 File is of type \fIc\fR:
233 block (buffered) special
235 character (unbuffered) special
250 File's numeric user ID is \fIn\fR.
252 File was last accessed \fIn\fR days after its status was last changed.
253 .IP "\-user \fIuname\fR"
254 File is owned by user \fIuname\fR (numeric user ID allowed).
255 .IP "\-xtype \fIc\fR"
256 The same as \-type unless the file is a symbolic link. For symbolic
257 links: if \-follow has not been given, true if the file is a link to a
258 file of type \fIc\fR; if \-follow has been given, true if \fIc\fR is
259 `l'. In other words, for symbolic links, \-xtype checks the type of
260 the file that \-type does not check.
262 .IP "\-exec \fIcommand\fR ;"
263 Execute \fIcommand\fR; true if 0 status is returned. All following
266 are taken to be arguments to the command until an argument consisting
267 of `;' is encountered. The string `{}' is replaced by the current
268 file name being processed everywhere it occurs in the arguments to the
269 command, not just in arguments where it is alone, as in some versions
272 Both of these constructions might need to be escaped (with a `\e') or
273 quoted to protect them from expansion by the shell. See the
275 section for examples of the use of the `-exec' option.
277 executed in the starting directory.
279 .IP "\-fls \fIfile\fR"
280 True; like \-ls but write to \fIfile\fR like \-fprint.
281 The output file is always created, even if the predicate is never matched.
282 .IP "\-fprint \fIfile\fR"
283 True; print the full file name into file \fIfile\fR. If \fIfile\fR
284 does not exist when \fBfind\fR is run, it is created; if it does
285 exist, it is truncated. The file names ``/dev/stdout'' and
286 ``/dev/stderr'' are handled specially; they refer to the standard
287 output and standard error output, respectively.
288 The output file is always created, even if the predicate is never matched.
289 .IP "\-fprint0 \fIfile\fR"
290 True; like \-print0 but write to \fIfile\fR like \-fprint.
291 The output file is always created, even if the predicate is never matched.
292 .IP "\-fprintf \fIfile\fR \fIformat\fR"
293 True; like \-printf but write to \fIfile\fR like \-fprint.
294 The output file is always created, even if the predicate is never matched.
295 .IP "\-ok \fIcommand\fR ;"
296 Like \-exec but ask the user first (on the standard input); if the
297 response does not start with `y' or `Y', do not run the command, and
300 True; print the full file name on the standard output, followed by a
301 newline. If you are piping the output of
303 into another program and there is the faintest possibility that the files
304 which you are searching for might contain a newline, then you should
305 seriously consider using the `\-print0' option instead of `\-print'.
308 True; print the full file name on the standard output, followed by a
309 null character (instead of the newline character that `-print' uses).
310 This allows file names that contain newlines or other types of white
311 space to be correctly interpreted by programs that process the
312 \fBfind\fR output. This option corresponds to the `\-0' option of
314 .IP "\-printf \fIformat\fR"
315 True; print \fIformat\fR on the standard output, interpreting `\e'
316 escapes and `%' directives. Field widths and precisions can be
317 specified as with the `printf' C function. Unlike \-print, \-printf
318 does not add a newline at the end of the string. The escapes and
326 Stop printing from this format immediately and flush the output.
340 A literal backslash (`\e').
342 The character whose ASCII code is NNN (octal).
344 A `\e' character followed by any other character is treated as an
345 ordinary character, so they both are printed.
347 A literal percent sign.
349 File's last access time in the format returned by the C `ctime' function.
351 File's last access time in the format specified by \fIk\fR, which is
352 either `@' or a directive for the C `strftime' function. The possible
353 values for \fIk\fR are listed below; some of them might not be
354 available on all systems, due to differences in `strftime' between
358 seconds since Jan. 1, 1970, 00:00 GMT.
374 time, 12-hour (hh:mm:ss [AP]M)
378 time, 24-hour (hh:mm:ss)
380 locale's time representation (H:M:S)
382 time zone (e.g., EDT), or nothing if no time zone is determinable
386 locale's abbreviated weekday name (Sun..Sat)
388 locale's full weekday name, variable length (Sunday..Saturday)
390 locale's abbreviated month name (Jan..Dec)
392 locale's full month name, variable length (January..December)
394 locale's date and time (Sat Nov 04 12:02:33 EST 1989)
396 day of month (01..31)
402 day of year (001..366)
406 week number of year with Sunday as first day of week (00..53)
410 week number of year with Monday as first day of week (00..53)
412 locale's date representation (mm/dd/yy)
414 last two digits of year (00..99)
419 File's size in 512-byte blocks (rounded up).
421 File's last status change time in the format returned by the C `ctime'
424 File's last status change time in the format specified by \fIk\fR,
425 which is the same as for %A.
427 File's depth in the directory tree; 0 means the file is a command line
430 File's name with any leading directories removed (only the last element).
432 Type of the filesystem the file is on; this value can be used for
435 File's group name, or numeric group ID if the group has no name.
437 File's numeric group ID.
439 Leading directories of file's name (all but the last element).
441 Command line argument under which file was found.
443 File's inode number (in decimal).
445 The amount of disk space used for this file in 1K blocks (rounded
446 up). This is different from %s/1024 if the file is a sparse file.
448 Object of symbolic link (empty string if file is not a symbolic link).
450 File's permission bits (in octal).
452 Number of hard links to file.
456 File's name with the name of the command line argument under which
457 it was found removed.
459 File's size in bytes.
461 File's last modification time in the format returned by the C `ctime'
464 File's last modification time in the format specified by \fIk\fR,
465 which is the same as for %A.
467 File's user name, or numeric user ID if the user has no name.
469 File's numeric user ID.
471 A `%' character followed by any other character is discarded (but the
472 other character is printed).
475 If \-depth is not given, true; do not descend the current directory.
477 If \-depth is given, false; no effect.
479 True; list current file in `ls \-dils' format on standard output.
480 The block counts are of 1K blocks, unless the environment variable
481 POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
482 .IP \-ignore_readdir_race
483 Normally, \fBfind\fR will emit an error message when it fails to stat a file.
484 If you give this option and a file is deleted between the time \fBfind\fR
485 reads the name of the file from the directory and the time it tries to stat
486 the file, nno error message will be issued. This also applies to files
487 or directories whose names are given on the command line. This option takes
488 effect at the time the command line is read, which means that you cannot search
489 one part of the filesystem with this option on and part of it with this option
490 off (if you need to do that, you will need to issue two \fBfind\fR commands
491 instead, one with the option and one without it).
492 .IP \-noignore_readdir_race
493 Turns off the effect of \-ignore_readdir_race.
496 Listed in order of decreasing precedence:
500 True if \fIexpr\fR is false.
501 .IP "\-not \fIexpr\fR"
502 Same as ! \fIexpr\fR.
503 .IP "\fIexpr1 expr2\fR"
504 And (implied); \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
505 .IP "\fIexpr1\fR \-a \fIexpr2\fR"
506 Same as \fIexpr1 expr2\fR.
507 .IP "\fIexpr1\fR \-and \fIexpr2\fR"
508 Same as \fIexpr1 expr2\fR.
509 .IP "\fIexpr1\fR \-o \fIexpr2\fR"
510 Or; \fIexpr2\fR is not evaluated if \fIexpr1\fR is true.
511 .IP "\fIexpr1\fR \-or \fIexpr2\fR"
512 Same as \fIexpr1\fR \-o \fIexpr2\fR.
513 .IP "\fIexpr1\fR , \fIexpr2\fR"
514 List; both \fIexpr1\fR and \fIexpr2\fR are always evaluated.
515 The value of \fIexpr1\fR is discarded; the value of the list is the
516 value of \fIexpr2\fR.
518 .SH "STANDARDS CONFORMANCE"
519 The following options are specified in the POSIX standard
520 (IEEE Std 1003.1, 2003 Edition):
522 This option is supported, but POSIX conformance depends on the
523 POSIX conformance of the system's
528 Supported. POSIX specifies `b', `c', `d', `l', `p', `f' and `s'.
529 GNU find also supports `D', representing a Door, where the OS provides these.
532 Supported. Interpretation of the response is not locale-dependent
533 (see ENVIRONMENT VARIABLES).
535 .IP "Other predicates"
556 The POSIX standard specifies parentheses `(', `)', negation `!' and the
557 `and' and `or' operators (`-a', `-o').
559 All other options, predicates, expressions and so forth are extensions
560 beyond the POSIX standard. Many of these extensions are not unique to
562 .SH "ENVIRONMENT VARIABLES"
564 Determines the block size used by `-ls'.
566 Provides a default value for the internationalization variables that
569 If set to a non-empty string value, override the values of all the
570 other internationalization variables.
572 The POSIX standard specifies that this variable affects the pattern
573 matching to be used for the `-name' option. GNU find uses the
575 library function, and so support for `LC_COLLATE' depends on the
578 POSIX also specifies that the `LC_COLLATE' environment
579 variable affects the interpretation of the user's response to the
580 query issued by `-ok', but this is not the case for GNU find.
582 This variable affects the treatment of character classes used with
583 the `-name' option, if the system's
585 library function supports this. It has no effect on the behaviour
586 of the `-ok' expression.
588 Determines the locale to be used for internationalised messages.
590 Determines the location of the internationalisation message catalogues.
592 Affects the directores which are searched to find the executables
593 invoked by `-exec' and `-ok'.
596 .B find /tmp -name core -type f -print | xargs /bin/rm -f
601 in or below the directory
603 and delete them. Note that this will work incorrectly if there are
604 any filenames containing newlines or spaces.
606 .B find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
611 in or below the directory
613 and delete them, processing filenames in such a way that file or
614 directory names containing spaces or newlines are correctly handled.
617 .B cut -d: -f1 < /etc/passwd | sort | xargs echo
620 Generates a compact listing of all the users on the system.
624 .B find . -type f -exec file '{}' \e\;
627 Runs `file' on every file in or below the current directory. Notice
628 that the braces are enclosed in single quote marks to protect them
629 from interpretation as shell script punctuation. The semicolon is
630 similarly protected by the use of a backslash, though ';' could have
631 been used in that case also.
636 exits with status 0 if all files are processed successfully, greater
637 than 0 if errors occur.
639 \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1), \fBxargs\fP(1)
640 \fBFinding Files\fP (on-line in Info, or printed)
643 The best way to report a bug is to use the form at
644 http://savannah.gnu.org/bugs/?group=findutils.
645 The reason for this is that you will then be able to track progress in
646 fixing the problem. Other comments about \fBfind\fP(1) and about
647 the findutils package in general can be sent to the
649 mailing list. To join the list, send email to
650 .IR bug-findutils-request@gnu.org .