1FIND(1) General Commands Manual FIND(1)
2
3
4
6 find - search for files in a directory hierarchy
7
9 find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
10
12 This manual page documents the GNU version of find. GNU find searches
13 the directory tree rooted at each given file name by evaluating the
14 given expression from left to right, according to the rules of prece‐
15 dence (see section OPERATORS), until the outcome is known (the left
16 hand side is false for and operations, true for or), at which point
17 find moves on to the next file name.
18
19 If you are using find in an environment where security is important
20 (for example if you are using it to search directories that are
21 writable by other users), you should read the "Security Considerations"
22 chapter of the findutils documentation, which is called Finding Files
23 and comes with findutils. That document also includes a lot more
24 detail and discussion than this manual page, so you may find it a more
25 useful source of information.
26
28 The -H, -L and -P options control the treatment of symbolic links.
29 Command-line arguments following these are taken to be names of files
30 or directories to be examined, up to the first argument that begins
31 with `-', or the argument `(' or `!'. That argument and any following
32 arguments are taken to be the expression describing what is to be
33 searched for. If no paths are given, the current directory is used.
34 If no expression is given, the expression -print is used (but you
35 should probably consider using -print0 instead, anyway).
36
37 This manual page talks about `options' within the expression list.
38 These options control the behaviour of find but are specified immedi‐
39 ately after the last path name. The five `real' options -H, -L, -P, -D
40 and -O must appear before the first path name, if at all. A double
41 dash -- can also be used to signal that any remaining arguments are not
42 options (though ensuring that all start points begin with either `./'
43 or `/' is generally safer if you use wildcards in the list of start
44 points).
45
46 -P Never follow symbolic links. This is the default behaviour.
47 When find examines or prints information a file, and the file is
48 a symbolic link, the information used shall be taken from the
49 properties of the symbolic link itself.
50
51
52 -L Follow symbolic links. When find examines or prints information
53 about files, the information used shall be taken from the prop‐
54 erties of the file to which the link points, not from the link
55 itself (unless it is a broken symbolic link or find is unable to
56 examine the file to which the link points). Use of this option
57 implies -noleaf. If you later use the -P option, -noleaf will
58 still be in effect. If -L is in effect and find discovers a
59 symbolic link to a subdirectory during its search, the subdirec‐
60 tory pointed to by the symbolic link will be searched.
61
62 When the -L option is in effect, the -type predicate will always
63 match against the type of the file that a symbolic link points
64 to rather than the link itself (unless the symbolic link is bro‐
65 ken). Using -L causes the -lname and -ilname predicates always
66 to return false.
67
68
69 -H Do not follow symbolic links, except while processing the com‐
70 mand line arguments. When find examines or prints information
71 about files, the information used shall be taken from the prop‐
72 erties of the symbolic link itself. The only exception to this
73 behaviour is when a file specified on the command line is a sym‐
74 bolic link, and the link can be resolved. For that situation,
75 the information used is taken from whatever the link points to
76 (that is, the link is followed). The information about the link
77 itself is used as a fallback if the file pointed to by the sym‐
78 bolic link cannot be examined. If -H is in effect and one of
79 the paths specified on the command line is a symbolic link to a
80 directory, the contents of that directory will be examined
81 (though of course -maxdepth 0 would prevent this).
82
83 If more than one of -H, -L and -P is specified, each overrides the oth‐
84 ers; the last one appearing on the command line takes effect. Since it
85 is the default, the -P option should be considered to be in effect
86 unless either -H or -L is specified.
87
88 GNU find frequently stats files during the processing of the command
89 line itself, before any searching has begun. These options also affect
90 how those arguments are processed. Specifically, there are a number of
91 tests that compare files listed on the command line against a file we
92 are currently considering. In each case, the file specified on the
93 command line will have been examined and some of its properties will
94 have been saved. If the named file is in fact a symbolic link, and the
95 -P option is in effect (or if neither -H nor -L were specified), the
96 information used for the comparison will be taken from the properties
97 of the symbolic link. Otherwise, it will be taken from the properties
98 of the file the link points to. If find cannot follow the link (for
99 example because it has insufficient privileges or the link points to a
100 nonexistent file) the properties of the link itself will be used.
101
102 When the -H or -L options are in effect, any symbolic links listed as
103 the argument of -newer will be dereferenced, and the timestamp will be
104 taken from the file to which the symbolic link points. The same con‐
105 sideration applies to -newerXY, -anewer and -cnewer.
106
107 The -follow option has a similar effect to -L, though it takes effect
108 at the point where it appears (that is, if -L is not used but -follow
109 is, any symbolic links appearing after -follow on the command line will
110 be dereferenced, and those before it will not).
111
112
113 -D debugoptions
114 Print diagnostic information; this can be helpful to diagnose
115 problems with why find is not doing what you want. The list of
116 debug options should be comma separated. Compatibility of the
117 debug options is not guaranteed between releases of findutils.
118 For a complete list of valid debug options, see the output of
119 find -D help. Valid debug options include
120
121 help Explain the debugging options
122
123 tree Show the expression tree in its original and optimised
124 form.
125
126 stat Print messages as files are examined with the stat and
127 lstat system calls. The find program tries to minimise
128 such calls.
129
130 opt Prints diagnostic information relating to the optimisa‐
131 tion of the expression tree; see the -O option.
132
133 rates Prints a summary indicating how often each predicate suc‐
134 ceeded or failed.
135
136 -Olevel
137 Enables query optimisation. The find program reorders tests to
138 speed up execution while preserving the overall effect; that is,
139 predicates with side effects are not reordered relative to each
140 other. The optimisations performed at each optimisation level
141 are as follows.
142
143 0 Equivalent to optimisation level 1.
144
145 1 This is the default optimisation level and corresponds to
146 the traditional behaviour. Expressions are reordered so
147 that tests based only on the names of files (for example
148 -name and -regex) are performed first.
149
150 2 Any -type or -xtype tests are performed after any tests
151 based only on the names of files, but before any tests
152 that require information from the inode. On many modern
153 versions of Unix, file types are returned by readdir()
154 and so these predicates are faster to evaluate than pred‐
155 icates which need to stat the file first. If you use the
156 -fstype FOO predicate and specify a filsystem type FOO
157 which is not known (that is, present in `/etc/mtab') at
158 the time find starts, that predicate is equivalent to
159 -false.
160
161 3 At this optimisation level, the full cost-based query
162 optimiser is enabled. The order of tests is modified so
163 that cheap (i.e. fast) tests are performed first and more
164 expensive ones are performed later, if necessary. Within
165 each cost band, predicates are evaluated earlier or later
166 according to whether they are likely to succeed or not.
167 For -o, predicates which are likely to succeed are evalu‐
168 ated earlier, and for -a, predicates which are likely to
169 fail are evaluated earlier.
170
171 The cost-based optimiser has a fixed idea of how likely any
172 given test is to succeed. In some cases the probability takes
173 account of the specific nature of the test (for example, -type f
174 is assumed to be more likely to succeed than -type c). The
175 cost-based optimiser is currently being evaluated. If it does
176 not actually improve the performance of find, it will be removed
177 again. Conversely, optimisations that prove to be reliable,
178 robust and effective may be enabled at lower optimisation levels
179 over time. However, the default behaviour (i.e. optimisation
180 level 1) will not be changed in the 4.3.x release series. The
181 findutils test suite runs all the tests on find at each optimi‐
182 sation level and ensures that the result is the same.
183
185 The expression is made up of options (which affect overall operation
186 rather than the processing of a specific file, and always return true),
187 tests (which return a true or false value), and actions (which have
188 side effects and return a true or false value), all separated by opera‐
189 tors. -and is assumed where the operator is omitted.
190
191 If the expression contains no actions other than -prune, -print is per‐
192 formed on all files for which the expression is true.
193
194
195 OPTIONS
196 All options always return true. Except for -daystart, -follow and
197 -regextype, the options affect all tests, including tests specified
198 before the option. This is because the options are processed when the
199 command line is parsed, while the tests don't do anything until files
200 are examined. The -daystart, -follow and -regextype options are dif‐
201 ferent in this respect, and have an effect only on tests which appear
202 later in the command line. Therefore, for clarity, it is best to place
203 them at the beginning of the expression. A warning is issued if you
204 don't do this.
205
206
207 -d A synonym for -depth, for compatibility with FreeBSD, NetBSD,
208 MacOS X and OpenBSD.
209
210
211 -daystart
212 Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and
213 -mtime) from the beginning of today rather than from 24 hours
214 ago. This option only affects tests which appear later on the
215 command line.
216
217
218 -depth Process each directory's contents before the directory itself.
219 The -delete action also implies -depth.
220
221
222 -follow
223 Deprecated; use the -L option instead. Dereference symbolic
224 links. Implies -noleaf. The -follow option affects only those
225 tests which appear after it on the command line. Unless the -H
226 or -L option has been specified, the position of the -follow
227 option changes the behaviour of the -newer predicate; any files
228 listed as the argument of -newer will be dereferenced if they
229 are symbolic links. The same consideration applies to -newerXY,
230 -anewer and -cnewer. Similarly, the -type predicate will always
231 match against the type of the file that a symbolic link points
232 to rather than the link itself. Using -follow causes the -lname
233 and -ilname predicates always to return false.
234
235
236 -help, --help
237 Print a summary of the command-line usage of find and exit.
238
239
240 -ignore_readdir_race
241 Normally, find will emit an error message when it fails to stat
242 a file. If you give this option and a file is deleted between
243 the time find reads the name of the file from the directory and
244 the time it tries to stat the file, no error message will be
245 issued. This also applies to files or directories whose names
246 are given on the command line. This option takes effect at the
247 time the command line is read, which means that you cannot
248 search one part of the filesystem with this option on and part
249 of it with this option off (if you need to do that, you will
250 need to issue two find commands instead, one with the option and
251 one without it).
252
253
254 -maxdepth levels
255 Descend at most levels (a non-negative integer) levels of direc‐
256 tories below the command line arguments. -maxdepth 0
257 means only apply the tests and actions to the command line
258 arguments.
259
260
261 -mindepth levels
262 Do not apply any tests or actions at levels less than levels (a
263 non-negative integer). -mindepth 1 means process all files
264 except the command line arguments.
265
266
267 -mount Don't descend directories on other filesystems. An alternate
268 name for -xdev, for compatibility with some other versions of
269 find.
270
271
272 -noignore_readdir_race
273 Turns off the effect of -ignore_readdir_race.
274
275
276 -noleaf
277 Do not optimize by assuming that directories contain 2 fewer
278 subdirectories than their hard link count. This option is
279 needed when searching filesystems that do not follow the Unix
280 directory-link convention, such as CD-ROM or MS-DOS filesystems
281 or AFS volume mount points. Each directory on a normal Unix
282 filesystem has at least 2 hard links: its name and its `.'
283 entry. Additionally, its subdirectories (if any) each have a
284 `..' entry linked to that directory. When find is examining a
285 directory, after it has statted 2 fewer subdirectories than the
286 directory's link count, it knows that the rest of the entries in
287 the directory are non-directories (`leaf' files in the directory
288 tree). If only the files' names need to be examined, there is
289 no need to stat them; this gives a significant increase in
290 search speed.
291
292
293 -regextype type
294 Changes the regular expression syntax understood by -regex and
295 -iregex tests which occur later on the command line. Currently-
296 implemented types are emacs (this is the default), posix-awk,
297 posix-basic, posix-egrep and posix-extended.
298
299
300 -version, --version
301 Print the find version number and exit.
302
303
304 -warn, -nowarn
305 Turn warning messages on or off. These warnings apply only to
306 the command line usage, not to any conditions that find might
307 encounter when it searches directories. The default behaviour
308 corresponds to -warn if standard input is a tty, and to -nowarn
309 otherwise.
310
311
312 -xautofs
313 Don't descend directories on autofs filesystems.
314
315
316 -xdev Don't descend directories on other filesystems.
317
318
319 TESTS
320 Some tests, for example -newerXY and -samefile, allow comparison
321 between the file currently being examined and some reference file spec‐
322 ified on the command line. When these tests are used, the interpreta‐
323 tion of the reference file is determined by the options -H, -L and -P
324 and any previous -follow, but the reference file is only examined once,
325 at the time the command line is parsed. If the reference file cannot
326 be examined (for example, the stat(2) system call fails for it), an
327 error message is issued, and find exits with a nonzero status.
328
329 Numeric arguments can be specified as
330
331 +n for greater than n,
332
333 -n for less than n,
334
335 n for exactly n.
336
337 -amin n
338 File was last accessed n minutes ago.
339
340
341 -anewer file
342 File was last accessed more recently than file was modified. If
343 file is a symbolic link and the -H option or the -L option is in
344 effect, the access time of the file it points to is always used.
345
346
347 -atime n
348 File was last accessed n*24 hours ago. When find figures out
349 how many 24-hour periods ago the file was last accessed, any
350 fractional part is ignored, so to match -atime +1, a file has to
351 have been accessed at least two days ago.
352
353
354 -cmin n
355 File's status was last changed n minutes ago.
356
357
358 -cnewer file
359 File's status was last changed more recently than file was modi‐
360 fied. If file is a symbolic link and the -H option or the -L
361 option is in effect, the status-change time of the file it
362 points to is always used.
363
364
365 -ctime n
366 File's status was last changed n*24 hours ago. See the comments
367 for -atime to understand how rounding affects the interpretation
368 of file status change times.
369
370
371 -empty File is empty and is either a regular file or a directory.
372
373
374 -executable
375 Matches files which are executable and directories which are
376 searchable (in a file name resolution sense). This takes into
377 account access control lists and other permissions artefacts
378 which the -perm test ignores. This test makes use of the
379 access(2) system call, and so can be fooled by NFS servers which
380 do UID mapping (or root-squashing), since many systems implement
381 access(2) in the client's kernel and so cannot make use of the
382 UID mapping information held on the server. Because this test
383 is based only on the result of the access(2) system call, there
384 is no guarantee that a file for which this test succeeds can
385 actually be executed.
386
387
388 -false Always false.
389
390
391 -fstype type
392 File is on a filesystem of type type. The valid filesystem
393 types vary among different versions of Unix; an incomplete list
394 of filesystem types that are accepted on some version of Unix or
395 another is: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K. You can
396 use -printf with the %F directive to see the types of your
397 filesystems.
398
399
400 -gid n File's numeric group ID is n.
401
402
403 -group gname
404 File belongs to group gname (numeric group ID allowed).
405
406
407 -ilname pattern
408 Like -lname, but the match is case insensitive. If the -L
409 option or the -follow option is in effect, this test returns
410 false unless the symbolic link is broken.
411
412
413
414 -iname pattern
415 Like -name, but the match is case insensitive. For example, the
416 patterns `fo*' and `F??' match the file names `Foo', `FOO',
417 `foo', `fOo', etc. The pattern `*foo*` will also match a file
418 called '.foobar'.
419
420
421 -inum n
422 File has inode number n. It is normally easier to use the
423 -samefile test instead.
424
425
426 -ipath pattern
427 Like -path. but the match is case insensitive.
428
429
430 -iregex pattern
431 Like -regex, but the match is case insensitive.
432
433
434 -iwholename pattern
435 See -ipath. This alternative is less portable than -ipath.
436
437
438 -links n
439 File has n links.
440
441
442 -lname pattern
443 File is a symbolic link whose contents match shell pattern pat‐
444 tern. The metacharacters do not treat `/' or `.' specially. If
445 the -L option or the -follow option is in effect, this test
446 returns false unless the symbolic link is broken.
447
448
449 -mmin n
450 File's data was last modified n minutes ago.
451
452
453 -mtime n
454 File's data was last modified n*24 hours ago. See the comments
455 for -atime to understand how rounding affects the interpretation
456 of file modification times.
457
458
459 -name pattern
460 Base of file name (the path with the leading directories
461 removed) matches shell pattern pattern. Because the leading
462 directories are removed, the file names considered for a match
463 with -name will never include a slash, so `-name a/b' will never
464 match anything (you probably need to use -path instead). The
465 metacharacters (`*', `?', and `[]') match a `.' at the start of
466 the base name (this is a change in findutils-4.2.2; see section
467 STANDARDS CONFORMANCE below). To ignore a directory and the
468 files under it, use -prune; see an example in the description of
469 -path. Braces are not recognised as being special, despite the
470 fact that some shells including Bash imbue braces with a special
471 meaning in shell patterns. The filename matching is performed
472 with the use of the fnmatch(3) library function. Don't forget
473 to enclose the pattern in quotes in order to protect it from
474 expansion by the shell.
475
476
477 -newer file
478 File was modified more recently than file. If file is a sym‐
479 bolic link and the -H option or the -L option is in effect, the
480 modification time of the file it points to is always used.
481
482
483 -newerXY reference
484 Compares the timestamp of the current file with reference. The
485 reference argument is normally the name of a file (and one of
486 its timestamps is used for the comparison) but it may also be a
487 string describing an absolute time. X and Y are placeholders
488 for other letters, and these letters select which time belonging
489 to how reference is used for the comparison.
490
491 a The access time of the file reference
492 B The birth time of the file reference
493 c The inode status change time of reference
494 m The modification time of the file reference
495 t reference is interpreted directly as a time
496
497 Some combinations are invalid; for example, it is invalid for X
498 to be t. Some combinations are not implemented on all systems;
499 for example B is not supported on all systems. If an invalid or
500 unsupported combination of XY is specified, a fatal error
501 results. Time specifications are interpreted as for the argu‐
502 ment to the -d option of GNU date. If you try to use the birth
503 time of a reference file, and the birth time cannot be deter‐
504 mined, a fatal error message results. If you specify a test
505 which refers to the birth time of files being examined, this
506 test will fail for any files where the birth time is unknown.
507
508
509 -nogroup
510 No group corresponds to file's numeric group ID.
511
512
513 -nouser
514 No user corresponds to file's numeric user ID.
515
516
517 -path pattern
518 File name matches shell pattern pattern. The metacharacters do
519 not treat `/' or `.' specially; so, for example,
520 find . -path "./sr*sc"
521 will print an entry for a directory called `./src/misc' (if one
522 exists). To ignore a whole directory tree, use -prune rather
523 than checking every file in the tree. For example, to skip the
524 directory `src/emacs' and all files and directories under it,
525 and print the names of the other files found, do something like
526 this:
527 find . -path ./src/emacs -prune -o -print
528 Note that the pattern match test applies to the whole file name,
529 starting from one of the start points named on the command line.
530 It would only make sense to use an absolute path name here if
531 the relevant start point is also an absolute path. This means
532 that this command will never match anything:
533 find bar -path /foo/bar/myfile -print
534 Find compares the -path argument with the concatenation of a
535 directory name and the base name of the file it's examining.
536 Since the concatenation will never end with a slash, -path argu‐
537 ments ending in a slash will match nothing (except perhaps a
538 start point specified on the command line). The predicate -path
539 is also supported by HP-UX find and will be in a forthcoming
540 version of the POSIX standard.
541
542
543 -perm mode
544 File's permission bits are exactly mode (octal or symbolic).
545 Since an exact match is required, if you want to use this form
546 for symbolic modes, you may have to specify a rather complex
547 mode string. For example `-perm g=w' will only match files
548 which have mode 0020 (that is, ones for which group write per‐
549 mission is the only permission set). It is more likely that you
550 will want to use the `/' or `-' forms, for example `-perm -g=w',
551 which matches any file with group write permission. See the
552 EXAMPLES section for some illustrative examples.
553
554
555 -perm -mode
556 All of the permission bits mode are set for the file. Symbolic
557 modes are accepted in this form, and this is usually the way in
558 which would want to use them. You must specify `u', `g' or `o'
559 if you use a symbolic mode. See the EXAMPLES section for some
560 illustrative examples.
561
562
563 -perm /mode
564 Any of the permission bits mode are set for the file. Symbolic
565 modes are accepted in this form. You must specify `u', `g' or
566 `o' if you use a symbolic mode. See the EXAMPLES section for
567 some illustrative examples. If no permission bits in mode are
568 set, this test matches any file (the idea here is to be consis‐
569 tent with the behaviour of -perm -000).
570
571
572 -perm +mode
573 Deprecated, old way of searching for files with any of the per‐
574 mission bits in mode set. You should use -perm /mode instead.
575 Trying to use the `+' syntax with symbolic modes will yield sur‐
576 prising results. For example, `+u+x' is a valid symbolic mode
577 (equivalent to +u,+x, i.e. 0111) and will therefore not be eval‐
578 uated as -perm +mode but instead as the exact mode specifier
579 -perm mode and so it matches files with exact permissions 0111
580 instead of files with any execute bit set. If you found this
581 paragraph confusing, you're not alone - just use -perm /mode.
582 This form of the -perm test is deprecated because the POSIX
583 specification requires the interpretation of a leading `+' as
584 being part of a symbolic mode, and so we switched to using `/'
585 instead.
586
587
588 -readable
589 Matches files which are readable. This takes into account
590 access control lists and other permissions artefacts which the
591 -perm test ignores. This test makes use of the access(2) system
592 call, and so can be fooled by NFS servers which do UID mapping
593 (or root-squashing), since many systems implement access(2) in
594 the client's kernel and so cannot make use of the UID mapping
595 information held on the server.
596
597
598 -regex pattern
599 File name matches regular expression pattern. This is a match
600 on the whole path, not a search. For example, to match a file
601 named `./fubar3', you can use the regular expression `.*bar.' or
602 `.*b.*3', but not `f.*r3'. The regular expressions understood
603 by find are by default Emacs Regular Expressions, but this can
604 be changed with the -regextype option.
605
606
607 -samefile name
608 File refers to the same inode as name. When -L is in effect,
609 this can include symbolic links.
610
611
612 -size n[cwbkMG]
613 File uses n units of space. The following suffixes can be used:
614
615 `b' for 512-byte blocks (this is the default if no suffix is
616 used)
617
618 `c' for bytes
619
620 `w' for two-byte words
621
622 `k' for Kilobytes (units of 1024 bytes)
623
624 `M' for Megabytes (units of 1048576 bytes)
625
626 `G' for Gigabytes (units of 1073741824 bytes)
627
628 The size does not count indirect blocks, but it does count
629 blocks in sparse files that are not actually allocated. Bear in
630 mind that the `%k' and `%b' format specifiers of -printf handle
631 sparse files differently. The `b' suffix always denotes
632 512-byte blocks and never 1 Kilobyte blocks, which is different
633 to the behaviour of -ls.
634
635
636 -true Always true.
637
638
639 -type c
640 File is of type c:
641
642 b block (buffered) special
643
644 c character (unbuffered) special
645
646 d directory
647
648 p named pipe (FIFO)
649
650 f regular file
651
652 l symbolic link; this is never true if the -L option or the
653 -follow option is in effect, unless the symbolic link is
654 broken. If you want to search for symbolic links when -L
655 is in effect, use -xtype.
656
657 s socket
658
659 D door (Solaris)
660
661 -uid n File's numeric user ID is n.
662
663
664 -used n
665 File was last accessed n days after its status was last changed.
666
667
668 -user uname
669 File is owned by user uname (numeric user ID allowed).
670
671
672 -wholename pattern
673 See -path. This alternative is less portable than -path.
674
675
676 -writable
677 Matches files which are writable. This takes into account
678 access control lists and other permissions artefacts which the
679 -perm test ignores. This test makes use of the access(2) system
680 call, and so can be fooled by NFS servers which do UID mapping
681 (or root-squashing), since many systems implement access(2) in
682 the client's kernel and so cannot make use of the UID mapping
683 information held on the server.
684
685
686 -xtype c
687 The same as -type unless the file is a symbolic link. For sym‐
688 bolic links: if the -H or -P option was specified, true if the
689 file is a link to a file of type c; if the -L option has been
690 given, true if c is `l'. In other words, for symbolic links,
691 -xtype checks the type of the file that -type does not check.
692
693 -context pattern
694 (SELinux only) Security context of the file matches glob pat‐
695 tern.
696
697
698 ACTIONS
699 -delete
700 Delete files; true if removal succeeded. If the removal failed,
701 an error message is issued. If -delete fails, find's exit sta‐
702 tus will be nonzero (when it eventually exits). Use of -delete
703 automatically turns on the `-depth' option.
704
705 Warnings: Don't forget that the find command line is evaluated
706 as an expression, so putting -delete first will make find try to
707 delete everything below the starting points you specified. When
708 testing a find command line that you later intend to use with
709 -delete, you should explicitly specify -depth in order to avoid
710 later surprises. Because -delete implies -depth, you cannot
711 usefully use -prune and -delete together.
712
713
714 -exec command ;
715 Execute command; true if 0 status is returned. All following
716 arguments to find are taken to be arguments to the command until
717 an argument consisting of `;' is encountered. The string `{}'
718 is replaced by the current file name being processed everywhere
719 it occurs in the arguments to the command, not just in arguments
720 where it is alone, as in some versions of find. Both of these
721 constructions might need to be escaped (with a `\') or quoted to
722 protect them from expansion by the shell. See the EXAMPLES sec‐
723 tion for examples of the use of the -exec option. The specified
724 command is run once for each matched file. The command is exe‐
725 cuted in the starting directory. There are unavoidable secu‐
726 rity problems surrounding use of the -exec action; you should
727 use the -execdir option instead.
728
729
730 -exec command {} +
731 This variant of the -exec action runs the specified command on
732 the selected files, but the command line is built by appending
733 each selected file name at the end; the total number of invoca‐
734 tions of the command will be much less than the number of
735 matched files. The command line is built in much the same way
736 that xargs builds its command lines. Only one instance of `{}'
737 is allowed within the command. The command is executed in the
738 starting directory.
739
740
741 -execdir command ;
742
743 -execdir command {} +
744 Like -exec, but the specified command is run from the subdirec‐
745 tory containing the matched file, which is not normally the
746 directory in which you started find. This a much more secure
747 method for invoking commands, as it avoids race conditions dur‐
748 ing resolution of the paths to the matched files. As with the
749 -exec action, the `+' form of -execdir will build a command line
750 to process more than one matched file, but any given invocation
751 of command will only list files that exist in the same subdirec‐
752 tory. If you use this option, you must ensure that your $PATH
753 environment variable does not reference `.'; otherwise, an
754 attacker can run any commands they like by leaving an appropri‐
755 ately-named file in a directory in which you will run -execdir.
756 The same applies to having entries in $PATH which are empty or
757 which are not absolute directory names.
758
759
760 -fls file
761 True; like -ls but write to file like -fprint. The output file
762 is always created, even if the predicate is never matched. See
763 the UNUSUAL FILENAMES section for information about how unusual
764 characters in filenames are handled.
765
766
767 -fprint file
768 True; print the full file name into file file. If file does not
769 exist when find is run, it is created; if it does exist, it is
770 truncated. The file names `/dev/stdout' and `/dev/stderr' are
771 handled specially; they refer to the standard output and stan‐
772 dard error output, respectively. The output file is always cre‐
773 ated, even if the predicate is never matched. See the UNUSUAL
774 FILENAMES section for information about how unusual characters
775 in filenames are handled.
776
777
778 -fprint0 file
779 True; like -print0 but write to file like -fprint. The output
780 file is always created, even if the predicate is never matched.
781 See the UNUSUAL FILENAMES section for information about how
782 unusual characters in filenames are handled.
783
784
785 -fprintf file format
786 True; like -printf but write to file like -fprint. The output
787 file is always created, even if the predicate is never matched.
788 See the UNUSUAL FILENAMES section for information about how
789 unusual characters in filenames are handled.
790
791
792 -ls True; list current file in ls -dils format on standard output.
793 The block counts are of 1K blocks, unless the environment vari‐
794 able POSIXLY_CORRECT is set, in which case 512-byte blocks are
795 used. See the UNUSUAL FILENAMES section for information about
796 how unusual characters in filenames are handled.
797
798
799 -ok command ;
800 Like -exec but ask the user first. If the user agrees, run the
801 command. Otherwise just return false. If the command is run,
802 its standard input is redirected from /dev/null.
803
804
805 The response to the prompt is matched against a pair of regular
806 expressions to determine if it is an affirmative or negative
807 response. This regular expression is obtained from the system
808 if the `POSIXLY_CORRECT' environment variable is set, or other‐
809 wise from find's message translations. If the system has no
810 suitable definition, find's own definition will be used. In
811 either case, the interpretation of the regular expression itself
812 will be affected by the environment variables 'LC_CTYPE' (char‐
813 acter classes) and 'LC_COLLATE' (character ranges and equiva‐
814 lence classes).
815
816
817
818
819 -okdir command ;
820 Like -execdir but ask the user first in the same way as for -ok.
821 If the user does not agree, just return false. If the command
822 is run, its standard input is redirected from /dev/null.
823
824
825 -print True; print the full file name on the standard output, followed
826 by a newline. If you are piping the output of find into
827 another program and there is the faintest possibility that the
828 files which you are searching for might contain a newline, then
829 you should seriously consider using the -print0 option instead
830 of -print. See the UNUSUAL FILENAMES section for information
831 about how unusual characters in filenames are handled.
832
833
834 -print0
835 True; print the full file name on the standard output, followed
836 by a null character (instead of the newline character that
837 -print uses). This allows file names that contain newlines or
838 other types of white space to be correctly interpreted by pro‐
839 grams that process the find output. This option corresponds to
840 the -0 option of xargs.
841
842
843 -printf format
844 True; print format on the standard output, interpreting `\'
845 escapes and `%' directives. Field widths and precisions can be
846 specified as with the `printf' C function. Please note that
847 many of the fields are printed as %s rather than %d, and this
848 may mean that flags don't work as you might expect. This also
849 means that the `-' flag does work (it forces fields to be left-
850 aligned). Unlike -print, -printf does not add a newline at the
851 end of the string. The escapes and directives are:
852
853 \a Alarm bell.
854
855 \b Backspace.
856
857 \c Stop printing from this format immediately and flush the
858 output.
859
860 \f Form feed.
861
862 \n Newline.
863
864 \r Carriage return.
865
866 \t Horizontal tab.
867
868 \v Vertical tab.
869
870 \0 ASCII NUL.
871
872 \\ A literal backslash (`\').
873
874 \NNN The character whose ASCII code is NNN (octal).
875
876 A `\' character followed by any other character is treated as an
877 ordinary character, so they both are printed.
878
879 %% A literal percent sign.
880
881 %a File's last access time in the format returned by the C
882 `ctime' function.
883
884 %Ak File's last access time in the format specified by k,
885 which is either `@' or a directive for the C `strftime'
886 function. The possible values for k are listed below;
887 some of them might not be available on all systems, due
888 to differences in `strftime' between systems.
889
890 @ seconds since Jan. 1, 1970, 00:00 GMT, with frac‐
891 tional part.
892
893 Time fields:
894
895 H hour (00..23)
896
897 I hour (01..12)
898
899 k hour ( 0..23)
900
901 l hour ( 1..12)
902
903 M minute (00..59)
904
905 p locale's AM or PM
906
907 r time, 12-hour (hh:mm:ss [AP]M)
908
909 S Second (00.00 .. 61.00). There is a fractional
910 part.
911
912 T time, 24-hour (hh:mm:ss)
913
914 + Date and time, separated by `+', for example
915 `2004-04-28+22:22:05.0'. This is a GNU extension.
916 The time is given in the current timezone (which
917 may be affected by setting the TZ environment
918 variable). The seconds field includes a frac‐
919 tional part.
920
921 X locale's time representation (H:M:S)
922
923 Z time zone (e.g., EDT), or nothing if no time zone
924 is determinable
925
926 Date fields:
927
928 a locale's abbreviated weekday name (Sun..Sat)
929
930 A locale's full weekday name, variable length (Sun‐
931 day..Saturday)
932
933 b locale's abbreviated month name (Jan..Dec)
934
935 B locale's full month name, variable length (Janu‐
936 ary..December)
937
938 c locale's date and time (Sat Nov 04 12:02:33 EST
939 1989). The format is the same as for ctime(3) and
940 so to preserve compatibility with that format,
941 there is no fractional part in the seconds field.
942
943 d day of month (01..31)
944
945 D date (mm/dd/yy)
946
947 h same as b
948
949 j day of year (001..366)
950
951 m month (01..12)
952
953 U week number of year with Sunday as first day of
954 week (00..53)
955
956 w day of week (0..6)
957
958 W week number of year with Monday as first day of
959 week (00..53)
960
961 x locale's date representation (mm/dd/yy)
962
963 y last two digits of year (00..99)
964
965 Y year (1970...)
966
967 %b The amount of disk space used for this file in 512-byte
968 blocks. Since disk space is allocated in multiples of the
969 filesystem block size this is usually greater than
970 %s/512, but it can also be smaller if the file is a
971 sparse file.
972
973 %c File's last status change time in the format returned by
974 the C `ctime' function.
975
976 %Ck File's last status change time in the format specified by
977 k, which is the same as for %A.
978
979 %d File's depth in the directory tree; 0 means the file is a
980 command line argument.
981
982 %D The device number on which the file exists (the st_dev
983 field of struct stat), in decimal.
984
985 %f File's name with any leading directories removed (only
986 the last element).
987
988 %F Type of the filesystem the file is on; this value can be
989 used for -fstype.
990
991 %g File's group name, or numeric group ID if the group has
992 no name.
993
994 %G File's numeric group ID.
995
996 %h Leading directories of file's name (all but the last ele‐
997 ment). If the file name contains no slashes (since it is
998 in the current directory) the %h specifier expands to
999 ".".
1000
1001 %H Command line argument under which file was found.
1002
1003 %i File's inode number (in decimal).
1004
1005 %k The amount of disk space used for this file in 1K blocks.
1006 Since disk space is allocated in multiples of the
1007 filesystem block size this is usually greater than
1008 %s/1024, but it can also be smaller if the file is a
1009 sparse file.
1010
1011 %l Object of symbolic link (empty string if file is not a
1012 symbolic link).
1013
1014 %m File's permission bits (in octal). This option uses the
1015 `traditional' numbers which most Unix implementations
1016 use, but if your particular implementation uses an
1017 unusual ordering of octal permissions bits, you will see
1018 a difference between the actual value of the file's mode
1019 and the output of %m. Normally you will want to have a
1020 leading zero on this number, and to do this, you should
1021 use the # flag (as in, for example, `%#m').
1022
1023 %M File's permissions (in symbolic form, as for ls). This
1024 directive is supported in findutils 4.2.5 and later.
1025
1026 %n Number of hard links to file.
1027
1028 %p File's name.
1029
1030 %P File's name with the name of the command line argument
1031 under which it was found removed.
1032
1033 %s File's size in bytes.
1034
1035 %S File's sparseness. This is calculated as (BLOCK‐
1036 SIZE*st_blocks / st_size). The exact value you will get
1037 for an ordinary file of a certain length is system-depen‐
1038 dent. However, normally sparse files will have values
1039 less than 1.0, and files which use indirect blocks may
1040 have a value which is greater than 1.0. The value used
1041 for BLOCKSIZE is system-dependent, but is usually 512
1042 bytes. If the file size is zero, the value printed is
1043 undefined. On systems which lack support for st_blocks,
1044 a file's sparseness is assumed to be 1.0.
1045
1046 %t File's last modification time in the format returned by
1047 the C `ctime' function.
1048
1049 %Tk File's last modification time in the format specified by
1050 k, which is the same as for %A.
1051
1052 %u File's user name, or numeric user ID if the user has no
1053 name.
1054
1055 %U File's numeric user ID.
1056
1057 %y File's type (like in ls -l), U=unknown type (shouldn't
1058 happen)
1059
1060 %Y File's type (like %y), plus follow symlinks: L=loop,
1061 N=nonexistent
1062
1063 %Z (SELinux only) file's security context.
1064
1065 %{ %[ %(
1066 Reserved for future use.
1067
1068 A `%' character followed by any other character is discarded,
1069 but the other character is printed (don't rely on this, as fur‐
1070 ther format characters may be introduced). A `%' at the end of
1071 the format argument causes undefined behaviour since there is no
1072 following character. In some locales, it may hide your door
1073 keys, while in others it may remove the final page from the
1074 novel you are reading.
1075
1076 The %m and %d directives support the # , 0 and + flags, but the
1077 other directives do not, even if they print numbers. Numeric
1078 directives that do not support these flags include G, U, b, D, k
1079 and n. The `-' format flag is supported and changes the align‐
1080 ment of a field from right-justified (which is the default) to
1081 left-justified.
1082
1083 See the UNUSUAL FILENAMES section for information about how
1084 unusual characters in filenames are handled.
1085
1086
1087
1088 -prune True; if the file is a directory, do not descend into it. If
1089 -depth is given, false; no effect. Because -delete implies
1090 -depth, you cannot usefully use -prune and -delete together.
1091
1092
1093 -quit Exit immediately. No child processes will be left running, but
1094 no more paths specified on the command line will be processed.
1095 For example, find /tmp/foo /tmp/bar -print -quit will print only
1096 /tmp/foo. Any command lines which have been built up with
1097 -execdir ... {} + will be invoked before find exits. The exit
1098 status may or may not be zero, depending on whether an error has
1099 already occurred.
1100
1101
1102 UNUSUAL FILENAMES
1103 Many of the actions of find result in the printing of data which is
1104 under the control of other users. This includes file names, sizes,
1105 modification times and so forth. File names are a potential problem
1106 since they can contain any character except `\0' and `/'. Unusual
1107 characters in file names can do unexpected and often undesirable things
1108 to your terminal (for example, changing the settings of your function
1109 keys on some terminals). Unusual characters are handled differently by
1110 various actions, as described below.
1111
1112
1113 -print0, -fprint0
1114 Always print the exact filename, unchanged, even if the output
1115 is going to a terminal.
1116
1117
1118 -ls, -fls
1119 Unusual characters are always escaped. White space, backslash,
1120 and double quote characters are printed using C-style escaping
1121 (for example `\f', `\"'). Other unusual characters are printed
1122 using an octal escape. Other printable characters (for -ls and
1123 -fls these are the characters between octal 041 and 0176) are
1124 printed as-is.
1125
1126
1127 -printf, -fprintf
1128 If the output is not going to a terminal, it is printed as-is.
1129 Otherwise, the result depends on which directive is in use. The
1130 directives %D, %F, %g, %G, %H, %Y, and %y expand to values which
1131 are not under control of files' owners, and so are printed as-
1132 is. The directives %a, %b, %c, %d, %i, %k, %m, %M, %n, %s, %t,
1133 %u and %U have values which are under the control of files' own‐
1134 ers but which cannot be used to send arbitrary data to the ter‐
1135 minal, and so these are printed as-is. The directives %f, %h,
1136 %l, %p and %P are quoted. This quoting is performed in the same
1137 way as for GNU ls. This is not the same quoting mechanism as
1138 the one used for -ls and -fls. If you are able to decide what
1139 format to use for the output of find then it is normally better
1140 to use `\0' as a terminator than to use newline, as file names
1141 can contain white space and newline characters. The setting of
1142 the `LC_CTYPE' environment variable is used to determine which
1143 characters need to be quoted.
1144
1145
1146 -print, -fprint
1147 Quoting is handled in the same way as for -printf and -fprintf.
1148 If you are using find in a script or in a situation where the
1149 matched files might have arbitrary names, you should consider
1150 using -print0 instead of -print.
1151
1152 The -ok and -okdir actions print the current filename as-is. This may
1153 change in a future release.
1154
1155
1156 OPERATORS
1157 Listed in order of decreasing precedence:
1158
1159
1160 ( expr )
1161 Force precedence. Since parentheses are special to the shell,
1162 you will normally need to quote them. Many of the examples in
1163 this manual page use backslashes for this purpose: `\(...\)'
1164 instead of `(...)'.
1165
1166
1167 ! expr True if expr is false. This character will also usually need
1168 protection from interpretation by the shell.
1169
1170
1171 -not expr
1172 Same as ! expr, but not POSIX compliant.
1173
1174
1175 expr1 expr2
1176 Two expressions in a row are taken to be joined with an implied
1177 "and"; expr2 is not evaluated if expr1 is false.
1178
1179
1180 expr1 -a expr2
1181 Same as expr1 expr2.
1182
1183
1184 expr1 -and expr2
1185 Same as expr1 expr2, but not POSIX compliant.
1186
1187
1188 expr1 -o expr2
1189 Or; expr2 is not evaluated if expr1 is true.
1190
1191
1192 expr1 -or expr2
1193 Same as expr1 -o expr2, but not POSIX compliant.
1194
1195
1196 expr1 , expr2
1197 List; both expr1 and expr2 are always evaluated. The value of
1198 expr1 is discarded; the value of the list is the value of expr2.
1199 The comma operator can be useful for searching for several dif‐
1200 ferent types of thing, but traversing the filesystem hierarchy
1201 only once. The -fprintf action can be used to list the various
1202 matched items into several different output files.
1203
1204
1205
1207 For closest compliance to the POSIX standard, you should set the
1208 POSIXLY_CORRECT environment variable. The following options are speci‐
1209 fied in the POSIX standard (IEEE Std 1003.1, 2003 Edition):
1210
1211
1212 -H This option is supported.
1213
1214
1215 -L This option is supported.
1216
1217
1218 -name This option is supported, but POSIX conformance depends on the
1219 POSIX conformance of the system's fnmatch(3) library function.
1220 As of findutils-4.2.2, shell metacharacters (`*', `?' or `[]'
1221 for example) will match a leading `.', because IEEE PASC inter‐
1222 pretation 126 requires this. This is a change from previous
1223 versions of findutils.
1224
1225
1226 -type Supported. POSIX specifies `b', `c', `d', `l', `p', `f' and
1227 `s'. GNU find also supports `D', representing a Door, where the
1228 OS provides these.
1229
1230
1231 -ok Supported. Interpretation of the response is according to the
1232 "yes" and "no" patterns selected by setting the `LC_MESSAGES'
1233 environment variable. When the `POSIXLY_CORRECT' environment
1234 variable is set, these patterns are taken system's definition of
1235 a positive (yes) or negative (no) response. See the system's
1236 documentation for nl_langinfo(3), in particular YESEXPR and
1237 NOEXPR. When `POSIXLY_CORRECT' is not set, the patterns are
1238 instead taken from find's own message catalogue.
1239
1240
1241 -newer Supported. If the file specified is a symbolic link, it is
1242 always dereferenced. This is a change from previous behaviour,
1243 which used to take the relevant time from the symbolic link; see
1244 the HISTORY section below.
1245
1246
1247 -perm Supported. If the POSIXLY_CORRECT environment variable is not
1248 set, some mode arguments (for example +a+x) which are not valid
1249 in POSIX are supported for backward-compatibility.
1250
1251
1252 Other predicates
1253 The predicates -atime, -ctime, -depth, -group, -links, -mtime,
1254 -nogroup, -nouser, -print, -prune, -size, -user and -xdev
1255 `-atime', `-ctime', `-depth', `-group', `-links', `-mtime',
1256 `-nogroup', `-nouser', `-perm', `-print', `-prune', `-size',
1257 `-user' and `-xdev', are all supported.
1258
1259
1260 The POSIX standard specifies parentheses `(', `)', negation `!' and the
1261 `and' and `or' operators ( -a, -o).
1262
1263 All other options, predicates, expressions and so forth are extensions
1264 beyond the POSIX standard. Many of these extensions are not unique to
1265 GNU find, however.
1266
1267 The POSIX standard requires that find detects loops:
1268
1269 The find utility shall detect infinite loops; that is, entering
1270 a previously visited directory that is an ancestor of the last
1271 file encountered. When it detects an infinite loop, find shall
1272 write a diagnostic message to standard error and shall either
1273 recover its position in the hierarchy or terminate.
1274
1275 GNU find complies with these requirements. The link count of directo‐
1276 ries which contain entries which are hard links to an ancestor will
1277 often be lower than they otherwise should be. This can mean that GNU
1278 find will sometimes optimise away the visiting of a subdirectory which
1279 is actually a link to an ancestor. Since find does not actually enter
1280 such a subdirectory, it is allowed to avoid emitting a diagnostic mes‐
1281 sage. Although this behaviour may be somewhat confusing, it is
1282 unlikely that anybody actually depends on this behaviour. If the leaf
1283 optimisation has been turned off with -noleaf, the directory entry will
1284 always be examined and the diagnostic message will be issued where it
1285 is appropriate. Symbolic links cannot be used to create filesystem
1286 cycles as such, but if the -L option or the -follow option is in use, a
1287 diagnostic message is issued when find encounters a loop of symbolic
1288 links. As with loops containing hard links, the leaf optimisation will
1289 often mean that find knows that it doesn't need to call stat() or
1290 chdir() on the symbolic link, so this diagnostic is frequently not nec‐
1291 essary.
1292
1293 The -d option is supported for compatibility with various BSD systems,
1294 but you should use the POSIX-compliant option -depth instead.
1295
1296 The POSIXLY_CORRECT environment variable does not affect the behaviour
1297 of the -regex or -iregex tests because those tests aren't specified in
1298 the POSIX standard.
1299
1301 LANG Provides a default value for the internationalization variables
1302 that are unset or null.
1303
1304
1305 LC_ALL If set to a non-empty string value, override the values of all
1306 the other internationalization variables.
1307
1308
1309 LC_COLLATE
1310 The POSIX standard specifies that this variable affects the pat‐
1311 tern matching to be used for the -name option. GNU find uses
1312 the fnmatch(3) library function, and so support for `LC_COLLATE'
1313 depends on the system library. This variable also affects the
1314 interpretation of the response to -ok; while the `LC_MESSAGES'
1315 variable selects the actual pattern used to interpret the
1316 response to -ok, the interpretation of any bracket expressions
1317 in the pattern will be affected by `LC_COLLATE'.
1318
1319
1320 LC_CTYPE
1321 This variable affects the treatment of character classes used in
1322 regular expressions and also with the -name test, if the sys‐
1323 tem's fnmatch(3) library function supports this. This variable
1324 also affects the interpretation of any character classes in the
1325 regular expressions used to interpret the response to the prompt
1326 issued by -ok. The `LC_CTYPE' environment variable will also
1327 affect which characters are considered to be unprintable when
1328 filenames are printed; see the section UNUSUAL FILENAMES.
1329
1330
1331 LC_MESSAGES
1332 Determines the locale to be used for internationalised messages.
1333 If the `POSIXLY_CORRECT' environment variable is set, this also
1334 determines the interpretation of the response to the prompt made
1335 by the -ok action.
1336
1337
1338 NLSPATH
1339 Determines the location of the internationalisation message cat‐
1340 alogues.
1341
1342
1343 PATH Affects the directories which are searched to find the executa‐
1344 bles invoked by -exec, -execdir, -ok and -okdir.
1345
1346
1347 POSIXLY_CORRECT
1348 Determines the block size used by -ls and -fls. If POSIXLY_COR‐
1349 RECT is set, blocks are units of 512 bytes. Otherwise they are
1350 units of 1024 bytes.
1351
1352 Setting this variable also turns off warning messages (that is,
1353 implies -nowarn) by default, because POSIX requires that apart
1354 from the output for -ok, all messages printed on stderr are
1355 diagnostics and must result in a non-zero exit status.
1356
1357 When POSIXLY_CORRECT is not set, -perm +zzz is treated just like
1358 -perm /zzz if +zzz is not a valid symbolic mode. When
1359 POSIXLY_CORRECT is set, such constructs are treated as an error.
1360
1361 When POSIXLY_CORRECT is set, the response to the prompt made by
1362 the -ok action is interpreted according to the system's message
1363 catalogue, as opposed to according to find's own message trans‐
1364 lations.
1365
1366
1367 TZ Affects the time zone used for some of the time-related format
1368 directives of -printf and -fprintf.
1369
1371 The findutils source distribution contains two different implementa‐
1372 tions of find. The older implementation descends the file system
1373 recursively, while the newer one uses fts(3). Both are normally
1374 installed.
1375
1376 If the option --without-fts was passed to configure, the recursive
1377 implementation is installed as find and the fts-based implementation is
1378 installed as ftsfind. Otherwise, the fts-based implementation is
1379 installed as find and the recursive implementation is installed as
1380 oldfind.
1381
1383 find /tmp -name core -type f -print | xargs /bin/rm -f
1384
1385 Find files named core in or below the directory /tmp and delete them.
1386 Note that this will work incorrectly if there are any filenames con‐
1387 taining newlines, single or double quotes, or spaces.
1388
1389 find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
1390
1391 Find files named core in or below the directory /tmp and delete them,
1392 processing filenames in such a way that file or directory names con‐
1393 taining single or double quotes, spaces or newlines are correctly han‐
1394 dled. The -name test comes before the -type test in order to avoid
1395 having to call stat(2) on every file.
1396
1397
1398 find . -type f -exec file '{}' \;
1399
1400 Runs `file' on every file in or below the current directory. Notice
1401 that the braces are enclosed in single quote marks to protect them from
1402 interpretation as shell script punctuation. The semicolon is similarly
1403 protected by the use of a backslash, though single quotes could have
1404 been used in that case also.
1405
1406
1407 find / \( -perm -4000 -fprintf /root/suid.txt '%#m %u %p\n' \) , \
1408 \( -size +100M -fprintf /root/big.txt '%-10s %p\n' \)
1409
1410 Traverse the filesystem just once, listing setuid files and directories
1411 into /root/suid.txt and large files into /root/big.txt.
1412
1413
1414 find $HOME -mtime 0
1415
1416 Search for files in your home directory which have been modified in the
1417 last twenty-four hours. This command works this way because the time
1418 since each file was last modified is divided by 24 hours and any
1419 remainder is discarded. That means that to match -mtime 0, a file will
1420 have to have a modification in the past which is less than 24 hours
1421 ago.
1422
1423
1424 find /sbin /usr/sbin -executable \! -readable -print
1425
1426 Search for files which are executable but not readable.
1427
1428
1429 find . -perm 664
1430
1431 Search for files which have read and write permission for their owner,
1432 and group, but which other users can read but not write to. Files
1433 which meet these criteria but have other permissions bits set (for
1434 example if someone can execute the file) will not be matched.
1435
1436
1437 find . -perm -664
1438
1439 Search for files which have read and write permission for their owner
1440 and group, and which other users can read, without regard to the pres‐
1441 ence of any extra permission bits (for example the executable bit).
1442 This will match a file which has mode 0777, for example.
1443
1444
1445 find . -perm /222
1446
1447 Search for files which are writable by somebody (their owner, or their
1448 group, or anybody else).
1449
1450
1451 find . -perm /220
1452 find . -perm /u+w,g+w
1453 find . -perm /u=w,g=w
1454
1455 All three of these commands do the same thing, but the first one uses
1456 the octal representation of the file mode, and the other two use the
1457 symbolic form. These commands all search for files which are writable
1458 by either their owner or their group. The files don't have to be
1459 writable by both the owner and group to be matched; either will do.
1460
1461
1462 find . -perm -220
1463 find . -perm -g+w,u+w
1464
1465 Both these commands do the same thing; search for files which are
1466 writable by both their owner and their group.
1467
1468
1469 find . -perm -444 -perm /222 ! -perm /111
1470 find . -perm -a+r -perm /a+w ! -perm /a+x
1471
1472 These two commands both search for files that are readable for every‐
1473 body ( -perm -444 or -perm -a+r), have at least one write bit set (
1474 -perm /222 or -perm /a+w) but are not executable for anybody ( ! -perm
1475 /111 and ! -perm /a+x respectively).
1476
1477
1478 cd /source-dir
1479 find . -name .snapshot -prune -o \( \! -name *~ -print0 \)|
1480 cpio -pmd0 /dest-dir
1481
1482 This command copies the contents of /source-dir to /dest-dir, but omits
1483 files and directories named .snapshot (and anything in them). It also
1484 omits files or directories whose name ends in ~, but not their con‐
1485 tents. The construct -prune -o \( ... -print0 \) is quite common. The
1486 idea here is that the expression before -prune matches things which are
1487 to be pruned. However, the -prune action itself returns true, so the
1488 following -o ensures that the right hand side is evaluated only for
1489 those directories which didn't get pruned (the contents of the pruned
1490 directories are not even visited, so their contents are irrelevant).
1491 The expression on the right hand side of the -o is in parentheses only
1492 for clarity. It emphasises that the -print0 action takes place only
1493 for things that didn't have -prune applied to them. Because the
1494 default `and' condition between tests binds more tightly than -o, this
1495 is the default anyway, but the parentheses help to show what is going
1496 on.
1497
1498
1499 find repo/ -exec test -d {}/.svn \; -or \
1500 -exec test -d {}/.git \; -or -exec test -d {}/CVS \; \
1501 -print -prune
1502
1503 Given the following directory of projects and their associated SCM
1504 administrative directories, perform an efficient search for the
1505 projects' roots:
1506
1507 repo/project1/CVS
1508 repo/gnu/project2/.svn
1509 repo/gnu/project3/.svn
1510 repo/gnu/project3/src/.svn
1511 repo/project4/.git
1512
1513 In this example, -prune prevents unnecessary descent into directories
1514 that have already been discovered (for example we do not search
1515 project3/src because we already found project3/.svn), but ensures sib‐
1516 ling directories (project2 and project3) are found.
1517
1518
1520 find exits with status 0 if all files are processed successfully,
1521 greater than 0 if errors occur. This is deliberately a very broad
1522 description, but if the return value is non-zero, you should not rely
1523 on the correctness of the results of find.
1524
1525
1527 locate(1), locatedb(5), updatedb(1), xargs(1), chmod(1), fnmatch(3),
1528 regex(7), stat(2), lstat(2), ls(1), printf(3), strftime(3), ctime(3),
1529 Finding Files (on-line in Info, or printed).
1530
1532 As of findutils-4.2.2, shell metacharacters (`*', `?' or `[]' for exam‐
1533 ple) used in filename patterns will match a leading `.', because IEEE
1534 POSIX interpretation 126 requires this.
1535
1536 As of findutils-4.3.3, -perm /000 now matches all files instead of
1537 none.
1538
1539 Nanosecond-resolution timestamps were implemented in findutils-4.3.3.
1540
1541 As of findutils-4.3.11, the -delete action sets find's exit status to a
1542 nonzero value when it fails. However, find will not exit immediately.
1543 Previously, find's exit status was unaffected by the failure of
1544 -delete.
1545
1546 Feature Added in Also occurs in
1547 -newerXY 4.3.3 BSD
1548 -D 4.3.1
1549 -O 4.3.1
1550 -readable 4.3.0
1551 -writable 4.3.0
1552 -executable 4.3.0
1553 -regextype 4.2.24
1554 -exec ... + 4.2.12 POSIX
1555 -execdir 4.2.12 BSD
1556 -okdir 4.2.12
1557 -samefile 4.2.11
1558 -H 4.2.5 POSIX
1559 -L 4.2.5 POSIX
1560 -P 4.2.5 BSD
1561 -delete 4.2.3
1562 -quit 4.2.3
1563
1564 -d 4.2.3 BSD
1565 -wholename 4.2.0
1566 -iwholename 4.2.0
1567 -ignore_readdir_race 4.2.0
1568 -fls 4.0
1569 -ilname 3.8
1570 -iname 3.8
1571 -ipath 3.8
1572 -iregex 3.8
1573
1574 The syntax -perm +MODE does not work as expected in findutils-4.5.11
1575 and it was removed in findutils-4.5.12, in favour of -perm /MODE. The
1576 +MODE syntax had been deprecated since findutils-4.2.21 which was
1577 released in 2005.
1578
1580 $ find . -name *.c -print
1581 find: paths must precede expression
1582 Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
1583
1584 This happens because *.c has been expanded by the shell resulting in
1585 find actually receiving a command line like this:
1586
1587 find . -name bigram.c code.c frcode.c locate.c -print
1588
1589 That command is of course not going to work. Instead of doing things
1590 this way, you should enclose the pattern in quotes or escape the wild‐
1591 card:
1592 $ find . -name '*.c' -print
1593 $ find . -name \*.c -print
1594
1595
1597 There are security problems inherent in the behaviour that the POSIX
1598 standard specifies for find, which therefore cannot be fixed. For
1599 example, the -exec action is inherently insecure, and -execdir should
1600 be used instead. Please see Finding Files for more information.
1601
1602 The environment variable LC_COLLATE has no effect on the -ok action.
1603
1604 The best way to report a bug is to use the form at http://savan‐
1605 nah.gnu.org/bugs/?group=findutils. The reason for this is that you
1606 will then be able to track progress in fixing the problem. Other com‐
1607 ments about find(1) and about the findutils package in general can be
1608 sent to the bug-findutils mailing list. To join the list, send email
1609 to bug-findutils-request@gnu.org.
1610
1611
1612
1613 FIND(1)