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