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. The
237 \-delete action also implies \-depth.
240 Deprecated; use the \-L option instead. Dereference symbolic links.
241 Implies \-noleaf. The \-follow option affects only those tests which
242 appear after it on the command line. Unless the \-H or \-L option has
243 been specified, the position of the \-follow option changes the
244 behaviour of the \-newer predicate; any files listed as the argument
245 of \-newer will be dereferenced if they are symbolic links. The same
246 consideration applies to \-newerXY, \-anewer and \-cnewer. Similarly,
247 the \-type predicate will always match against the type of the file
248 that a symbolic link points to rather than the link itself. Using
249 \-follow causes the \-lname and \-ilname predicates always to return
252 .IP "\-help, \-\-help"
253 Print a summary of the command-line usage of
257 .IP \-ignore_readdir_race
258 Normally, \fBfind\fR will emit an error message when it fails to stat a file.
259 If you give this option and a file is deleted between the time \fBfind\fR
260 reads the name of the file from the directory and the time it tries to stat
261 the file, no error message will be issued. This also applies to files
262 or directories whose names are given on the command line. This option takes
263 effect at the time the command line is read, which means that you cannot search
264 one part of the filesystem with this option on and part of it with this option
265 off (if you need to do that, you will need to issue two \fBfind\fR commands
266 instead, one with the option and one without it).
268 .IP "\-maxdepth \fIlevels\fR"
269 Descend at most \fIlevels\fR (a non-negative integer) levels of
270 directories below the command line arguments. `\-maxdepth 0' means
271 only apply the tests and actions to the command line arguments.
273 .IP "\-mindepth \fIlevels\fR"
274 Do not apply any tests or actions at levels less than \fIlevels\fR (a
275 non-negative integer). `\-mindepth 1' means process all files except
276 the command line arguments.
279 Don't descend directories on other filesystems. An alternate name for
280 \-xdev, for compatibility with some other versions of
283 .IP \-noignore_readdir_race
284 Turns off the effect of \-ignore_readdir_race.
287 Do not optimize by assuming that directories contain 2 fewer
288 subdirectories than their hard link count. This option is needed when
289 searching filesystems that do not follow the Unix directory-link
290 convention, such as CD-ROM or MS-DOS filesystems or AFS volume mount
291 points. Each directory on a normal Unix filesystem has at least 2
292 hard links: its name and its `.' entry. Additionally, its
293 subdirectories (if any) each have a `..' entry linked to that
296 is examining a directory, after it has statted 2 fewer subdirectories
297 than the directory's link count, it knows that the rest of the entries
298 in the directory are non-directories (`leaf' files in the directory
299 tree). If only the files' names need to be examined, there is no need
300 to stat them; this gives a significant increase in search speed.
302 .IP "\-regextype \fItype\fR"
303 Changes the regular expression syntax understood by
307 tests which occur later on the command line. Currently-implemented
308 types are emacs (this is the default), posix-awk, posix-basic,
309 posix-egrep and posix-extended.
311 .IP "\-version, \-\-version"
312 Print the \fBfind\fR version number and exit.
314 .IP "\-warn, \-nowarn"
315 Turn warning messages on or off. These warnings apply only to the
316 command line usage, not to any conditions that
318 might encounter when it searches directories. The default behaviour
319 corresponds to \-warn if standard input is a tty, and to \-nowarn
323 Don't descend directories on other filesystems.
326 Some tests, for example
330 allow comparison between the file currently being examined and some
331 reference file specified on the command line. When these tests are
332 used, the interpretation of the reference file is determined by the
340 but the reference file is only examined once, at the time the command
341 line is parsed. If the reference file cannot be examined (for
344 system call fails for it), an error message is issued, and
346 exits with a nonzero status.
348 Numeric arguments can be specified as
361 File was last accessed \fIn\fR minutes ago.
363 .IP "\-anewer \fIfile\fR"
364 File was last accessed more recently than \fIfile\fR was modified. If
365 \fIfile\fR is a symbolic link and the \-H option or the \-L option is
366 in effect, the access time of the file it points to is always
369 .IP "\-atime \fIn\fR"
370 File was last accessed \fIn\fR*24 hours ago.
371 When find figures out how many 24-hour periods ago the file
372 was last accessed, any fractional part is ignored, so to match
375 a file has to have been accessed at least
380 File's status was last changed \fIn\fR minutes ago.
382 .IP "\-cnewer \fIfile\fR"
383 File's status was last changed more recently than \fIfile\fR was
384 modified. If \fIfile\fR is a symbolic link and the \-H option or the
385 \-L option is in effect, the status-change time of the file it points
388 .IP "\-ctime \fIn\fR"
389 File's status was last changed \fIn\fR*24 hours ago.
392 to understand how rounding affects the interpretation of file status
396 File is empty and is either a regular file or a directory.
399 Matches files which are executable and directories which are
400 searchable (in a file name resolution sense). This takes into account
401 access control lists and other permissions artefacts which the
403 test ignores. This test makes use of the
405 system call, and so can be fooled by NFS servers which do UID
406 mapping (or root-squashing), since many systems implement
408 in the client's kernel and so cannot make use of the UID mapping
409 information held on the server. Because this test is based only on
412 system call, there is no guarantee that a file for which this test
413 succeeds can actually be executed.
418 .IP "\-fstype \fItype\fR"
419 File is on a filesystem of type \fItype\fR. The valid filesystem
420 types vary among different versions of Unix; an incomplete list of
421 filesystem types that are accepted on some version of Unix or another
422 is: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K. You can use \-printf
423 with the %F directive to see the types of your filesystems.
426 File's numeric group ID is \fIn\fR.
428 .IP "\-group \fIgname\fR"
429 File belongs to group \fIgname\fR (numeric group ID allowed).
431 .IP "\-ilname \fIpattern\fR"
432 Like \-lname, but the match is case insensitive.
433 If the \-L option or the \-follow option is in effect, this test
434 returns false unless the symbolic link is broken.
436 .IP "\-iname \fIpattern\fR"
437 Like \-name, but the match is case insensitive. For example, the
438 patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo',
439 `fOo', etc. In these patterns, unlike filename expansion by the
440 shell, an initial '.' can be matched by `*'. That is,
442 will match the file `.foobar'. Please note that you should quote
443 patterns as a matter of course, otherwise the shell will expand any
444 wildcard characters in them.
447 File has inode number \fIn\fR. It is normally easier to use the
451 .IP "\-ipath \fIpattern\fR"
452 Behaves in the same way as \-iwholename. This option is deprecated,
453 so please do not use it.
455 .IP "\-iregex \fIpattern\fR"
456 Like \-regex, but the match is case insensitive.
458 .IP "\-iwholename \fIpattern\fR"
459 Like \-wholename, but the match is case insensitive.
461 .IP "\-links \fIn\fR"
462 File has \fIn\fR links.
464 .IP "\-lname \fIpattern\fR"
465 File is a symbolic link whose contents match shell pattern
466 \fIpattern\fR. The metacharacters do not treat `/' or `.' specially.
467 If the \-L option or the \-follow option is in effect, this test
468 returns false unless the symbolic link is broken.
471 File's data was last modified \fIn\fR minutes ago.
473 .IP "\-mtime \fIn\fR"
474 File's data was last modified \fIn\fR*24 hours ago.
477 to understand how rounding affects the interpretation of file
480 .IP "\-name \fIpattern\fR"
481 Base of file name (the path with the leading directories removed)
482 matches shell pattern \fIpattern\fR. The metacharacters (`*', `?',
483 and `[]') match a `.' at the start of the base name (this is a change
484 in findutils-4.2.2; see section STANDARDS CONFORMANCE below). To ignore a
485 directory and the files under it, use \-prune; see an example in the
486 description of \-path. Braces are not recognised as being
487 special, despite the fact that some shells including Bash imbue braces
488 with a special meaning in shell patterns. The filename matching is
489 performed with the use of the
491 library function. Don't forget to enclose the pattern in quotes
492 in order to protect it from expansion by the shell.
494 .IP "\-newer \fIfile\fR"
495 File was modified more recently than \fIfile\fR. If \fIfile\fR is a
496 symbolic link and the \-H option or the \-L option is in effect, the
497 modification time of the file it points to is always used.
499 .IP "\-newerXY \fIreference\fR"
500 Compares the timestamp of the current file with \fIreference\fR.
503 argument is normally the name of a file (and one of its timestamps is
504 used for the comparison) but it may also be a string describing an
509 are placeholders for other letters, and these letters select which
513 is used for the comparison.
520 a The access time of the file \fIreference\fR
521 B The birth time of the file \fIreference\fR
522 c The inode status change time of \fIreference\fR
523 m The modification time of the file \fIreference\fR
524 t \fIreference\fR is interpreted directly as a time
527 Some combinations are invalid; for example, it is invalid for
531 Some combinations are not implemented on all systems; for example
533 is not supported on all systems. If an invalid or unsupported
536 is specified, a fatal error results. Time specifications are
537 interpreted as for the argument to the \-d option of GNU
539 If you try to use the birth time of a reference file, and the birth
540 time cannot be determined, a fatal error message results. If you
541 specify a test which refers to the birth time of files being examined,
542 this test will fail for any files where the birth time is unknown.
545 No group corresponds to file's numeric group ID.
548 No user corresponds to file's numeric user ID.
550 .IP "\-path \fIpattern\fR"
551 File name matches shell pattern \fIpattern\fR. The metacharacters do
552 not treat `/' or `.' specially; so, for example,
555 find . \-path "./sr*sc"
558 will print an entry for a directory called `./src/misc' (if one
559 exists). To ignore a whole directory tree, use \-prune rather than
560 checking every file in the tree. For example, to skip the
561 directory `src/emacs' and all files and directories under it, and
562 print the names of the other files found, do something like this:
565 find . \-path ./src/emacs \-prune \-o \-print
568 Note that the pattern match test applies to the whole file name,
569 starting from one of the start points named on the command line. It
570 would only make sense to use an absolute path name here if the
571 relevant start point is also an absolute path. This means that this
572 command will never match anything:
575 find bar \-path /foo/bar/myfile \-print
579 is also supported by HP-UX
581 and will be in a forthcoming version of the POSIX standard.
583 .IP "\-perm \fImode\fR"
584 File's permission bits are exactly \fImode\fR (octal or symbolic).
585 Since an exact match is required, if you want to use this form for
586 symbolic modes, you may have to specify a rather complex mode string.
587 For example `\-perm g=w' will only match files which have mode 0020
588 (that is, ones for which group write permission is the only permission
589 set). It is more likely that you will want to use the `/' or `-'
590 forms, for example `\-perm \-g=w', which matches any file with group
591 write permission. See the
593 section for some illustrative examples.
595 .IP "\-perm \-\fImode\fR"
596 All of the permission bits \fImode\fR are set for the file.
597 Symbolic modes are accepted in this form, and this is usually the way
598 in which would want to use them. You must specify `u', `g' or `o' if
599 you use a symbolic mode. See the
601 section for some illustrative examples.
603 .IP "\-perm /\fImode\fR"
604 Any of the permission bits \fImode\fR are set for the file. Symbolic
605 modes are accepted in this form. You must specify `u', `g' or `o' if
606 you use a symbolic mode. See the
608 section for some illustrative examples. If no permission bits in
610 are set, this test currently matches no files. However, it will soon
611 be changed to match any file (the idea is to be more consistent with
616 .IP "\-perm +\fImode\fR"
617 Deprecated, old way of searching for files with any of the permission
618 bits in \fImode\fR set. You should use
619 .B \-perm \fI/mode\fR
620 instead. Trying to use the `+' syntax with symbolic modes will yield
621 surprising results. For example, `+u+x' is a valid symbolic mode
622 (equivalent to +u,+x, i.e. 0111) and will therefore not be evaluated
624 .B \-perm +\fImode\fR
625 but instead as the exact mode specifier
627 and so it matches files with exact permissions 0111 instead of files with any
628 execute bit set. If you found this paragraph confusing, you're not
630 .B \-perm /\fImode\fR.
633 test is deprecated because the POSIX specification requires the
634 interpretation of a leading `+' as being part of a symbolic mode, and
635 so we switched to using `/' instead.
638 Matches files which are readable. This takes into account access
639 control lists and other permissions artefacts which the
641 test ignores. This test makes use of the
643 system call, and so can be fooled by NFS servers which do UID
644 mapping (or root-squashing), since many systems implement
646 in the client's kernel and so cannot make use of the UID mapping
647 information held on the server.
649 .IP "\-regex \fIpattern\fR"
650 File name matches regular expression \fIpattern\fR. This is a match
651 on the whole path, not a search. For example, to match a file named
652 `./fubar3', you can use the regular expression `.*bar.' or `.*b.*3',
653 but not `f.*r3'. The regular expressions understood by
655 are by default Emacs Regular Expressions, but this can be
660 .IP "\-samefile \fIname\fR"
661 File refers to the same inode as \fIname\fR. When \-L is in effect,
662 this can include symbolic links.
664 .IP "\-size \fIn\fR[cwbkMG]"
665 File uses \fIn\fP units of space. The following suffixes
669 for 512-byte blocks (this is the default if no suffix is used)
675 for Kilobytes (units of 1024 bytes)
677 for Megabytes (units of 1048576 bytes)
679 for Gigabytes (units of 1073741824 bytes)
682 The size does not count indirect blocks, but it does count blocks in
683 sparse files that are not actually allocated. Bear in mind that the
684 `%k' and `%b' format specifiers of \-printf handle sparse files
685 differently. The `b' suffix always denotes 512-byte blocks and never
686 1 Kilobyte blocks, which is different to the behaviour of \-ls.
692 File is of type \fIc\fR:
695 block (buffered) special
697 character (unbuffered) special
705 symbolic link; this is never true if the \-L option or the \-follow
706 option is in effect, unless the symbolic link is broken. If you want
707 to search for symbolic links when \-L is in effect, use \-xtype.
714 File's numeric user ID is \fIn\fR.
717 File was last accessed \fIn\fR days after its status was last changed.
719 .IP "\-user \fIuname\fR"
720 File is owned by user \fIuname\fR (numeric user ID allowed).
722 .IP "\-wholename \fIpattern\fR"
723 See \-path. This alternative is less portable than \-path.
726 Matches files which are writable. This takes into account access
727 control lists and other permissions artefacts which the
729 test ignores. This test makes use of the
731 system call, and so can be fooled by NFS servers which do UID
732 mapping (or root-squashing), since many systems implement
734 in the client's kernel and so cannot make use of the UID mapping
735 information held on the server.
737 .IP "\-xtype \fIc\fR"
738 The same as \-type unless the file is a symbolic link. For symbolic
739 links: if the \-H or \-P option was specified, true if the file is a
740 link to a file of type \fIc\fR; if the \-L option has been given, true
741 if \fIc\fR is `l'. In other words, for symbolic links, \-xtype checks
742 the type of the file that \-type does not check.
746 Delete files; true if removal succeeded. If the removal failed, an
747 error message is issued. Use of this action automatically turns on
748 the `\-depth' option. Don't forget that the find command line is
749 evaluated as an expression, so putting \-delete first will make
751 try to delete everything below the starting points you specified.
754 command line that you later intend to use with \-delete, you should
755 explicitly specify \-depth in order to avoid later surprises. Because
756 \-delete implies \-depth, you cannot usefully use \-prune and \-delete
759 .IP "\-exec \fIcommand\fR ;"
760 Execute \fIcommand\fR; true if 0 status is returned. All following
763 are taken to be arguments to the command until an argument consisting
764 of `;' is encountered. The string `{}' is replaced by the current
765 file name being processed everywhere it occurs in the arguments to the
766 command, not just in arguments where it is alone, as in some versions
769 Both of these constructions might need to be escaped (with a `\e') or
770 quoted to protect them from expansion by the shell. See the
772 section for examples of the use of the `\-exec' option. The specified
773 command is run once for each matched file.
774 The command is executed in the starting directory. There are
775 unavoidable security problems surrounding use of the \-exec action;
776 you should use the \-execdir option instead.
778 .IP "\-exec \fIcommand\fR {} +"
779 This variant of the \-exec action runs the specified command on the
780 selected files, but the command line is built by appending each
781 selected file name at the end; the total number of invocations of the
782 command will be much less than the number of matched files. The
783 command line is built in much the same way that
785 builds its command lines. Only one instance of `{}' is allowed within
786 the command. The command is executed in the starting directory.
788 .IP "\-execdir \fIcommand\fR ;"
789 .IP "\-execdir \fIcommand\fR {} +"
790 Like \-exec, but the specified command is run from the subdirectory
791 containing the matched file, which is not normally the directory in
794 This a much more secure method for invoking commands, as it avoids
795 race conditions during resolution of the paths to the matched files.
796 As with the \-exec action, the `+' form of \-execdir will build a
797 command line to process more than one matched file, but any given
800 will only list files that exist in the same subdirectory. If you use
801 this option, you must ensure that your
803 environment variable does not reference `.';
804 otherwise, an attacker can run any commands they like by leaving an
805 appropriately-named file in a directory in which you will run
806 \-execdir. The same applies to having entries in
808 which are empty or which are not absolute directory names.
810 .IP "\-fls \fIfile\fR"
811 True; like \-ls but write to \fIfile\fR like \-fprint.
812 The output file is always created, even if the predicate is never
816 section for information about how unusual characters in filenames are handled.
818 .IP "\-fprint \fIfile\fR"
819 True; print the full file name into file \fIfile\fR. If \fIfile\fR
820 does not exist when \fBfind\fR is run, it is created; if it does
821 exist, it is truncated. The file names ``/dev/stdout'' and
822 ``/dev/stderr'' are handled specially; they refer to the standard
823 output and standard error output, respectively.
824 The output file is always created, even if the predicate is never matched.
827 section for information about how unusual characters in filenames are handled.
829 .IP "\-fprint0 \fIfile\fR"
830 True; like \-print0 but write to \fIfile\fR like \-fprint.
831 The output file is always created, even if the predicate is never matched.
834 section for information about how unusual characters in filenames are handled.
836 .IP "\-fprintf \fIfile\fR \fIformat\fR"
837 True; like \-printf but write to \fIfile\fR like \-fprint.
838 The output file is always created, even if the predicate is never matched.
841 section for information about how unusual characters in filenames are handled.
844 True; list current file in `ls \-dils' format on standard output.
845 The block counts are of 1K blocks, unless the environment variable
846 POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
849 section for information about how unusual characters in filenames are handled.
851 .IP "\-ok \fIcommand\fR ;"
852 Like \-exec but ask the user first (on the standard input); if the
853 response does not start with `y' or `Y', do not run the command, and
854 return false. If the command is run, its standard input is redirected
858 .IP "\-okdir \fIcommand\fR ;"
859 Like \-execdir but ask the user first (on the standard input); if the
860 response does not start with `y' or `Y', do not run the command, and
861 return false. If the command is run, its standard input is redirected
866 True; print the full file name on the standard output, followed by a
867 newline. If you are piping the output of
869 into another program and there is the faintest possibility that the files
870 which you are searching for might contain a newline, then you should
871 seriously consider using the `\-print0' option instead of `\-print'.
874 section for information about how unusual characters in filenames are handled.
877 True; print the full file name on the standard output, followed by a
878 null character (instead of the newline character that `\-print' uses).
879 This allows file names that contain newlines or other types of white
880 space to be correctly interpreted by programs that process the
881 \fBfind\fR output. This option corresponds to the `\-0' option of
884 .IP "\-printf \fIformat\fR"
885 True; print \fIformat\fR on the standard output, interpreting `\e'
886 escapes and `%' directives. Field widths and precisions can be
887 specified as with the `printf' C function. Please note that many of
888 the fields are printed as %s rather than %d, and this may mean that
889 flags don't work as you might expect. This also means that the `\-'
890 flag does work (it forces fields to be left-aligned). Unlike \-print,
891 \-printf does not add a newline at the end of the string. The escapes
899 Stop printing from this format immediately and flush the output.
913 A literal backslash (`\e').
915 The character whose ASCII code is NNN (octal).
917 A `\e' character followed by any other character is treated as an
918 ordinary character, so they both are printed.
920 A literal percent sign.
922 File's last access time in the format returned by the C `ctime' function.
924 File's last access time in the format specified by \fIk\fR, which is
925 either `@' or a directive for the C `strftime' function. The possible
926 values for \fIk\fR are listed below; some of them might not be
927 available on all systems, due to differences in `strftime' between
931 seconds since Jan. 1, 1970, 00:00 GMT, with fractional part.
947 time, 12-hour (hh:mm:ss [AP]M)
949 Second (00.00 .. 61.00). There is a fractional part.
951 time, 24-hour (hh:mm:ss)
953 Date and time, separated by `+', for example
954 `2004\-04\-28+22:22:05.0'. This is a GNU extension. The time is
955 given in the current timezone (which may be affected by setting the TZ
956 environment variable). The seconds field includes a fractional part.
958 locale's time representation (H:M:S)
960 time zone (e.g., EDT), or nothing if no time zone is determinable
964 locale's abbreviated weekday name (Sun..Sat)
966 locale's full weekday name, variable length (Sunday..Saturday)
968 locale's abbreviated month name (Jan..Dec)
970 locale's full month name, variable length (January..December)
972 locale's date and time (Sat Nov 04 12:02:33 EST 1989). The format is
975 and so to preserve compatibility with that format, there is no fractional part
976 in the seconds field.
978 day of month (01..31)
984 day of year (001..366)
988 week number of year with Sunday as first day of week (00..53)
992 week number of year with Monday as first day of week (00..53)
994 locale's date representation (mm/dd/yy)
996 last two digits of year (00..99)
1001 The amount of disk space used for this file in 512-byte blocks. Since disk
1002 space is allocated in multiples of the filesystem block size this is usually
1003 greater than %s/512, but it can also be smaller if the file is a sparse file.
1005 File's last status change time in the format returned by the C `ctime'
1008 File's last status change time in the format specified by \fIk\fR,
1009 which is the same as for %A.
1011 File's depth in the directory tree; 0 means the file is a command line
1014 The device number on which the file exists (the st_dev field of struct
1017 File's name with any leading directories removed (only the last element).
1019 Type of the filesystem the file is on; this value can be used for
1022 File's group name, or numeric group ID if the group has no name.
1024 File's numeric group ID.
1026 Leading directories of file's name (all but the last element).
1027 If the file name contains no slashes (since it is in the current
1028 directory) the %h specifier expands to ".".
1030 Command line argument under which file was found.
1032 File's inode number (in decimal).
1034 The amount of disk space used for this file in 1K blocks. Since disk space is
1035 allocated in multiples of the filesystem block size this is usually greater
1036 than %s/1024, but it can also be smaller if the file is a sparse file.
1038 Object of symbolic link (empty string if file is not a symbolic link).
1040 File's permission bits (in octal). This option uses the `traditional'
1041 numbers which most Unix implementations use, but if your particular
1042 implementation uses an unusual ordering of octal permissions bits, you
1043 will see a difference between the actual value of the file's mode and
1044 the output of %m. Normally you will want to have a leading
1045 zero on this number, and to do this, you should use the
1047 flag (as in, for example, `%#m').
1049 File's permissions (in symbolic form, as for
1051 This directive is supported in findutils 4.2.5 and later.
1053 Number of hard links to file.
1057 File's name with the name of the command line argument under which
1058 it was found removed.
1060 File's size in bytes.
1062 File's sparseness. This is calculated as (BLOCKSIZE*st_blocks /
1063 st_size). The exact value you will get for an ordinary file of a
1064 certain length is system-dependent. However, normally sparse files
1065 will have values less than 1.0, and files which use indirect blocks
1066 may have a value which is greater than 1.0. The value used for
1067 BLOCKSIZE is system-dependent, but is usually 512 bytes. If the file
1068 size is zero, the value printed is undefined. On systems which lack
1069 support for st_blocks, a file's sparseness is assumed to be 1.0.
1071 File's last modification time in the format returned by the C `ctime'
1074 File's last modification time in the format specified by \fIk\fR,
1075 which is the same as for %A.
1077 File's user name, or numeric user ID if the user has no name.
1079 File's numeric user ID.
1081 File's type (like in ls \-l), U=unknown type (shouldn't happen)
1083 File's type (like %y), plus follow symlinks: L=loop, N=nonexistent
1085 A `%' character followed by any other character is discarded, but the
1086 other character is printed (don't rely on this, as further format
1087 characters may be introduced). A `%' at the end of the format
1088 argument causes undefined behaviour since there is no following
1089 character. In some locales, it may hide your door keys, while in
1090 others it may remove the final page from the novel you are reading.
1092 The %m and %d directives support the
1098 flags, but the other directives do not, even if they
1099 print numbers. Numeric directives that do not support these flags
1108 The `\-' format flag is supported and changes the alignment of a field
1109 from right-justified (which is the default) to left-justified.
1112 .B UNUSUAL FILENAMES
1113 section for information about how unusual characters in filenames are handled.
1118 True; if the file is a directory, do not descend into it. If \-depth
1119 is given, false; no effect. Because \-delete implies \-depth, you
1120 cannot usefully use \-prune and \-delete together.
1123 Exit immediately. No child processes will be left running, but no more
1124 paths specified on the command line will be processed. For example,
1125 .B find /tmp/foo /tmp/bar \-print \-quit
1128 Any command lines which have been built up with
1129 .B \-execdir ... {} +
1130 will be invoked before
1132 exits. The exit status may or may not be zero, depending on whether
1133 an error has already occurred.
1135 .SS UNUSUAL FILENAMES
1136 Many of the actions of
1138 result in the printing of data which is under the control of other
1139 users. This includes file names, sizes, modification times and so
1140 forth. File names are a potential problem since they can contain any
1141 character except `\e0' and `/'. Unusual characters in file names can
1142 do unexpected and often undesirable things to your terminal (for
1143 example, changing the settings of your function keys on some
1144 terminals). Unusual characters are handled differently by various
1145 actions, as described below.
1147 .IP "\-print0, \-fprint0\"
1148 Always print the exact filename, unchanged, even if the output is
1149 going to a terminal.
1152 Unusual characters are always escaped. White space, backslash, and
1153 double quote characters are printed using C-style escaping (for
1154 example `\ef', `\e"'). Other unusual characters are printed using an
1155 octal escape. Other printable characters (for \-ls and \-fls these are
1156 the characters between octal 041 and 0176) are printed as-is.
1158 .IP "\-printf, \-fprintf"
1159 If the output is not going to a terminal, it is printed as-is.
1160 Otherwise, the result depends on which directive is in use. The
1161 directives %D, %F, %g, %G, %H, %Y, and %y expand to values which are
1162 not under control of files' owners, and so are printed as-is. The
1163 directives %a, %b, %c, %d, %i, %k, %m, %M, %n, %s, %t, %u and %U have
1164 values which are under the control of files' owners but which cannot
1165 be used to send arbitrary data to the terminal, and so these are
1166 printed as-is. The directives %f, %h, %l, %p and %P are quoted. This
1167 quoting is performed in the same way as for GNU
1169 This is not the same quoting mechanism as the one used for \-ls and
1170 \-fls. If you are able to decide what format to use for the output
1173 then it is normally better to use `\e0' as a terminator
1174 than to use newline, as file names can contain white space and newline
1177 .IP "\-print, \-fprint"
1178 Quoting is handled in the same way as for \-printf and \-fprintf.
1181 in a script or in a situation where the matched files might have
1182 arbitrary names, you should consider using \-print0 instead of
1185 The \-ok and \-okdir actions print the current filename as-is. This
1186 may change in a future release.
1189 Listed in order of decreasing precedence:
1191 .IP "( \fIexpr\fR )"
1192 Force precedence. Since parentheses are special to the shell, you
1193 will normally need to quote them. Many of the examples in this manual
1194 page use backslashes for this purpose: `\e(...\e)' instead of `(...)'.
1197 True if \fIexpr\fR is false. This character will also usually need
1198 protection from interpretation by the shell.
1200 .IP "\-not \fIexpr\fR"
1201 Same as ! \fIexpr\fR, but not POSIX compliant.
1203 .IP "\fIexpr1 expr2\fR"
1204 Two expressions in a row are taken to be joined with an
1205 implied "and"; \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
1207 .IP "\fIexpr1\fR \-a \fIexpr2\fR"
1208 Same as \fIexpr1 expr2\fR.
1210 .IP "\fIexpr1\fR \-and \fIexpr2\fR"
1211 Same as \fIexpr1 expr2\fR, but not POSIX compliant.
1213 .IP "\fIexpr1\fR \-o \fIexpr2\fR"
1214 Or; \fIexpr2\fR is not evaluated if \fIexpr1\fR is true.
1216 .IP "\fIexpr1\fR \-or \fIexpr2\fR"
1217 Same as \fIexpr1\fR \-o \fIexpr2\fR, but not POSIX compliant.
1219 .IP "\fIexpr1\fR , \fIexpr2\fR"
1220 List; both \fIexpr1\fR and \fIexpr2\fR are always evaluated. The
1221 value of \fIexpr1\fR is discarded; the value of the list is the value
1222 of \fIexpr2\fR. The comma operator can be useful for searching for
1223 several different types of thing, but traversing the filesystem
1224 hierarchy only once. The
1226 action can be used to list the various matched items into several
1227 different output files.
1230 .SH "STANDARDS CONFORMANCE"
1231 For closest compliance to the POSIX standard, you should set the
1232 POSIXLY_CORRECT environment variable. The following options are
1233 specified in the POSIX standard (IEEE Std 1003.1, 2003 Edition):
1236 This option is supported.
1239 This option is supported.
1242 This option is supported, but POSIX conformance depends on the
1243 POSIX conformance of the system's
1245 library function. As of findutils-4.2.2, shell metacharacters
1246 (`*', `?' or `[]' for example) will match a leading `.', because
1247 IEEE PASC interpretation 126 requires this. This is a change from
1248 previous versions of findutils.
1251 Supported. POSIX specifies `b', `c', `d', `l', `p', `f' and `s'.
1252 GNU find also supports `D', representing a Door, where the OS provides these.
1255 Supported. Interpretation of the response is not locale-dependent
1256 (see ENVIRONMENT VARIABLES).
1259 Supported. If the file specified is a symbolic link, it is always
1260 dereferenced. This is a change from previous behaviour, which used to
1261 take the relevant time from the symbolic link; see the HISTORY section
1265 Supported. If the POSIXLY_CORRECT environment variable is not set,
1266 some mode arguments (for example +a+x) which are not valid in POSIX
1267 are supported for backward-compatibility.
1269 .IP "Other predicates"
1288 The POSIX standard specifies parentheses `(', `)', negation `!' and the
1289 `and' and `or' operators (`\-a', `\-o').
1291 All other options, predicates, expressions and so forth are extensions
1292 beyond the POSIX standard. Many of these extensions are not unique to
1295 The POSIX standard requires that
1301 utility shall detect infinite loops; that is, entering a
1302 previously visited directory that is an ancestor of the last file
1303 encountered. When it detects an infinite loop, find shall write a
1304 diagnostic message to standard error and shall either recover its
1305 position in the hierarchy or terminate.
1309 complies with these requirements. The link count of
1310 directories which contain entries which are hard links to an ancestor
1311 will often be lower than they otherwise should be. This can mean that
1312 GNU find will sometimes optimise away the visiting of a subdirectory
1313 which is actually a link to an ancestor. Since
1315 does not actually enter such a subdirectory, it is allowed to avoid
1316 emitting a diagnostic message. Although this behaviour may be
1317 somewhat confusing, it is unlikely that anybody actually depends on
1318 this behaviour. If the leaf optimisation has been turned off with
1320 the directory entry will always be examined and the diagnostic message
1321 will be issued where it is appropriate. Symbolic links cannot be used
1322 to create filesystem cycles as such, but if the \-L option or the
1323 \-follow option is in use, a diagnostic message is issued when
1325 encounters a loop of symbolic links. As with loops containing hard
1326 links, the leaf optimisation will often mean that
1328 knows that it doesn't need to call
1332 on the symbolic link, so this diagnostic is frequently not necessary.
1334 The \-d option is supported for compatibility with various BSD systems,
1335 but you should use the POSIX-compliant option \-depth instead.
1337 The POSIXLY_CORRECT environment variable does not affect the behaviour
1338 of the \-regex or \-iregex tests because those tests aren't specified in
1340 .SH "ENVIRONMENT VARIABLES"
1343 Provides a default value for the internationalization variables that
1347 If set to a non-empty string value, override the values of all the
1348 other internationalization variables.
1351 The POSIX standard specifies that this variable affects the pattern
1352 matching to be used for the `\-name' option. GNU find uses the
1354 library function, and so support for `LC_COLLATE' depends on the
1358 POSIX also specifies that the `LC_COLLATE' environment
1359 variable affects the interpretation of the user's response to the
1360 query issued by `\-ok', but this is not the case for GNU find.
1363 This variable affects the treatment of character classes used with
1364 the `\-name' test, if the system's
1366 library function supports this. It has no effect on the behaviour
1367 of the `\-ok' expression.
1370 Determines the locale to be used for internationalised messages.
1373 Determines the location of the internationalisation message catalogues.
1376 Affects the directories which are searched to find the executables
1377 invoked by `\-exec', `\-execdir', `\-ok' and `\-okdir'.
1380 Determines the block size used by
1386 is set, blocks are units of 512 bytes. Otherwise
1387 they are units of 1024 bytes.
1389 Setting this variable also turns off
1390 warning messages (that is, implies
1392 by default, because POSIX requires that apart from
1395 all messages printed on stderr are diagnositcs and must result in a
1396 non-zero exit status.
1398 When POSIXLY_CORRECT is not set,
1401 is treated just like
1405 +zzz is not a valid symbolic mode. When POSIXLY_CORRECT is set, such
1406 constructs are treated as an error.
1409 Affects the time zone used for some of the time-related format
1410 directives of \-printf and \-fprintf.
1413 .B find /tmp \-name core \-type f \-print | xargs /bin/rm \-f
1418 in or below the directory
1420 and delete them. Note that this will work incorrectly if there are
1421 any filenames containing newlines, single or double quotes, or spaces.
1423 .B find /tmp \-name core \-type f \-print0 | xargs \-0 /bin/rm \-f
1428 in or below the directory
1430 and delete them, processing filenames in such a way that file or
1431 directory names containing single or double quotes, spaces or newlines
1432 are correctly handled. The
1434 test comes before the
1436 test in order to avoid having to call
1442 .B find . \-type f \-exec file \(aq{}\(aq \e\;
1445 Runs `file' on every file in or below the current directory. Notice
1446 that the braces are enclosed in single quote marks to protect them
1447 from interpretation as shell script punctuation. The semicolon is
1448 similarly protected by the use of a backslash, though single quotes
1449 could have been used in that case also.
1454 .B \e( \-perm \-4000 \-fprintf /root/suid.txt "%#m %u %p\en" \e) , \e
1455 .B \e( \-size +100M \-fprintf /root/big.txt "%\-10s %p\en" \e)
1458 Traverse the filesystem just once, listing setuid files and
1461 and large files into
1466 .B find $HOME \-mtime 0
1469 Search for files in your home directory which have been modified in
1470 the last twenty-four hours. This command works this way because the
1471 time since each file was last modified is divided by 24 hours and any
1472 remainder is discarded. That means that to match
1475 a file will have to have a modification in the past which is less than
1480 .B find /sbin /usr/sbin -executable \e! -readable \-print
1483 Search for files which are executable but not readable.
1487 .B find . \-perm 664
1490 Search for files which have read and write permission for their owner,
1491 and group, but which other users can read but not write to. Files
1492 which meet these criteria but have other permissions bits set (for
1493 example if someone can execute the file) will not be matched.
1497 .B find . \-perm \-664
1500 Search for files which have read and write permission for their owner
1501 and group, and which other users can read, without regard to the
1502 presence of any extra permission bits (for example the executable
1503 bit). This will match a file which has mode 0777, for example.
1507 .B find . \-perm /222
1510 Search for files which are writable by somebody (their owner, or
1511 their group, or anybody else).
1515 .B find . \-perm /220
1516 .B find . \-perm /u+w,g+w
1517 .B find . \-perm /u=w,g=w
1520 All three of these commands do the same thing, but the first one uses
1521 the octal representation of the file mode, and the other two use the
1522 symbolic form. These commands all search for files which are
1523 writable by either their owner or their group. The files don't have
1524 to be writable by both the owner and group to be matched; either will
1529 .B find . \-perm \-220
1530 .B find . \-perm \-g+w,u+w
1533 Both these commands do the same thing; search for files which are
1534 writable by both their owner and their group.
1538 .B find . \-perm \-444 \-perm /222 ! \-perm /111
1539 .B find . \-perm \-a+r \-perm /a+w ! \-perm /a+x
1542 These two commands both search for files that are readable for
1543 everybody (\-perm \-444 or \-perm \-a+r), have at least on write bit
1544 set (\-perm /222 or \-perm /a+w) but are not executable for anybody (!
1545 \-perm /111 and ! \-perm /a+x respectively)
1550 .B find . \-name .snapshot \-prune \-o \e( \e! \-name "*~" \-print0 \e)|
1551 .B cpio \-pmd0 /dest-dir
1554 This command copies the contents of
1558 but omits files and directories named
1560 (and anything in them). It also omits files or directories whose name
1563 but not their contents. The construct
1564 .B \-prune \-o \e( ... \-print0 \e)
1565 is quite common. The idea here is that the expression before
1567 matches things which are to be pruned. However, the
1569 action itself returns true, so the following
1571 ensures that the right hand side is evaluated only for those
1572 directories which didn't get pruned (the contents of the pruned
1573 directories are not even visited, so their contents are irrelevant).
1574 The expression on the right hand side of the
1576 is in parentheses only for clarity. It emphasises that the
1578 action takes place only for things that didn't have
1580 applied to them. Because the default `and' condition between tests
1581 binds more tightly than
1583 this is the default anyway, but the parentheses help to show
1589 exits with status 0 if all files are processed successfully, greater
1590 than 0 if errors occur. This is deliberately a very broad
1591 description, but if the return value is non-zero, you should not rely
1592 on the correctness of the results of
1596 \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1), \fBxargs\fP(1),
1597 \fBchmod\fP(1), \fBfnmatch\fP(3), \fBregex\fP(7), \fBstat\fP(2),
1598 \fBlstat\fP(2), \fBls\fP(1), \fBprintf\fP(3), \fBstrftime\fP(3),
1599 \fBctime\fP(3), \fBFinding Files\fP (on-line in Info, or printed).
1601 As of findutils-4.2.2, shell metacharacters (`*', `?' or `[]' for
1602 example) used in filename patterns will match a leading `.', because
1603 IEEE POSIX interpretation 126 requires this.
1607 was deprecated in findutils-4.2.21, in favour of
1610 As of findutils-4.3.3,
1612 now matches all files instead of none.
1614 Nanosecond-resolution
1615 timestamps were implemented in findutils-4.3.3.
1618 Feature Added in Also occurs in
1626 \-exec ... + 4.2.12 POSIX
1627 \-execdir 4.2.12 BSD
1638 \-ignore_readdir_race 4.2.0
1647 .B $ find . \-name *.c \-print
1648 find: paths must precede expression
1649 Usage: find [\-H] [\-L] [\-P] [\-Olevel] [\-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
1652 This happens because
1654 has been expanded by the shell
1657 actually receiving a command line like this:
1660 .B find . \-name bigram.c code.c frcode.c locate.c \-print
1663 That command is of course not going to work. Instead of doing things
1664 this way, you should enclose the pattern in quotes or escape the wildcard:
1666 .B $ find . \-name \e*.c \-print
1671 There are security problems inherent in the behaviour that the POSIX
1672 standard specifies for
1674 which therefore cannot be fixed. For example, the \-exec action is
1675 inherently insecure, and \-execdir should be used instead.
1676 Please see \fBFinding Files\fP for more information.
1678 The environment variable
1680 has no effect on the
1684 The best way to report a bug is to use the form at
1685 http://savannah.gnu.org/bugs/?group=findutils.
1686 The reason for this is that you will then be able to track progress in
1687 fixing the problem. Other comments about \fBfind\fP(1) and about
1688 the findutils package in general can be sent to the
1690 mailing list. To join the list, send email to
1691 .IR bug\-findutils\-request@gnu.org .