1 .TH FIND 1 \" -*- nroff -*-
3 find \- search for files in a directory hierarchy
6 [\-H] [\-L] [\-P] [\-D debugopts] [\-Olevel] [path...] [expression]
9 documents the GNU version of
13 searches the directory tree rooted at each given file name by
14 evaluating the given expression from left to right, according to the
15 rules of precedence (see section OPERATORS), until the outcome is
16 known (the left hand side is false for \fIand\fR operations, true for
17 \fIor\fR), at which point
19 moves on to the next file name.
23 in an environment where security is important (for example if you are
24 using it to seach directories that are writable by other users), you
25 should read the "Security Considerations" chapter of the findutils
26 documentation, which is called \fBFinding Files\fP and comes with
27 findutils. That document also includes a lot more detail
28 and discussion than this manual page, so you may find it a more useful
29 source of information.
31 The `\-H', `\-L' and `\-P' options control the treatment of symbolic
32 links. Command-line arguments following these are taken to be names
33 of files or directories to be examined, up to the first argument that
34 begins with `\-', or the argument `(' or `!'. That argument and any
35 following arguments are taken to be the expression describing what is
36 to be searched for. If no paths are given, the current directory is
37 used. If no expression is given, the expression `\-print' is used
38 (but you should probably consider using `\-print0' instead, anyway).
40 This manual page talks about `options' within the expression list.
41 These options control the behaviour of
43 but are specified immediately after the last path name. The five
44 `real' options `\-H', `\-L', `\-P', `\-D' and `\-O' must appear before
45 the first path name, if at all. A double dash `\-\-' can also be used
46 to signal that any remaining arguments are not options (though
47 ensuring that all start points begin with either `./' or `/' is
48 generally safer if you use wildcards in the list of start points).
50 Never follow symbolic links. This is the default behaviour. When
52 examines or prints information a file, and the file is a symbolic
53 link, the information used shall be taken from the properties of the
57 Follow symbolic links. When
59 examines or prints information about files, the information used shall
60 be taken from the properties of the file to which the link points, not
61 from the link itself (unless it is a broken symbolic link or
63 is unable to examine the file to which the link points). Use of this
64 option implies \-noleaf. If you later use the \-P option, \-noleaf
65 will still be in effect. If \-L is in effect and
67 discovers a symbolic link to a subdirectory during its search,
68 the subdirectory pointed to by the symbolic link will be searched.
70 When the \-L option is in effect, the \-type predicate will always
71 match against the type of the file that a symbolic link points to
72 rather than the link itself (unless the symbolic link is broken).
73 Using \-L causes the \-lname and \-ilname predicates always to return
77 Do not follow symbolic links, except while processing the command
80 examines or prints information about files, the information used
81 shall be taken from the properties of the symbolic link itself. The
82 only exception to this behaviour is when a file specified on the
83 command line is a symbolic link, and the link can be resolved. For
84 that situation, the information used is taken from whatever the link
85 points to (that is, the link is followed). The information about the
86 link itself is used as a fallback if the file pointed to by the
87 symbolic link cannot be examined. If \-H is in effect and one of the
88 paths specified on the command line is a symbolic link to a directory,
89 the contents of that directory will be examined (though of course
90 \-maxdepth 0 would prevent this).
92 If more than one of \-H, \-L and \-P is specified, each overrides the
93 others; the last one appearing on the command line takes effect.
94 Since it is the default, the \-P option should be considered to be in
95 effect unless either \-H or \-L is specified.
99 frequently stats files during the processing of the command line
100 itself, before any searching has begun. These options also affect how
101 those arguments are processed. Specifically, there are a number of
102 tests that compare files listed on the command line against a file we
103 are currently considering. In each case, the file specified on the
104 command line will have been examined and some of its properties will
105 have been saved. If the named file is in fact a symbolic link, and
106 the \-P option is in effect (or if neither \-H nor \-L were
107 specified), the information used for the comparison will be taken from
108 the properties of the symbolic link. Otherwise, it will be taken from
109 the properties of the file the link points to. If
111 cannot follow the link (for example because it has insufficient
112 privileges or the link points to a nonexistent file) the properties of
113 the link itself will be used.
115 When the \-H or \-L options are in effect, any symbolic links listed
116 as the argument of \-newer will be dereferenced, and the timestamp
117 will be taken from the file to which the symbolic link points. The
118 same consideration applies to \-newerXY, \-anewer and \-cnewer.
120 The \-follow option has a similar effect to \-L, though it takes
121 effect at the point where it appears (that is, if \-L is not used but
122 \-follow is, any symbolic links appearing after \-follow on the
123 command line will be dereferenced, and those before it will not).
125 .IP "\-D debugoptions"
126 Print diagnostic information; this can be helpful to diagnose problems
129 is not doing what you want. The list of debug options should be comma
130 separated. Compatibility of the debug options is not guaranteed
131 between releases of findutils. For a complete list of valid debug
132 options, see the output of
135 Valid debug options include
138 Explain the debugging options
140 Show the expression tree in its original and optimised form.
142 Print messages as files are examined with the
148 program tries to minimise such calls.
150 Prints diagnostic information relating to the optimisation of the
151 expression tree; see the \-O option.
153 Prints a summary indicating how often each predicate succeeded or
157 Enables query optimisation. The
159 program reorders tests to speed up execution while preserving the
160 overall effect; that is, predicates with side effects are not
161 reordered relative to each other. The optimisations performed at each
162 optimisation level are as follows.
165 Equivalent to optimisation level 1.
167 This is the default optimisation level and corresponds to the
168 traditional behaviour. Expressions are reordered so that tests based
169 only on the names of files (for example \-name
170 and \-regex) are performed first.
174 tests are performed after any tests based only on the names of files,
175 but before any tests that require information from the inode. On many
176 modern versions of Unix, file types are returned by
178 and so these predicates are faster to evaluate than predicates which
179 need to stat the file first.
181 At this optimisation level, the full cost-based query optimiser is
182 enabled. The order of tests is modified so that cheap (i.e. fast)
183 tests are performed first and more expensive ones are performed later,
184 if necessary. Within each cost band, predicates are evaluated earlier
185 or later according to whether they are likely to succeed or not. For \-o,
186 predicates which are likely to succeed are evaluated earlier, and for \-a,
187 predicates which are likely to fail are evaluated earlier.
190 The cost-based optimiser has a fixed idea of how likely any given test
191 is to succeed. In some cases the probability takes account of the
192 specific nature of the test (for example, \-type f
193 is assumed to be more likely to succeed than \-type c).
194 The cost-based optimiser is currently being evaluated. If it does
195 not actually improve the performance of
197 it will be removed again. Conversely, optimisations that prove to be
198 reliable, robust and effective may be enabled at lower optimisation
199 levels over time. However, the default behaviour (i.e. optimisation
200 level 1) will not be changed in the 4.3.x release series. The
201 findutils test suite runs all the tests on
203 at each optimisation level and ensures that the result is the same.
206 The expression is made up of options (which affect overall operation
207 rather than the processing of a specific file, and always return
208 true), tests (which return a true or false value), and actions (which
209 have side effects and return a true or false value), all separated by
210 operators. \-and is assumed where the operator is omitted.
212 If the expression contains no actions other than \-prune, \-print is
213 performed on all files for which the expression is true.
217 All options always return true. Except for \-daystart, \-follow and
218 \-regextype, the options affect all tests, including tests specified
219 before the option. This is because the options are processed when the
220 command line is parsed, while the tests don't do anything until files
221 are examined. The \-daystart, \-follow and \-regextype options are
222 different in this respect, and have an effect only on tests which
223 appear later in the command line. Therefore, for clarity, it is best
224 to place them at the beginning of the expression. A warning is issued
225 if you don't do this.
228 A synonym for \-depth, for compatibility with FreeBSD, NetBSD, MacOS X and OpenBSD.
231 Measure times (for \-amin, \-atime, \-cmin, \-ctime, \-mmin, and \-mtime)
232 from the beginning of today rather than from 24 hours ago. This
233 option only affects tests which appear later on the command line.
236 Process each directory's contents before the directory itself.
239 Deprecated; use the \-L option instead. Dereference symbolic links.
240 Implies \-noleaf. The \-follow option affects only those tests which
241 appear after it on the command line. Unless the \-H or \-L option has
242 been specified, the position of the \-follow option changes the
243 behaviour of the \-newer predicate; any files listed as the argument
244 of \-newer will be dereferenced if they are symbolic links. The same
245 consideration applies to \-newerXY, \-anewer and \-cnewer. Similarly,
246 the \-type predicate will always match against the type of the file
247 that a symbolic link points to rather than the link itself. Using
248 \-follow causes the \-lname and \-ilname predicates always to return
251 .IP "\-help, \-\-help"
252 Print a summary of the command-line usage of
256 .IP \-ignore_readdir_race
257 Normally, \fBfind\fR will emit an error message when it fails to stat a file.
258 If you give this option and a file is deleted between the time \fBfind\fR
259 reads the name of the file from the directory and the time it tries to stat
260 the file, no error message will be issued. This also applies to files
261 or directories whose names are given on the command line. This option takes
262 effect at the time the command line is read, which means that you cannot search
263 one part of the filesystem with this option on and part of it with this option
264 off (if you need to do that, you will need to issue two \fBfind\fR commands
265 instead, one with the option and one without it).
267 .IP "\-maxdepth \fIlevels\fR"
268 Descend at most \fIlevels\fR (a non-negative integer) levels of
269 directories below the command line arguments. `\-maxdepth 0' means
270 only apply the tests and actions to the command line arguments.
272 .IP "\-mindepth \fIlevels\fR"
273 Do not apply any tests or actions at levels less than \fIlevels\fR (a
274 non-negative integer). `\-mindepth 1' means process all files except
275 the command line arguments.
278 Don't descend directories on other filesystems. An alternate name for
279 \-xdev, for compatibility with some other versions of
282 .IP \-noignore_readdir_race
283 Turns off the effect of \-ignore_readdir_race.
286 Do not optimize by assuming that directories contain 2 fewer
287 subdirectories than their hard link count. This option is needed when
288 searching filesystems that do not follow the Unix directory-link
289 convention, such as CD-ROM or MS-DOS filesystems or AFS volume mount
290 points. Each directory on a normal Unix filesystem has at least 2
291 hard links: its name and its `.' entry. Additionally, its
292 subdirectories (if any) each have a `..' entry linked to that
295 is examining a directory, after it has statted 2 fewer subdirectories
296 than the directory's link count, it knows that the rest of the entries
297 in the directory are non-directories (`leaf' files in the directory
298 tree). If only the files' names need to be examined, there is no need
299 to stat them; this gives a significant increase in search speed.
301 .IP "\-regextype \fItype\fR"
302 Changes the regular expression syntax understood by
306 tests which occur later on the command line. Currently-implemented
307 types are emacs (this is the default), posix-awk, posix-basic,
308 posix-egrep and posix-extended.
310 .IP "\-version, \-\-version"
311 Print the \fBfind\fR version number and exit.
313 .IP "\-warn, \-nowarn"
314 Turn warning messages on or off. These warnings apply only to the
315 command line usage, not to any conditions that
317 might encounter when it searches directories. The default behaviour
318 corresponds to \-warn if standard input is a tty, and to \-nowarn
322 Don't descend directories on other filesystems.
325 Some tests, for example
329 allow comparison between the file currently being examined and some
330 reference file specified on the command line. When these tests are
331 used, the interpretation of the reference file is determined by the
339 but the reference file is only examined once, at the time the command
340 line is parsed. If the reference file cannot be examined (for
343 system call fails for it), an error message is issued, and
345 exits with a nonzero status.
347 Numeric arguments can be specified as
360 File was last accessed \fIn\fR minutes ago.
362 .IP "\-anewer \fIfile\fR"
363 File was last accessed more recently than \fIfile\fR was modified. If
364 \fIfile\fR is a symbolic link and the \-H option or the \-L option is
365 in effect, the access time of the file it points to is always
368 .IP "\-atime \fIn\fR"
369 File was last accessed \fIn\fR*24 hours ago.
370 When find figures out how many 24-hour periods ago the file
371 was last accessed, any fractional part is ignored, so to match
374 a file has to have been accessed at least
379 File's status was last changed \fIn\fR minutes ago.
381 .IP "\-cnewer \fIfile\fR"
382 File's status was last changed more recently than \fIfile\fR was
383 modified. If \fIfile\fR is a symbolic link and the \-H option or the
384 \-L option is in effect, the status-change time of the file it points
387 .IP "\-ctime \fIn\fR"
388 File's status was last changed \fIn\fR*24 hours ago.
391 to understand how rounding affects the interpretation of file status
395 File is empty and is either a regular file or a directory.
398 Matches files which are executable and directories which are
399 searchable (in a file name resolution sense). This takes into account
400 access control lists and other permissions artefacts which the
402 test ignores. This test makes use of the
404 system call, and so can be fooled by NFS servers which do UID
405 mapping (or root-squashing), since many systems implement
407 in the client's kernel and so cannot make use of the UID mapping
408 information held on the server. Because this test is based only on
411 system call, there is no guarantee that a file for which this test
412 succeeds can actually be executed.
417 .IP "\-fstype \fItype\fR"
418 File is on a filesystem of type \fItype\fR. The valid filesystem
419 types vary among different versions of Unix; an incomplete list of
420 filesystem types that are accepted on some version of Unix or another
421 is: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K. You can use \-printf
422 with the %F directive to see the types of your filesystems.
425 File's numeric group ID is \fIn\fR.
427 .IP "\-group \fIgname\fR"
428 File belongs to group \fIgname\fR (numeric group ID allowed).
430 .IP "\-ilname \fIpattern\fR"
431 Like \-lname, but the match is case insensitive.
432 If the \-L option or the \-follow option is in effect, this test
433 returns false unless the symbolic link is broken.
435 .IP "\-iname \fIpattern\fR"
436 Like \-name, but the match is case insensitive. For example, the
437 patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo',
438 `fOo', etc. In these patterns, unlike filename expansion by the
439 shell, an initial '.' can be matched by `*'. That is,
441 will match the file `.foobar'. Please note that you should quote
442 patterns as a matter of course, otherwise the shell will expand any
443 wildcard characters in them.
446 File has inode number \fIn\fR. It is normally easier to use the
450 .IP "\-ipath \fIpattern\fR"
451 Behaves in the same way as \-iwholename. This option is deprecated,
452 so please do not use it.
454 .IP "\-iregex \fIpattern\fR"
455 Like \-regex, but the match is case insensitive.
457 .IP "\-iwholename \fIpattern\fR"
458 Like \-wholename, but the match is case insensitive.
460 .IP "\-links \fIn\fR"
461 File has \fIn\fR links.
463 .IP "\-lname \fIpattern\fR"
464 File is a symbolic link whose contents match shell pattern
465 \fIpattern\fR. The metacharacters do not treat `/' or `.' specially.
466 If the \-L option or the \-follow option is in effect, this test
467 returns false unless the symbolic link is broken.
470 File's data was last modified \fIn\fR minutes ago.
472 .IP "\-mtime \fIn\fR"
473 File's data was last modified \fIn\fR*24 hours ago.
476 to understand how rounding affects the interpretation of file
479 .IP "\-name \fIpattern\fR"
480 Base of file name (the path with the leading directories removed)
481 matches shell pattern \fIpattern\fR. The metacharacters (`*', `?',
482 and `[]') match a `.' at the start of the base name (this is a change
483 in findutils-4.2.2; see section STANDARDS CONFORMANCE below). To ignore a
484 directory and the files under it, use \-prune; see an example in the
485 description of \-wholename. Braces are not recognised as being
486 special, despite the fact that some shells including Bash imbue braces
487 with a special meaning in shell patterns. The filename matching is
488 performed with the use of the
490 library function. Don't forget to enclose the pattern in quotes
491 in order to protect it from expansion by the shell.
493 .IP "\-newer \fIfile\fR"
494 File was modified more recently than \fIfile\fR. If \fIfile\fR is a
495 symbolic link and the \-H option or the \-L option is in effect, the
496 modification time of the file it points to is always used.
498 .IP "\-newerXY \fIreference\fR"
499 Compares the timestamp of the current file with \fIreference\fR.
502 argument is normally the name of a file (and one of its timestamps is
503 used for the comparison) but it may also be a string describing an
508 are placeholders for other letters, and these letters select which
512 is used for the comparison.
519 a The access time of the file \fIreference\fR
520 B The birth time of the file \fIreference\fR
521 c The inode status change time of \fIreference\fR
522 m The modification time of the file \fIreference\fR
523 t \fIreference\fR is interpreted directly as a time
526 Some combinations are invalid; for example, it is invalid for
530 Some combinations are not implemented on all systems; for example
532 is not supported on all systems. If an invalid or unsupported
535 is specified, a fatal error results. Time specifications are
536 interpreted as for the argument to the \-d option of GNU
538 If you try to use the birth time of a reference file, and the birth
539 time cannot be determined, a fatal error message results. If you
540 specify a test which refers to the birth time of files being examined,
541 this test will fail for any files where the birth time is unknown.
544 No group corresponds to file's numeric group ID.
547 No user corresponds to file's numeric user ID.
549 .IP "\-path \fIpattern\fR"
550 See \-wholename. The predicate \-path is also supported by HP-UX
553 .IP "\-perm \fImode\fR"
554 File's permission bits are exactly \fImode\fR (octal or symbolic).
555 Since an exact match is required, if you want to use this form for
556 symbolic modes, you may have to specify a rather complex mode string.
557 For example `\-perm g=w' will only match files which have mode 0020
558 (that is, ones for which group write permission is the only permission
559 set). It is more likely that you will want to use the `/' or `-'
560 forms, for example `\-perm \-g=w', which matches any file with group
561 write permission. See the
563 section for some illustrative examples.
565 .IP "\-perm \-\fImode\fR"
566 All of the permission bits \fImode\fR are set for the file.
567 Symbolic modes are accepted in this form, and this is usually the way
568 in which would want to use them. You must specify `u', `g' or `o' if
569 you use a symbolic mode. See the
571 section for some illustrative examples.
573 .IP "\-perm /\fImode\fR"
574 Any of the permission bits \fImode\fR are set for the file. Symbolic
575 modes are accepted in this form. You must specify `u', `g' or `o' if
576 you use a symbolic mode. See the
578 section for some illustrative examples. If no permission bits in
580 are set, this test currently matches no files. However, it will soon
581 be changed to match any file (the idea is to be more consistent with
586 .IP "\-perm +\fImode\fR"
587 Deprecated, old way of searching for files with any of the permission
588 bits in \fImode\fR set. You should use
589 .B \-perm \fI/mode\fR
590 instead. Trying to use the `+' syntax with symbolic modes will yield
591 surprising results. For example, `+u+x' is a valid symbolic mode
592 (equivalent to +u,+x, i.e. 0111) and will therefore not be evaluated
594 .B \-perm +\fImode\fR
595 but instead as the exact mode specifier
597 and so it matches files with exact permissions 0111 instead of files with any
598 execute bit set. If you found this paragraph confusing, you're not
600 .B \-perm /\fImode\fR.
603 test is deprecated because the POSIX specification requires the
604 interpretation of a leading `+' as being part of a symbolic mode, and
605 so we switched to using `/' instead.
608 Matches files which are readable. This takes into account access
609 control lists and other permissions artefacts which the
611 test ignores. This test makes use of the
613 system call, and so can be fooled by NFS servers which do UID
614 mapping (or root-squashing), since many systems implement
616 in the client's kernel and so cannot make use of the UID mapping
617 information held on the server.
619 .IP "\-regex \fIpattern\fR"
620 File name matches regular expression \fIpattern\fR. This is a match
621 on the whole path, not a search. For example, to match a file named
622 `./fubar3', you can use the regular expression `.*bar.' or `.*b.*3',
623 but not `f.*r3'. The regular expressions understood by
625 are by default Emacs Regular Expressions, but this can be
630 .IP "\-samefile \fIname\fR"
631 File refers to the same inode as \fIname\fR. When \-L is in effect,
632 this can include symbolic links.
634 .IP "\-size \fIn\fR[cwbkMG]"
635 File uses \fIn\fP units of space. The following suffixes
639 for 512-byte blocks (this is the default if no suffix is used)
645 for Kilobytes (units of 1024 bytes)
647 for Megabytes (units of 1048576 bytes)
649 for Gigabytes (units of 1073741824 bytes)
652 The size does not count indirect blocks, but it does count blocks in
653 sparse files that are not actually allocated. Bear in mind that the
654 `%k' and `%b' format specifiers of \-printf handle sparse files
655 differently. The `b' suffix always denotes 512-byte blocks and never
656 1 Kilobyte blocks, which is different to the behaviour of \-ls.
662 File is of type \fIc\fR:
665 block (buffered) special
667 character (unbuffered) special
675 symbolic link; this is never true if the \-L option or the \-follow
676 option is in effect, unless the symbolic link is broken. If you want
677 to search for symbolic links when \-L is in effect, use \-xtype.
684 File's numeric user ID is \fIn\fR.
687 File was last accessed \fIn\fR days after its status was last changed.
689 .IP "\-user \fIuname\fR"
690 File is owned by user \fIuname\fR (numeric user ID allowed).
692 .IP "\-wholename \fIpattern\fR"
693 File name matches shell pattern \fIpattern\fR. The metacharacters do
694 not treat `/' or `.' specially; so, for example,
697 find . \-wholename "./sr*sc"
700 will print an entry for a directory called `./src/misc' (if one
701 exists). To ignore a whole directory tree, use \-prune rather than
702 checking every file in the tree. For example, to skip the
703 directory `src/emacs' and all files and directories under it, and
704 print the names of the other files found, do something like this:
707 find . \-wholename ./src/emacs \-prune \-o \-print
712 Matches files which are writable. This takes into account access
713 control lists and other permissions artefacts which the
715 test ignores. This test makes use of the
717 system call, and so can be fooled by NFS servers which do UID
718 mapping (or root-squashing), since many systems implement
720 in the client's kernel and so cannot make use of the UID mapping
721 information held on the server.
723 .IP "\-xtype \fIc\fR"
724 The same as \-type unless the file is a symbolic link. For symbolic
725 links: if the \-H or \-P option was specified, true if the file is a
726 link to a file of type \fIc\fR; if the \-L option has been given, true
727 if \fIc\fR is `l'. In other words, for symbolic links, \-xtype checks
728 the type of the file that \-type does not check.
732 Delete files; true if removal succeeded. If the removal failed, an
733 error message is issued. Use of this action automatically turns on
734 the `\-depth' option.
736 .IP "\-exec \fIcommand\fR ;"
737 Execute \fIcommand\fR; true if 0 status is returned. All following
740 are taken to be arguments to the command until an argument consisting
741 of `;' is encountered. The string `{}' is replaced by the current
742 file name being processed everywhere it occurs in the arguments to the
743 command, not just in arguments where it is alone, as in some versions
746 Both of these constructions might need to be escaped (with a `\e') or
747 quoted to protect them from expansion by the shell. See the
749 section for examples of the use of the `\-exec' option. The specified
750 command is run once for each matched file.
751 The command is executed in the starting directory. There are
752 unavoidable security problems surrounding use of the \-exec action;
753 you should use the \-execdir option instead.
755 .IP "\-exec \fIcommand\fR {} +"
756 This variant of the \-exec action runs the specified command on the
757 selected files, but the command line is built by appending each
758 selected file name at the end; the total number of invocations of the
759 command will be much less than the number of matched files. The
760 command line is built in much the same way that
762 builds its command lines. Only one instance of `{}' is allowed within
763 the command. The command is executed in the starting directory.
765 .IP "\-execdir \fIcommand\fR ;"
766 .IP "\-execdir \fIcommand\fR {} +"
767 Like \-exec, but the specified command is run from the subdirectory
768 containing the matched file, which is not normally the directory in
771 This a much more secure method for invoking commands, as it avoids
772 race conditions during resolution of the paths to the matched files.
773 As with the \-exec action, the `+' form of \-execdir will build a
774 command line to process more than one matched file, but any given
777 will only list files that exist in the same subdirectory. If you use
778 this option, you must ensure that your
780 environment variable does not reference the current directory;
781 otherwise, an attacker can run any commands they like by leaving an
782 appropriately-named file in a directory in which you will run
785 .IP "\-fls \fIfile\fR"
786 True; like \-ls but write to \fIfile\fR like \-fprint.
787 The output file is always created, even if the predicate is never
791 section for information about how unusual characters in filenames are handled.
793 .IP "\-fprint \fIfile\fR"
794 True; print the full file name into file \fIfile\fR. If \fIfile\fR
795 does not exist when \fBfind\fR is run, it is created; if it does
796 exist, it is truncated. The file names ``/dev/stdout'' and
797 ``/dev/stderr'' are handled specially; they refer to the standard
798 output and standard error output, respectively.
799 The output file is always created, even if the predicate is never matched.
802 section for information about how unusual characters in filenames are handled.
804 .IP "\-fprint0 \fIfile\fR"
805 True; like \-print0 but write to \fIfile\fR like \-fprint.
806 The output file is always created, even if the predicate is never matched.
809 section for information about how unusual characters in filenames are handled.
811 .IP "\-fprintf \fIfile\fR \fIformat\fR"
812 True; like \-printf but write to \fIfile\fR like \-fprint.
813 The output file is always created, even if the predicate is never matched.
816 section for information about how unusual characters in filenames are handled.
819 True; list current file in `ls \-dils' format on standard output.
820 The block counts are of 1K blocks, unless the environment variable
821 POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
824 section for information about how unusual characters in filenames are handled.
826 .IP "\-ok \fIcommand\fR ;"
827 Like \-exec but ask the user first (on the standard input); if the
828 response does not start with `y' or `Y', do not run the command, and
829 return false. If the command is run, its standard input is redirected
833 .IP "\-okdir \fIcommand\fR ;"
834 Like \-execdir but ask the user first (on the standard input); if the
835 response does not start with `y' or `Y', do not run the command, and
836 return false. If the command is run, its standard input is redirected
841 True; print the full file name on the standard output, followed by a
842 newline. If you are piping the output of
844 into another program and there is the faintest possibility that the files
845 which you are searching for might contain a newline, then you should
846 seriously consider using the `\-print0' option instead of `\-print'.
849 section for information about how unusual characters in filenames are handled.
852 True; print the full file name on the standard output, followed by a
853 null character (instead of the newline character that `\-print' uses).
854 This allows file names that contain newlines or other types of white
855 space to be correctly interpreted by programs that process the
856 \fBfind\fR output. This option corresponds to the `\-0' option of
859 .IP "\-printf \fIformat\fR"
860 True; print \fIformat\fR on the standard output, interpreting `\e'
861 escapes and `%' directives. Field widths and precisions can be
862 specified as with the `printf' C function. Please note that many of
863 the fields are printed as %s rather than %d, and this may mean that
864 flags don't work as you might expect. This also means that the `\-'
865 flag does work (it forces fields to be left-aligned). Unlike \-print,
866 \-printf does not add a newline at the end of the string. The escapes
874 Stop printing from this format immediately and flush the output.
888 A literal backslash (`\e').
890 The character whose ASCII code is NNN (octal).
892 A `\e' character followed by any other character is treated as an
893 ordinary character, so they both are printed.
895 A literal percent sign.
897 File's last access time in the format returned by the C `ctime' function.
899 File's last access time in the format specified by \fIk\fR, which is
900 either `@' or a directive for the C `strftime' function. The possible
901 values for \fIk\fR are listed below; some of them might not be
902 available on all systems, due to differences in `strftime' between
906 seconds since Jan. 1, 1970, 00:00 GMT, with fractional part.
922 time, 12-hour (hh:mm:ss [AP]M)
924 Second (00.00 .. 61.00). There is a fractional part.
926 time, 24-hour (hh:mm:ss)
928 Date and time, separated by `+', for example
929 `2004\-04\-28+22:22:05.0'. This is a GNU extension. The time is
930 given in the current timezone (which may be affected by setting the TZ
931 environment variable). The seconds field includes a fractional part.
933 locale's time representation (H:M:S)
935 time zone (e.g., EDT), or nothing if no time zone is determinable
939 locale's abbreviated weekday name (Sun..Sat)
941 locale's full weekday name, variable length (Sunday..Saturday)
943 locale's abbreviated month name (Jan..Dec)
945 locale's full month name, variable length (January..December)
947 locale's date and time (Sat Nov 04 12:02:33 EST 1989). The format is
950 and so to preserve compatibility with that format, there is no fractional part
951 in the seconds field.
953 day of month (01..31)
959 day of year (001..366)
963 week number of year with Sunday as first day of week (00..53)
967 week number of year with Monday as first day of week (00..53)
969 locale's date representation (mm/dd/yy)
971 last two digits of year (00..99)
976 The amount of disk space used for this file in 512-byte blocks. Since disk
977 space is allocated in multiples of the filesystem block size this is usually
978 greater than %s/512, but it can also be smaller if the file is a sparse file.
980 File's last status change time in the format returned by the C `ctime'
983 File's last status change time in the format specified by \fIk\fR,
984 which is the same as for %A.
986 File's depth in the directory tree; 0 means the file is a command line
989 The device number on which the file exists (the st_dev field of struct
992 File's name with any leading directories removed (only the last element).
994 Type of the filesystem the file is on; this value can be used for
997 File's group name, or numeric group ID if the group has no name.
999 File's numeric group ID.
1001 Leading directories of file's name (all but the last element).
1002 If the file name contains no slashes (since it is in the current
1003 directory) the %h specifier expands to ".".
1005 Command line argument under which file was found.
1007 File's inode number (in decimal).
1009 The amount of disk space used for this file in 1K blocks. Since disk space is
1010 allocated in multiples of the filesystem block size this is usually greater
1011 than %s/1024, but it can also be smaller if the file is a sparse file.
1013 Object of symbolic link (empty string if file is not a symbolic link).
1015 File's permission bits (in octal). This option uses the `traditional'
1016 numbers which most Unix implementations use, but if your particular
1017 implementation uses an unusual ordering of octal permissions bits, you
1018 will see a difference between the actual value of the file's mode and
1019 the output of %m. Normally you will want to have a leading
1020 zero on this number, and to do this, you should use the
1022 flag (as in, for example, `%#m').
1024 File's permissions (in symbolic form, as for
1026 This directive is supported in findutils 4.2.5 and later.
1028 Number of hard links to file.
1032 File's name with the name of the command line argument under which
1033 it was found removed.
1035 File's size in bytes.
1037 File's sparseness. This is calculated as (BLOCKSIZE*st_blocks /
1038 st_size). The exact value you will get for an ordinary file of a
1039 certain length is system-dependent. However, normally sparse files
1040 will have values less than 1.0, and files which use indirect blocks
1041 may have a value which is greater than 1.0. The value used for
1042 BLOCKSIZE is system-dependent, but is usually 512 bytes. If the file
1043 size is zero, the value printed is undefined. On systems which lack
1044 support for st_blocks, a file's sparseness is assumed to be 1.0.
1046 File's last modification time in the format returned by the C `ctime'
1049 File's last modification time in the format specified by \fIk\fR,
1050 which is the same as for %A.
1052 File's user name, or numeric user ID if the user has no name.
1054 File's numeric user ID.
1056 File's type (like in ls \-l), U=unknown type (shouldn't happen)
1058 File's type (like %y), plus follow symlinks: L=loop, N=nonexistent
1060 A `%' character followed by any other character is discarded, but the
1061 other character is printed (don't rely on this, as further format
1062 characters may be introduced). A `%' at the end of the format
1063 argument causes undefined behaviour since there is no following
1064 character. In some locales, it may hide your door keys, while in
1065 others it may remove the final page from the novel you are reading.
1067 The %m and %d directives support the
1073 flags, but the other directives do not, even if they
1074 print numbers. Numeric directives that do not support these flags
1083 The `\-' format flag is supported and changes the alignment of a field
1084 from right-justified (which is the default) to left-justified.
1087 .B UNUSUAL FILENAMES
1088 section for information about how unusual characters in filenames are handled.
1093 If \-depth is not given, true; if the file is a directory, do not descend
1096 If \-depth is given, false; no effect.
1099 Exit immediately. No child processes will be left running, but no more
1100 paths specified on the command line will be processed. For example,
1101 .B find /tmp/foo /tmp/bar \-print \-quit
1104 Any command lines which have been built up with
1105 .B \-execdir ... {} +
1106 will be invoked before
1108 exits. The exit status may or may not be zero, depending on whether
1109 an error has already occurred.
1111 .SS UNUSUAL FILENAMES
1112 Many of the actions of
1114 result in the printing of data which is under the control of other
1115 users. This includes file names, sizes, modification times and so
1116 forth. File names are a potential problem since they can contain any
1117 character except `\e0' and `/'. Unusual characters in file names can
1118 do unexpected and often undesirable things to your terminal (for
1119 example, changing the settings of your function keys on some
1120 terminals). Unusual characters are handled differently by various
1121 actions, as described below.
1123 .IP "\-print0, \-fprint0\"
1124 Always print the exact filename, unchanged, even if the output is
1125 going to a terminal.
1128 Unusual characters are always escaped. White space, backslash, and
1129 double quote characters are printed using C-style escaping (for
1130 example `\ef', `\e"'). Other unusual characters are printed using an
1131 octal escape. Other printable characters (for \-ls and \-fls these are
1132 the characters between octal 041 and 0176) are printed as-is.
1134 .IP "\-printf, \-fprintf"
1135 If the output is not going to a terminal, it is printed as-is.
1136 Otherwise, the result depends on which directive is in use. The
1137 directives %D, %F, %g, %G, %H, %Y, and %y expand to values which are
1138 not under control of files' owners, and so are printed as-is. The
1139 directives %a, %b, %c, %d, %i, %k, %m, %M, %n, %s, %t, %u and %U have
1140 values which are under the control of files' owners but which cannot
1141 be used to send arbitrary data to the terminal, and so these are
1142 printed as-is. The directives %f, %h, %l, %p and %P are quoted. This
1143 quoting is performed in the same way as for GNU
1145 This is not the same quoting mechanism as the one used for \-ls and
1146 \-fls. If you are able to decide what format to use for the output
1149 then it is normally better to use `\e0' as a terminator
1150 than to use newline, as file names can contain white space and newline
1153 .IP "\-print, \-fprint"
1154 Quoting is handled in the same way as for \-printf and \-fprintf.
1157 in a script or in a situation where the matched files might have
1158 arbitrary names, you should consider using \-print0 instead of
1161 The \-ok and \-okdir actions print the current filename as-is. This
1162 may change in a future release.
1165 Listed in order of decreasing precedence:
1167 .IP "( \fIexpr\fR )"
1168 Force precedence. Since parentheses are special to the shell, you
1169 will normally need to quote them. Many of the examples in this manual
1170 page use backslashes for this purpose: `\e(...\e)' instead of `(...)'.
1173 True if \fIexpr\fR is false. This character will also usually need
1174 protection from interpretation by the shell.
1176 .IP "\-not \fIexpr\fR"
1177 Same as ! \fIexpr\fR, but not POSIX compliant.
1179 .IP "\fIexpr1 expr2\fR"
1180 Two expressions in a row are taken to be joined with an
1181 implied "and"; \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
1183 .IP "\fIexpr1\fR \-a \fIexpr2\fR"
1184 Same as \fIexpr1 expr2\fR.
1186 .IP "\fIexpr1\fR \-and \fIexpr2\fR"
1187 Same as \fIexpr1 expr2\fR, but not POSIX compliant.
1189 .IP "\fIexpr1\fR \-o \fIexpr2\fR"
1190 Or; \fIexpr2\fR is not evaluated if \fIexpr1\fR is true.
1192 .IP "\fIexpr1\fR \-or \fIexpr2\fR"
1193 Same as \fIexpr1\fR \-o \fIexpr2\fR, but not POSIX compliant.
1195 .IP "\fIexpr1\fR , \fIexpr2\fR"
1196 List; both \fIexpr1\fR and \fIexpr2\fR are always evaluated. The
1197 value of \fIexpr1\fR is discarded; the value of the list is the value
1198 of \fIexpr2\fR. The comma operator can be useful for searching for
1199 several different types of thing, but traversing the filesystem
1200 hierarchy only once. The
1202 action can be used to list the various matched items into several
1203 different output files.
1206 .SH "STANDARDS CONFORMANCE"
1207 The following options are specified in the POSIX standard
1208 (IEEE Std 1003.1, 2003 Edition):
1211 This option is supported.
1214 This option is supported.
1217 This option is supported, but POSIX conformance depends on the
1218 POSIX conformance of the system's
1220 library function. As of findutils-4.2.2, shell metacharacters
1221 (`*', `?' or `[]' for example) will match a leading `.', because
1222 IEEE PASC interpretation 126 requires this. This is a change from
1223 previous versions of findutils.
1226 Supported. POSIX specifies `b', `c', `d', `l', `p', `f' and `s'.
1227 GNU find also supports `D', representing a Door, where the OS provides these.
1230 Supported. Interpretation of the response is not locale-dependent
1231 (see ENVIRONMENT VARIABLES).
1234 Supported. If the file specified is a symbolic link, it is always
1235 dereferenced. This is a change from previous behaviour, which used to
1236 take the relevant time from the symbolic link; see the HISTORY section
1239 .IP "Other predicates"
1258 The POSIX standard specifies parentheses `(', `)', negation `!' and the
1259 `and' and `or' operators (`\-a', `\-o').
1261 All other options, predicates, expressions and so forth are extensions
1262 beyond the POSIX standard. Many of these extensions are not unique to
1265 The POSIX standard requires that
1271 utility shall detect infinite loops; that is, entering a
1272 previously visited directory that is an ancestor of the last file
1273 encountered. When it detects an infinite loop, find shall write a
1274 diagnostic message to standard error and shall either recover its
1275 position in the hierarchy or terminate.
1279 complies with these requirements. The link count of
1280 directories which contain entries which are hard links to an ancestor
1281 will often be lower than they otherwise should be. This can mean that
1282 GNU find will sometimes optimise away the visiting of a subdirectory
1283 which is actually a link to an ancestor. Since
1285 does not actually enter such a subdirectory, it is allowed to avoid
1286 emitting a diagnostic message. Although this behaviour may be
1287 somewhat confusing, it is unlikely that anybody actually depends on
1288 this behaviour. If the leaf optimisation has been turned off with
1290 the directory entry will always be examined and the diagnostic message
1291 will be issued where it is appropriate. Symbolic links cannot be used
1292 to create filesystem cycles as such, but if the \-L option or the
1293 \-follow option is in use, a diagnostic message is issued when
1295 encounters a loop of symbolic links. As with loops containing hard
1296 links, the leaf optimisation will often mean that
1298 knows that it doesn't need to call
1302 on the symbolic link, so this diagnostic is frequently not necessary.
1304 The \-d option is supported for compatibility with various BSD systems,
1305 but you should use the POSIX-compliant option \-depth instead.
1307 The POSIXLY_CORRECT environment variable does not affect the behaviour
1308 of the \-regex or \-iregex tests because those tests aren't specified in
1310 .SH "ENVIRONMENT VARIABLES"
1313 Provides a default value for the internationalization variables that
1317 If set to a non-empty string value, override the values of all the
1318 other internationalization variables.
1321 The POSIX standard specifies that this variable affects the pattern
1322 matching to be used for the `\-name' option. GNU find uses the
1324 library function, and so support for `LC_COLLATE' depends on the
1328 POSIX also specifies that the `LC_COLLATE' environment
1329 variable affects the interpretation of the user's response to the
1330 query issued by `\-ok', but this is not the case for GNU find.
1333 This variable affects the treatment of character classes used with
1334 the `\-name' test, if the system's
1336 library function supports this. It has no effect on the behaviour
1337 of the `\-ok' expression.
1340 Determines the locale to be used for internationalised messages.
1343 Determines the location of the internationalisation message catalogues.
1346 Affects the directories which are searched to find the executables
1347 invoked by `\-exec', `\-execdir', `\-ok' and `\-okdir'.
1350 Determines the block size used by `\-ls' and `\-fls'.
1353 is set, blocks are units of 512 bytes. Otherwise
1354 they are units of 1024 bytes.
1357 Affects the time zone used for some of the time-related format
1358 directives of \-printf and \-fprintf.
1361 .B find /tmp \-name core \-type f \-print | xargs /bin/rm \-f
1366 in or below the directory
1368 and delete them. Note that this will work incorrectly if there are
1369 any filenames containing newlines, single or double quotes, or spaces.
1371 .B find /tmp \-name core \-type f \-print0 | xargs \-0 /bin/rm \-f
1376 in or below the directory
1378 and delete them, processing filenames in such a way that file or
1379 directory names containing single or double quotes, spaces or newlines
1380 are correctly handled. The
1382 test comes before the
1384 test in order to avoid having to call
1390 .B find . \-type f \-exec file \(aq{}\(aq \e\;
1393 Runs `file' on every file in or below the current directory. Notice
1394 that the braces are enclosed in single quote marks to protect them
1395 from interpretation as shell script punctuation. The semicolon is
1396 similarly protected by the use of a backslash, though single quotes
1397 could have been used in that case also.
1402 .B \e( \-perm \-4000 \-fprintf /root/suid.txt "%#m %u %p\en" \e) , \e
1403 .B \e( \-size +100M \-fprintf /root/big.txt "%\-10s %p\en" \e)
1406 Traverse the filesystem just once, listing setuid files and
1409 and large files into
1414 .B find $HOME \-mtime 0
1417 Search for files in your home directory which have been modified in
1418 the last twenty-four hours. This command works this way because the
1419 time since each file was last modified is divided by 24 hours and any
1420 remainder is discarded. That means that to match
1423 a file will have to have a modification in the past which is less than
1428 .B find /sbin /usr/sbin -executable \e! -readable \-print
1431 Search for files which are executable but not readable.
1435 .B find . \-perm 664
1438 Search for files which have read and write permission for their owner,
1439 and group, but which other users can read but not write to. Files
1440 which meet these criteria but have other permissions bits set (for
1441 example if someone can execute the file) will not be matched.
1445 .B find . \-perm \-664
1448 Search for files which have read and write permission for their owner
1449 and group, and which other users can read, without regard to the
1450 presence of any extra permission bits (for example the executable
1451 bit). This will match a file which has mode 0777, for example.
1455 .B find . \-perm /222
1458 Search for files which are writable by somebody (their owner, or
1459 their group, or anybody else).
1463 .B find . \-perm /220
1464 .B find . \-perm /u+w,g+w
1465 .B find . \-perm /u=w,g=w
1468 All three of these commands do the same thing, but the first one uses
1469 the octal representation of the file mode, and the other two use the
1470 symbolic form. These commands all search for files which are
1471 writable by either their owner or their group. The files don't have
1472 to be writable by both the owner and group to be matched; either will
1477 .B find . \-perm \-220
1478 .B find . \-perm \-g+w,u+w
1481 Both these commands do the same thing; search for files which are
1482 writable by both their owner and their group.
1486 .B find . \-perm \-444 \-perm /222 ! \-perm /111
1487 .B find . \-perm \-a+r \-perm /a+w ! \-perm /a+x
1490 These two commands both search for files that are readable for
1491 everybody (\-perm \-444 or \-perm \-a+r), have at least on write bit
1492 set (\-perm /222 or \-perm /a+w) but are not executable for anybody (!
1493 \-perm /111 and ! \-perm /a+x respectively)
1498 .B find . \-name .snapshot \-prune \-o \e( \e! \-name "*~" \-print0 \e)|
1499 .B cpio \-pmd0 /dest-dir
1502 This command copies the contents of
1506 but omits files and directories named
1508 (and anything in them). It also omits files or directories whose name
1511 but not their contents. The construct
1512 .B \-prune \-o \e( ... \-print0 \e)
1513 is quite common. The idea here is that the expression before
1515 matches things which are to be pruned. However, the
1517 action itself returns true, so the following
1519 ensures that the right hand side is evaluated only for those
1520 directories which didn't get pruned (the contents of the pruned
1521 directories are not even visited, so their contents are irrelevant).
1522 The expression on the right hand side of the
1524 is in parentheses only for clarity. It emphasises that the
1526 action takes place only for things that didn't have
1528 applied to them. Because the default `and' condition between tests
1529 binds more tightly than
1531 this is the default anyway, but the parentheses help to show
1537 exits with status 0 if all files are processed successfully, greater
1538 than 0 if errors occur. This is deliberately a very broad
1539 description, but if the return value is non-zero, you should not rely
1540 on the correctness of the results of
1544 \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1), \fBxargs\fP(1),
1545 \fBchmod\fP(1), \fBfnmatch\fP(3), \fBregex\fP(7), \fBstat\fP(2),
1546 \fBlstat\fP(2), \fBls\fP(1), \fBprintf\fP(3), \fBstrftime\fP(3),
1547 \fBctime\fP(3), \fBFinding Files\fP (on-line in Info, or printed).
1549 As of findutils-4.2.2, shell metacharacters (`*', `?' or `[]' for
1550 example) used in filename patterns will match a leading `.', because
1551 IEEE POSIX interpretation 126 requires this.
1555 was deprecated in findutils-4.2.21, in favour of
1558 As of findutils-4.3.3,
1560 now matches all files instead of none.
1562 Nanosecond-resolution
1563 timestamps were implemented in findutils-4.3.3.
1566 Feature Added in Also occurs in
1574 \-exec ... + 4.2.12 POSIX
1575 \-execdir 4.2.12 BSD
1586 \-ignore_readdir_race 4.2.0
1595 .B $ find . \-name *.c \-print
1596 find: paths must precede expression
1597 Usage: find [\-H] [\-L] [\-P] [\-Olevel] [\-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
1600 This happens because
1602 has been expanded by the shell
1605 actually receiving a command line like this:
1608 .B find . \-name bigram.c code.c frcode.c locate.c \-print
1611 That command is of course not going to work. Instead of doing things
1612 this way, you should enclose the pattern in quotes or escape the wildcard:
1614 .B $ find . \-name \e*.c \-print
1619 There are security problems inherent in the behaviour that the POSIX
1620 standard specifies for
1622 which therefore cannot be fixed. For example, the \-exec action is
1623 inherently insecure, and \-execdir should be used instead.
1624 Please see \fBFinding Files\fP for more information.
1626 The environment variable
1628 has no effect on the
1632 The best way to report a bug is to use the form at
1633 http://savannah.gnu.org/bugs/?group=findutils.
1634 The reason for this is that you will then be able to track progress in
1635 fixing the problem. Other comments about \fBfind\fP(1) and about
1636 the findutils package in general can be sent to the
1638 mailing list. To join the list, send email to
1639 .IR bug\-findutils\-request@gnu.org .