Imported Upstream version 4.5.10
[platform/upstream/findutils.git] / find / find.1
1 .TH FIND 1 \" -*- nroff -*-
2 .SH NAME
3 find \- search for files in a directory hierarchy
4 .SH SYNOPSIS
5 .B find
6 [\-H] [\-L] [\-P] [\-D debugopts] [\-Olevel] [path...] [expression]
7 .SH DESCRIPTION
8 This manual page
9 documents the GNU version of
10 .BR find .
11 GNU
12 .B find
13 searches the directory tree rooted at each given file name by
14 evaluating the given expression from left to right, according to the
15 rules of precedence (see section OPERATORS), until the outcome is
16 known (the left hand side is false for \fIand\fR operations, true for
17 \fIor\fR), at which point
18 .B find
19 moves on to the next file name.
20 .PP
21 If you are using
22 .B find
23 in an environment where security is important (for example if you are
24 using it to search directories that are writable by other users), you
25 should read the "Security Considerations" chapter of the findutils
26 documentation, which is called \fBFinding Files\fP and comes with
27 findutils.   That document also includes a lot more detail
28 and discussion than this manual page, so you may find it a more useful
29 source of information.
30 .SH OPTIONS
31 The
32 .BR \-H ,
33 .B \-L
34 and
35 .B \-P
36 options control the treatment of symbolic
37 links.  Command-line arguments following these are taken to be names
38 of files or directories to be examined, up to the first argument that
39 begins with `\-', or the argument `(' or `!'.  That argument and any
40 following arguments are taken to be the expression describing what is
41 to be searched for.  If no paths are given, the current directory is
42 used.  If no expression is given, the expression
43 .B \-print
44 is used
45 (but you should probably consider using
46 .B \-print0
47 instead, anyway).
48 .PP
49 This manual page talks about `options' within the expression list.
50 These options control the behaviour of
51 .B find
52 but are specified immediately after the last path name.  The five
53 `real' options
54 .BR \-H ,
55 .BR \-L ,
56 .BR \-P ,
57 .B  \-D
58 and
59 .B  \-O
60 must appear before
61 the first path name, if at all.  A double dash
62 .B \-\-
63 can also be used
64 to signal that any remaining arguments are not options (though
65 ensuring that all start points begin with either `./' or `/' is
66 generally safer if you use wildcards in the list of start points).
67 .IP \-P
68 Never follow symbolic links.  This is the default behaviour.  When
69 .B find
70 examines or prints information a file, and the file is a symbolic
71 link, the information used shall be taken from the properties of the
72 symbolic link itself.
73
74 .IP \-L
75 Follow symbolic links.  When
76 .B find
77 examines or prints information about files, the information used shall
78 be taken from the properties of the file to which the link points, not
79 from the link itself (unless it is a broken symbolic link or
80 .B find
81 is unable to examine the file to which the link points).  Use of this
82 option implies
83 .BR \-noleaf .
84 If you later use the
85 .B \-P
86 option,
87 .B \-noleaf
88 will still be in effect.  If
89 .B \-L
90 is in effect and
91 .B find
92 discovers a symbolic link to a subdirectory during its search,
93 the subdirectory pointed to by the symbolic link will be searched.
94 .IP
95 When the
96 .B \-L
97 option is in effect, the
98 .B \-type
99 predicate will always
100 match against the type of the file that a symbolic link points to
101 rather than the link itself (unless the symbolic link is broken).
102 Using
103 .B \-L
104 causes the
105 .B \-lname
106 and
107 .B \-ilname
108 predicates always to return
109 false.
110
111 .IP \-H
112 Do not follow symbolic links, except while processing the command
113 line arguments.  When
114 .B find
115 examines or prints information about files, the information used
116 shall be taken from the properties of the symbolic link itself.   The
117 only exception to this behaviour is when a file specified on the
118 command line is a symbolic link, and the link can be resolved.  For
119 that situation, the information used is taken from whatever the link
120 points to (that is, the link is followed).  The information about the
121 link itself is used as a fallback if the file pointed to by the
122 symbolic link cannot be examined.  If
123 .B \-H
124 is in effect and one of the
125 paths specified on the command line is a symbolic link to a directory,
126 the contents of that directory will be examined (though of course
127 \-maxdepth 0 would prevent this).
128 .P
129 If more than one of
130 .BR \-H ,
131 .B \-L
132 and
133 .B \-P
134 is specified, each overrides the
135 others; the last one appearing on the command line takes effect.
136 Since it is the default, the
137 .B \-P
138 option should be considered to be in
139 effect unless either
140 .B \-H
141 or
142 .B \-L
143 is specified.
144
145 GNU
146 .B find
147 frequently stats files during the processing of the command line
148 itself, before any searching has begun.  These options also affect how
149 those arguments are processed.  Specifically, there are a number of
150 tests that compare files listed on the command line against a file we
151 are currently considering.  In each case, the file specified on the
152 command line will have been examined and some of its properties will
153 have been saved.  If the named file is in fact a symbolic link, and
154 the
155 .B \-P
156 option is in effect (or if neither
157 .B \-H
158 nor
159 .B \-L
160 were specified), the information used for the comparison will be taken from
161 the properties of the symbolic link.  Otherwise, it will be taken from
162 the properties of the file the link points to.  If
163 .B find
164 cannot follow the link (for example because it has insufficient
165 privileges or the link points to a nonexistent file) the properties of
166 the link itself will be used.
167 .P
168 When the
169 .B \-H
170 or
171 .B \-L options are in effect, any symbolic links listed
172 as the argument of
173 .B \-newer
174 will be dereferenced, and the timestamp
175 will be taken from the file to which the symbolic link points.  The
176 same consideration applies to
177 .BR \-newerXY ,
178 .B \-anewer
179 and
180 .BR \-cnewer .
181
182 The
183 .B \-follow
184 option has a similar effect to
185 .BR \-L ,
186 though it takes
187 effect at the point where it appears (that is, if
188 .B \-L
189 is not used but
190 .B \-follow
191 is, any symbolic links appearing after
192 .B \-follow
193 on the
194 command line will be dereferenced, and those before it will not).
195
196 .IP "\-D debugoptions"
197 Print diagnostic information; this can be helpful to diagnose problems
198 with why
199 .B find
200 is not doing what you want.  The list of debug options should be comma
201 separated.  Compatibility of the debug options is not guaranteed
202 between releases of findutils.  For a complete list of valid debug
203 options, see the output of
204 .B find \-D
205 .BR help .
206 Valid debug options include
207 .RS
208 .IP help
209 Explain the debugging options
210 .IP tree
211 Show the expression tree in its original and optimised form.
212 .IP stat
213 Print messages as files are examined with the
214 .B stat
215 and
216 .B lstat
217 system calls.  The
218 .B find
219 program tries to minimise such calls.
220 .IP opt
221 Prints diagnostic information relating to the optimisation of the
222 expression tree; see the \-O option.
223 .IP rates
224 Prints a summary indicating how often each predicate succeeded or
225 failed.
226 .RE
227 .IP \-Olevel
228 Enables query optimisation.   The
229 .B find
230 program reorders tests to speed up execution while preserving the
231 overall effect; that is, predicates with side effects are not
232 reordered relative to each other.  The optimisations performed at each
233 optimisation level are as follows.
234 .RS
235 .IP 0
236 Equivalent to optimisation level 1.
237 .IP 1
238 This is the default optimisation level and corresponds to the
239 traditional behaviour.  Expressions are reordered so that tests based
240 only on the names of files (for example
241 .B \-name
242 and
243 .BR \-regex )
244 are performed first.
245 .IP 2
246 Any
247 .B \-type
248 or
249 .B \-xtype
250 tests are performed after any tests based only on the names of files,
251 but before any tests that require information from the inode.  On many
252 modern versions of Unix, file types are returned by
253 .B readdir()
254 and so these predicates are faster to evaluate than predicates which
255 need to stat the file first.
256 If you use the
257 .B \-fstype
258 .I FOO
259 predicate and specify a filsystem type
260 .I FOO
261 which is not known (that is, present in `/etc/mtab') at the time
262 .B find
263 starts, that predicate is equivalent to
264 .BR \-false .
265 .IP 3
266 At this optimisation level, the full cost-based query optimiser is
267 enabled.  The order of tests is modified so that cheap (i.e. fast)
268 tests are performed first and more expensive ones are performed later,
269 if necessary.  Within each cost band, predicates are evaluated earlier
270 or later according to whether they are likely to succeed or not.  For
271 .BR \-o ,
272 predicates which are likely to succeed are evaluated earlier, and for
273 .BR \-a ,
274 predicates which are likely to fail are evaluated earlier.
275 .RE
276 .IP
277 The cost-based optimiser has a fixed idea of how likely any given test
278 is to succeed.  In some cases the probability takes account of the
279 specific nature of the test (for example,
280 .B \-type f
281 is assumed to be more likely to succeed than
282 .BR "\-type c" ).
283 The cost-based optimiser is currently being evaluated.   If it does
284 not actually improve the performance of
285 .BR find ,
286 it will be removed again.  Conversely, optimisations that prove to be
287 reliable, robust and effective may be enabled at lower optimisation
288 levels over time.  However, the default behaviour (i.e. optimisation
289 level 1) will not be changed in the 4.3.x release series.  The
290 findutils test suite runs all the tests on
291 .B find
292 at each optimisation level and ensures that the result is the same.
293 .P
294 .SH EXPRESSIONS
295 The expression is made up of options (which affect overall operation
296 rather than the processing of a specific file, and always return
297 true), tests (which return a true or false value), and actions (which
298 have side effects and return a true or false value), all separated by
299 operators.
300 .B \-and
301 is assumed where the operator is omitted.
302
303 If the expression contains no actions other than
304 .BR \-prune ,
305 .B \-print
306 is
307 performed on all files for which the expression is true.
308
309 .SS OPTIONS
310 .P
311 All options always return true.  Except for
312 .BR \-daystart ,
313 .B \-follow
314 and
315 .BR \-regextype ,
316 the options affect all tests, including tests specified
317 before the option.  This is because the options are processed when the
318 command line is parsed, while the tests don't do anything until files
319 are examined.  The
320 .BR \-daystart ,
321 .B \-follow
322 and
323 .B \-regextype
324 options are different in this respect, and have an effect only on tests which
325 appear later in the command line.  Therefore, for clarity, it is best
326 to place them at the beginning of the expression.  A warning is issued
327 if you don't do this.
328
329 .IP \-d
330 A synonym for \-depth, for compatibility with FreeBSD, NetBSD, MacOS X and OpenBSD.
331
332 .IP \-daystart
333 Measure times (for
334 .BR \-amin ,
335 .BR \-atime ,
336 .BR \-cmin ,
337 .BR \-ctime ,
338 .BR \-mmin ,
339 and
340 .BR \-mtime )
341 from the beginning of today rather than from 24 hours ago.  This
342 option only affects tests which appear later on the command line.
343
344 .IP \-depth
345 Process each directory's contents before the directory itself.  The
346 \-delete action also implies
347 .BR \-depth .
348
349 .IP \-follow
350 Deprecated; use the
351 .B \-L
352 option instead.  Dereference symbolic links.
353 Implies
354 .BR \-noleaf .
355 The
356 .B \-follow
357 option affects only those tests which
358 appear after it on the command line.  Unless the
359 .B \-H
360 or
361 .B \-L
362 option has
363 been specified, the position of the
364 .B \-follow
365 option changes the behaviour of the
366 .B \-newer
367 predicate; any files listed as the argument
368 of
369 .B \-newer
370 will be dereferenced if they are symbolic links.  The same
371 consideration applies to
372 .BR \-newerXY ,
373 .B \-anewer
374 and
375 .BR \-cnewer .
376 Similarly, the
377 .B \-type
378 predicate will always match against the type of the file
379 that a symbolic link points to rather than the link itself.  Using
380 .B \-follow
381 causes the
382 .B \-lname and
383 .B \-ilname
384 predicates always to return false.
385
386 .IP "\-help, \-\-help"
387 Print a summary of the command-line usage of
388 .B find
389 and exit.
390
391 .IP \-ignore_readdir_race
392 Normally, \fBfind\fR will emit an error message when it fails to stat a file.
393 If you give this option and a file is deleted between the time \fBfind\fR
394 reads the name of the file from the directory and the time it tries to stat
395 the file, no error message will be issued.    This also applies to files
396 or directories whose names are given on the command line.  This option takes
397 effect at the time the command line is read, which means that you cannot search
398 one part of the filesystem with this option on and part of it with this option
399 off (if you need to do that, you will need to issue two \fBfind\fR commands
400 instead, one with the option and one without it).
401
402 .IP "\-maxdepth \fIlevels\fR"
403 Descend at most \fIlevels\fR (a non-negative integer) levels of
404 directories below the command line arguments.
405 .B \-maxdepth 0
406  means only apply the tests and actions to the command line arguments.
407
408 .IP "\-mindepth \fIlevels\fR"
409 Do not apply any tests or actions at levels less than \fIlevels\fR (a
410 non-negative integer).
411 .B \-mindepth 1
412 means process all files except the command line arguments.
413
414 .IP \-mount
415 Don't descend directories on other filesystems.  An alternate name for
416 .BR \-xdev ,
417 for compatibility with some other versions of
418 .BR find .
419
420 .IP \-noignore_readdir_race
421 Turns off the effect of
422 .BR \-ignore_readdir_race .
423
424 .IP "\-noleaf"
425 Do not optimize by assuming that directories contain 2 fewer
426 subdirectories than their hard link count.  This option is needed when
427 searching filesystems that do not follow the Unix directory-link
428 convention, such as CD-ROM or MS-DOS filesystems or AFS volume mount
429 points.  Each directory on a normal Unix filesystem has at least 2
430 hard links: its name and its `.'  entry.  Additionally, its
431 subdirectories (if any) each have a `..'  entry linked to that
432 directory.  When
433 .B find
434 is examining a directory, after it has statted 2 fewer subdirectories
435 than the directory's link count, it knows that the rest of the entries
436 in the directory are non-directories (`leaf' files in the directory
437 tree).  If only the files' names need to be examined, there is no need
438 to stat them; this gives a significant increase in search speed.
439
440 .IP "\-regextype \fItype\fR"
441 Changes the regular expression syntax understood by
442 .B \-regex
443 and
444 .B \-iregex
445 tests which occur later on the command line.  Currently-implemented
446 types are emacs (this is the default), posix-awk, posix-basic,
447 posix-egrep and posix-extended.
448
449 .IP "\-version, \-\-version"
450 Print the \fBfind\fR version number and exit.
451
452 .IP "\-warn, \-nowarn"
453 Turn warning messages on or off.  These warnings apply only to the
454 command line usage, not to any conditions that
455 .B find
456 might encounter when it searches directories.  The default behaviour
457 corresponds to
458 .B \-warn
459 if standard input is a tty, and to
460 .B \-nowarn
461 otherwise.
462
463 .IP \-xdev
464 Don't descend directories on other filesystems.
465
466 .SS TESTS
467 Some tests, for example
468 .B \-newerXY
469 and
470 .BR -samefile ,
471 allow comparison between the file currently being examined and some
472 reference file specified on the command line.  When these tests are
473 used, the interpretation of the reference file is determined by the
474 options
475 .BR \-H ,
476 .B \-L
477 and
478 .B \-P
479 and any previous
480 .BR \-follow ,
481 but the reference file is only examined once, at the time the command
482 line is parsed.  If the reference file cannot be examined (for
483 example, the
484 .BR stat (2)
485 system call fails for it), an error message is issued, and
486 .B find
487 exits with a nonzero status.
488 .P
489 Numeric arguments can be specified as
490 .IP \fI+n\fP
491 for greater than
492 .IR n ,
493 .IP \fI\-n\fP
494 for less than
495 .IR n ,
496 .IP \fIn\fP
497 for exactly
498 .IR n .
499 .P
500
501 .IP "\-amin \fIn\fR"
502 File was last accessed \fIn\fR minutes ago.
503
504 .IP "\-anewer \fIfile\fR"
505 File was last accessed more recently than \fIfile\fR was modified.  If
506 \fIfile\fR is a symbolic link and the
507 .B \-H
508 option or the
509 .B \-L
510 option is in effect, the access time of the file it points to is
511 always used.
512
513 .IP "\-atime \fIn\fR"
514 File was last accessed \fIn\fR*24 hours ago.
515 When find figures out how many 24-hour periods ago the file
516 was last accessed, any fractional part is ignored, so to match
517 .B \-atime
518 .BR +1 ,
519 a file has to have been accessed at least
520 .I two
521 days ago.
522
523 .IP "\-cmin \fIn\fR"
524 File's status was last changed \fIn\fR minutes ago.
525
526 .IP "\-cnewer \fIfile\fR"
527 File's status was last changed more recently than \fIfile\fR was
528 modified.  If \fIfile\fR is a symbolic link and the
529 .B \-H
530 option or the
531 .B \-L
532 option is in effect, the status-change time of the file it points
533 to is always used.
534
535 .IP "\-ctime \fIn\fR"
536 File's status was last changed \fIn\fR*24 hours ago.
537 See the comments for
538 .B \-atime
539 to understand how rounding affects the interpretation of file status
540 change times.
541
542 .IP \-empty
543 File is empty and is either a regular file or a directory.
544
545 .IP \-executable
546 Matches files which are executable and directories which are
547 searchable (in a file name resolution sense).  This takes into account
548 access control lists and other permissions artefacts which the
549 .B \-perm
550 test ignores.  This test makes use of the
551 .BR access (2)
552 system call, and so can be fooled by NFS servers which do UID
553 mapping (or root-squashing), since many systems implement
554 .BR access (2)
555 in the client's kernel and so cannot make use of the UID mapping
556 information held on the server.  Because this test is based only on
557 the result of the
558 .BR access (2)
559 system call, there is no guarantee that a file for which this test
560 succeeds can actually be executed.
561
562 .IP \-false
563 Always false.
564
565 .IP "\-fstype \fItype\fR"
566 File is on a filesystem of type \fItype\fR.  The valid filesystem
567 types vary among different versions of Unix; an incomplete list of
568 filesystem types that are accepted on some version of Unix or another
569 is: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K.  You can use
570 .B \-printf
571 with the %F directive to see the types of your filesystems.
572
573 .IP "\-gid \fIn\fR"
574 File's numeric group ID is \fIn\fR.
575
576 .IP "\-group \fIgname\fR"
577 File belongs to group \fIgname\fR (numeric group ID allowed).
578
579 .IP "\-ilname \fIpattern\fR"
580 Like
581 .BR \-lname ,
582 but the match is case insensitive.
583 If the
584 .B \-L
585 option or the
586 .B \-follow
587 option is in effect, this test returns false unless the symbolic link
588 is broken.
589
590
591 .IP "\-iname \fIpattern\fR"
592 Like
593 .BR \-name ,
594 but the match is case insensitive.  For example, the
595 patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo',
596 `fOo', etc.   The pattern `*foo*` will also match a file
597 called '.foobar'.
598
599 .IP "\-inum \fIn\fR"
600 File has inode number \fIn\fR.  It is normally easier to use the
601 .B \-samefile
602 test instead.
603
604 .IP "\-ipath \fIpattern\fR"
605 Like
606 .BR \-path .
607 but the match is case insensitive.
608
609 .IP "\-iregex \fIpattern\fR"
610 Like
611 .BR \-regex ,
612 but the match is case insensitive.
613
614 .IP "\-iwholename \fIpattern\fR"
615 See \-ipath.    This alternative is less portable than
616 .BR \-ipath .
617
618 .IP "\-links \fIn\fR"
619 File has \fIn\fR links.
620
621 .IP "\-lname \fIpattern\fR"
622 File is a symbolic link whose contents match shell pattern
623 \fIpattern\fR.  The metacharacters do not treat `/' or `.' specially.
624 If the
625 .B \-L
626 option or the
627 .B \-follow
628 option is in effect, this test returns false unless the symbolic link
629 is broken.
630
631 .IP "\-mmin \fIn\fR"
632 File's data was last modified \fIn\fR minutes ago.
633
634 .IP "\-mtime \fIn\fR"
635 File's data was last modified \fIn\fR*24 hours ago.
636 See the comments for
637 .B \-atime
638 to understand how rounding affects the interpretation of file
639 modification times.
640
641 .IP "\-name \fIpattern\fR"
642 Base of file name (the path with the leading directories removed)
643 matches shell pattern \fIpattern\fR.  Because the leading directories
644 are removed, the file names considered for a match with
645 .B \-name
646 will never include a slash, so `\-name a/b' will never match anything
647 (you probably need to use
648 .B \-path
649 instead).  The metacharacters (`*', `?',
650 and `[]') match a `.' at the start of the base name (this is a change
651 in findutils-4.2.2; see section STANDARDS CONFORMANCE below).  To ignore a
652 directory and the files under it, use
653 .BR \-prune ;
654 see an example in the
655 description of
656 .BR \-path .
657 Braces are not recognised as being
658 special, despite the fact that some shells including Bash imbue braces
659 with a special meaning in shell patterns.  The filename matching is
660 performed with the use of the
661 .BR fnmatch (3)
662 library function.   Don't forget to enclose the pattern in quotes
663 in order to protect it from expansion by the shell.
664
665 .IP "\-newer \fIfile\fR"
666 File was modified more recently than \fIfile\fR.  If \fIfile\fR is a
667 symbolic link and the
668 .B \-H
669 option or the
670 .B \-L
671 option is in effect, the
672 modification time of the file it points to is always used.
673
674 .IP "\-newerXY \fIreference\fR"
675 Compares the timestamp of the current file with \fIreference\fR.
676 The
677 .I reference
678 argument is normally the name of a file (and one of its timestamps is
679 used for the comparison) but it may also be a string describing an
680 absolute time.
681 .I X
682 and
683 .I Y
684 are placeholders for other letters, and these letters select which
685 time belonging to
686 how
687 .I reference
688 is used for the comparison.
689 .TS
690 ll
691 ll
692 ll
693 ll
694 llw(2i).
695 a       The access time of the file \fIreference\fR
696 B       The birth time of the file \fIreference\fR
697 c       The inode status change time of \fIreference\fR
698 m       The modification time of the file \fIreference\fR
699 t       \fIreference\fR is interpreted directly as a time
700 .TE
701
702 Some combinations are invalid; for example, it is invalid for
703 .I X
704 to be
705 .IR t .
706 Some combinations are not implemented on all systems; for example
707 .I B
708 is not supported on all systems.  If an invalid or unsupported
709 combination of
710 .I XY
711 is specified, a fatal error results.  Time specifications are
712 interpreted as for the argument to the
713 .B \-d
714 option of GNU
715 .BR date .
716 If you try to use the birth time of a reference file, and the birth
717 time cannot be determined, a fatal error message results.  If you
718 specify a test which refers to the birth time of files being examined,
719 this test will fail for any files where the birth time is unknown.
720
721 .IP \-nogroup
722 No group corresponds to file's numeric group ID.
723
724 .IP \-nouser
725 No user corresponds to file's numeric user ID.
726
727 .IP "\-path \fIpattern\fR"
728 File name matches shell pattern \fIpattern\fR.  The metacharacters do
729 not treat `/' or `.' specially; so, for example,
730 .br
731 .in +1i
732 find . \-path "./sr*sc"
733 .br
734 .in -1i
735 will print an entry for a directory called `./src/misc' (if one
736 exists).  To ignore a whole directory tree, use
737 .B \-prune
738 rather than
739 checking every file in the tree.  For example, to skip the
740 directory `src/emacs' and all files and directories under it, and
741 print the names of the other files found, do something like this:
742 .br
743 .in +1i
744 find . \-path ./src/emacs \-prune \-o \-print
745 .br
746 .in -1i
747 Note that the pattern match test applies to the whole file name,
748 starting from one of the start points named on the command line.  It
749 would only make sense to use an absolute path name here if the
750 relevant start point is also an absolute path.  This means that this
751 command will never match anything:
752 .br
753 .in +1i
754 find bar \-path /foo/bar/myfile \-print
755 .br
756 .in -1i
757 Find compares the
758 .B \-path
759 argument with the concatenation of a directory name and the base name
760 of the file it's examining.  Since the concatenation will never end
761 with a slash,
762 .B \-path
763 arguments ending in a slash will match nothing (except perhaps a start
764 point specified on the command line).
765 The predicate
766 .B \-path
767 is also supported by HP-UX
768 .B find
769 and will be in a forthcoming version of the POSIX standard.
770
771 .IP "\-perm \fImode\fR"
772 File's permission bits are exactly \fImode\fR (octal or symbolic).
773 Since an exact match is required, if you want to use this form for
774 symbolic modes, you may have to specify a rather complex mode string.
775 For example `\-perm g=w' will only match files which have mode 0020
776 (that is, ones for which group write permission is the only permission
777 set).  It is more likely that you will want to use the `/' or `-'
778 forms, for example `\-perm \-g=w', which matches any file with group
779 write permission.  See the
780 .B EXAMPLES
781 section for some illustrative examples.
782
783 .IP "\-perm \-\fImode\fR"
784 All of the permission bits \fImode\fR are set for the file.
785 Symbolic modes are accepted in this form, and this is usually the way
786 in which would want to use them.  You must specify `u', `g' or `o' if
787 you use a symbolic mode.   See the
788 .B EXAMPLES
789 section for some illustrative examples.
790
791 .IP "\-perm /\fImode\fR"
792 Any of the permission bits \fImode\fR are set for the file.  Symbolic
793 modes are accepted in this form.  You must specify `u', `g' or `o' if
794 you use a symbolic mode.  See the
795 .B EXAMPLES
796 section for some illustrative examples.  If no permission bits in
797 .I mode
798 are set, this test matches any file (the idea here is to be consistent
799 with the behaviour of
800 .B \-perm
801 .BR \-000 ).
802
803 .IP "\-perm +\fImode\fR"
804 Deprecated, old way of searching for files with any of the permission
805 bits in \fImode\fR set.  You should use
806 .B \-perm \fI/mode\fR
807 instead. Trying to use the `+' syntax with symbolic modes will yield
808 surprising results.  For example, `+u+x' is a valid symbolic mode
809 (equivalent to +u,+x, i.e. 0111) and will therefore not be evaluated
810 as
811 .B \-perm +\fImode\fR
812 but instead as the exact mode specifier
813 .B \-perm \fImode\fR
814 and so it matches files with exact permissions 0111 instead of files with any
815 execute bit set.  If you found this paragraph confusing, you're not
816 alone - just use
817 .B \-perm /\fImode\fR.
818 This form of the
819 .B \-perm
820 test is deprecated because the POSIX specification requires the
821 interpretation of a leading `+' as being part of a symbolic mode, and
822 so we switched to using `/' instead.
823
824 .IP \-readable
825 Matches files which are readable.  This takes into account access
826 control lists and other permissions artefacts which the
827 .B \-perm
828 test ignores.  This test makes use of the
829 .BR access (2)
830 system call, and so can be fooled by NFS servers which do UID
831 mapping (or root-squashing), since many systems implement
832 .BR access (2)
833 in the client's kernel and so cannot make use of the UID mapping
834 information held on the server.
835
836 .IP "\-regex \fIpattern\fR"
837 File name matches regular expression \fIpattern\fR.  This is a match
838 on the whole path, not a search.  For example, to match a file named
839 `./fubar3', you can use the regular expression `.*bar.' or `.*b.*3',
840 but not `f.*r3'.  The regular expressions understood by
841 .B find
842 are by default Emacs Regular Expressions, but this can be
843 changed with the
844 .B \-regextype
845 option.
846
847 .IP "\-samefile \fIname\fR"
848 File refers to the same inode as \fIname\fR.   When
849 .B \-L
850 is in effect, this can include symbolic links.
851
852 .IP "\-size \fIn\fR[cwbkMG]"
853 File uses \fIn\fP units of space.  The following suffixes
854 can be used:
855 .RS
856 .IP `b'
857 for 512-byte blocks (this is the default if no suffix is used)
858 .IP `c'
859 for bytes
860 .IP `w'
861 for two-byte words
862 .IP `k'
863 for Kilobytes (units of 1024 bytes)
864 .IP `M'
865 for Megabytes (units of 1048576 bytes)
866 .IP `G'
867 for Gigabytes (units of 1073741824 bytes)
868 .RE
869 .IP
870 The size does not count indirect blocks, but it does count blocks in
871 sparse files that are not actually allocated.  Bear in mind that the
872 `%k' and `%b' format specifiers of
873 .B \-printf
874 handle sparse files
875 differently.  The `b' suffix always denotes 512-byte blocks and never
876 1 Kilobyte blocks, which is different to the behaviour of
877 .BR \-ls .
878
879 .IP \-true
880 Always true.
881
882 .IP "\-type \fIc\fR"
883 File is of type \fIc\fR:
884 .RS
885 .IP b
886 block (buffered) special
887 .IP c
888 character (unbuffered) special
889 .IP d
890 directory
891 .IP p
892 named pipe (FIFO)
893 .IP f
894 regular file
895 .IP l
896 symbolic link; this is never true if the
897 .B \-L
898 option or the
899 .B \-follow
900 option is in effect, unless the symbolic link is broken.  If you want
901 to search for symbolic links when
902 .B \-L
903 is in effect, use
904 .BR \-xtype .
905 .IP s
906 socket
907 .IP D
908 door (Solaris)
909 .RE
910 .IP "\-uid \fIn\fR"
911 File's numeric user ID is \fIn\fR.
912
913 .IP "\-used \fIn\fR"
914 File was last accessed \fIn\fR days after its status was last changed.
915
916 .IP "\-user \fIuname\fR"
917 File is owned by user \fIuname\fR (numeric user ID allowed).
918
919 .IP "\-wholename \fIpattern\fR"
920 See \-path.    This alternative is less portable than
921 .BR \-path .
922
923 .IP "\-writable"
924 Matches files which are writable.  This takes into account access
925 control lists and other permissions artefacts which the
926 .B \-perm
927 test ignores.  This test makes use of the
928 .BR access (2)
929 system call, and so can be fooled by NFS servers which do UID
930 mapping (or root-squashing), since many systems implement
931 .BR access (2)
932 in the client's kernel and so cannot make use of the UID mapping
933 information held on the server.
934
935 .IP "\-xtype \fIc\fR"
936 The same as
937 .B \-type
938 unless the file is a symbolic link.  For symbolic
939 links: if the
940 .B \-H
941 or
942 .B \-P
943 option was specified, true if the file is a
944 link to a file of type \fIc\fR; if the
945 .B \-L
946 option has been given, true
947 if \fIc\fR is `l'.  In other words, for symbolic links,
948 .B \-xtype
949 checks the type of the file that
950 .B \-type
951 does not check.
952 .IP "\-context \fIpattern\fR"
953 (SELinux only) Security context of the file matches glob \fIpattern\fR.
954
955 .SS ACTIONS
956 .IP "\-delete\fR"
957 Delete files; true if removal succeeded.  If the removal failed, an
958 error message is issued.
959 If
960 .B \-delete
961 fails,
962 .BR find 's
963 exit status will be nonzero
964 (when it eventually exits).
965 Use of
966 .B \-delete
967 automatically turns on the
968 .RB ` \-depth '
969 option.
970
971 .BR Warnings :
972 Don't forget that the find command line is
973 evaluated as an expression, so putting
974 .B \-delete
975 first will make
976 .B find
977 try to delete everything below the starting points you specified.
978 When testing a
979 .B find
980 command line that you later intend to use with
981 .BR \-delete ,
982 you should explicitly specify
983 .B \-depth
984 in order to avoid later surprises.  Because
985 .B \-delete
986 implies
987 .BR \-depth ,
988 you cannot usefully use
989 .B \-prune
990 and
991 .B \-delete
992 together.
993
994 .IP "\-exec \fIcommand\fR ;"
995 Execute \fIcommand\fR; true if 0 status is returned.  All following
996 arguments to
997 .B find
998 are taken to be arguments to the command until an argument consisting
999 of `;' is encountered.  The string `{}' is replaced by the current
1000 file name being processed everywhere it occurs in the arguments to the
1001 command, not just in arguments where it is alone, as in some versions
1002 of
1003 .BR find .
1004 Both of these constructions might need to be escaped (with a `\e') or
1005 quoted to protect them from expansion by the shell.  See the
1006 .B EXAMPLES
1007 section for examples of the use of the
1008 .B \-exec
1009 option.  The specified
1010 command is run once for each matched file.
1011 The command is executed in the starting directory.   There are
1012 unavoidable security problems surrounding use of the
1013 .B \-exec
1014 action;
1015 you should use the
1016 .B \-execdir
1017 option instead.
1018
1019 .IP "\-exec \fIcommand\fR {} +"
1020 This variant of the
1021 .B \-exec
1022 action runs the specified command on the
1023 selected files, but the command line is built by appending each
1024 selected file name at the end; the total number of invocations of the
1025 command will be much less than the number of matched files.  The
1026 command line is built in much the same way that
1027 .B xargs
1028 builds its command lines.  Only one instance of `{}' is allowed within
1029 the command.  The command is executed in the starting directory.
1030
1031 .IP "\-execdir \fIcommand\fR ;"
1032 .IP "\-execdir \fIcommand\fR {} +"
1033 Like
1034 .BR \-exec ,
1035 but the specified command is run from the subdirectory
1036 containing the matched file, which is not normally the directory in
1037 which you started
1038 .BR find .
1039 This a much more secure method for invoking commands, as it avoids
1040 race conditions during resolution of the paths to the matched files.
1041 As with the
1042 .B \-exec
1043 action, the `+' form of
1044 .B \-execdir
1045 will build a
1046 command line to process more than one matched file, but any given
1047 invocation of
1048 .I command
1049 will only list files that exist in the same subdirectory.  If you use
1050 this option, you must ensure that your
1051 .B $PATH
1052 environment variable does not reference `.';
1053 otherwise, an attacker can run any commands they like by leaving an
1054 appropriately-named file in a directory in which you will run
1055 .BR \-execdir .
1056 The same applies to having entries in
1057 .B $PATH
1058 which are empty or which are not absolute directory names.
1059
1060 .IP "\-fls \fIfile\fR"
1061 True; like
1062 .B \-ls
1063 but write to \fIfile\fR like
1064 .BR \-fprint .
1065 The output file is always created, even if the predicate is never
1066 matched.
1067 See the
1068 .B UNUSUAL FILENAMES
1069 section for information about how unusual characters in filenames are handled.
1070
1071 .IP "\-fprint \fIfile\fR"
1072 True; print the full file name into file \fIfile\fR.  If \fIfile\fR
1073 does not exist when \fBfind\fR is run, it is created; if it does
1074 exist, it is truncated.  The file names `/dev/stdout' and
1075 `/dev/stderr' are handled specially; they refer to the standard
1076 output and standard error output, respectively.
1077 The output file is always created, even if the predicate is never matched.
1078 See the
1079 .B UNUSUAL FILENAMES
1080 section for information about how unusual characters in filenames are handled.
1081
1082 .IP "\-fprint0 \fIfile\fR"
1083 True; like
1084 .B \-print0
1085 but write to \fIfile\fR like
1086 .BR \-fprint .
1087 The output file is always created, even if the predicate is never matched.
1088 See the
1089 .B UNUSUAL FILENAMES
1090 section for information about how unusual characters in filenames are handled.
1091
1092 .IP "\-fprintf \fIfile\fR \fIformat\fR"
1093 True; like
1094 .B \-printf
1095 but write to \fIfile\fR like
1096 .BR \-fprint .
1097 The output file is always created, even if the predicate is never matched.
1098 See the
1099 .B UNUSUAL FILENAMES
1100 section for information about how unusual characters in filenames are handled.
1101
1102 .IP \-ls
1103 True; list current file in
1104 .B ls \-dils
1105 format on standard output.
1106 The block counts are of 1K blocks, unless the environment variable
1107 POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
1108 See the
1109 .B UNUSUAL FILENAMES
1110 section for information about how unusual characters in filenames are handled.
1111
1112 .IP "\-ok \fIcommand\fR ;"
1113 Like
1114 .B \-exec
1115 but ask the user first.  If the user agrees, run the command.  Otherwise
1116 just return false.  If the command is run, its standard input is redirected
1117 from
1118 .BR /dev/null .
1119
1120 .IP
1121 The response to the prompt is matched against a pair of regular
1122 expressions to determine if it is an affirmative or negative
1123 response.  This regular expression is obtained from the system if the
1124 `POSIXLY_CORRECT' environment variable is set, or otherwise from
1125 .BR find 's
1126 message translations.  If the system has no suitable
1127 definition,
1128 .BR find 's
1129 own definition will be used.   In either case, the interpretation of
1130 the regular expression itself will be affected by the environment
1131 variables 'LC_CTYPE' (character classes) and 'LC_COLLATE' (character
1132 ranges and equivalence classes).
1133
1134
1135
1136 .IP "\-okdir \fIcommand\fR ;"
1137 Like
1138 .B \-execdir
1139 but ask the user first in the same way as for
1140 .BR \-ok .
1141 If the user does not agree, just return false.
1142 If the command is run, its standard input is redirected from
1143 .BR /dev/null .
1144
1145 .IP \-print
1146 True; print the full file name on the standard output, followed by a
1147 newline.   If you are piping the output of
1148 .B find
1149 into another program and there is the faintest possibility that the files
1150 which you are searching for might contain a newline, then you should
1151 seriously consider using the
1152 .B \-print0
1153 option instead of
1154 .BR \-print .
1155 See the
1156 .B UNUSUAL FILENAMES
1157 section for information about how unusual characters in filenames are handled.
1158
1159 .IP \-print0
1160 True; print the full file name on the standard output, followed by a
1161 null character (instead of the newline character that
1162 .B \-print
1163 uses).
1164 This allows file names that contain newlines or other types of white
1165 space to be correctly interpreted by programs that process the
1166 \fBfind\fR output.  This option corresponds to the
1167 .B \-0
1168 option of
1169 .BR xargs .
1170
1171 .IP "\-printf \fIformat\fR"
1172 True; print \fIformat\fR on the standard output, interpreting `\e'
1173 escapes and `%' directives.  Field widths and precisions can be
1174 specified as with the `printf' C function.  Please note that many of
1175 the fields are printed as %s rather than %d, and this may mean that
1176 flags don't work as you might expect.  This also means that the `\-'
1177 flag does work (it forces fields to be left-aligned).  Unlike
1178 .BR \-print ,
1179 .B \-printf
1180 does not add a newline at the end of the string.  The escapes
1181 and directives are:
1182 .RS
1183 .IP \ea
1184 Alarm bell.
1185 .IP \eb
1186 Backspace.
1187 .IP \ec
1188 Stop printing from this format immediately and flush the output.
1189 .IP \ef
1190 Form feed.
1191 .IP \en
1192 Newline.
1193 .IP \er
1194 Carriage return.
1195 .IP \et
1196 Horizontal tab.
1197 .IP \ev
1198 Vertical tab.
1199 .IP \e0
1200 ASCII NUL.
1201 .IP \e\e
1202 A literal backslash (`\e').
1203 .IP \eNNN
1204 The character whose ASCII code is NNN (octal).
1205 .PP
1206 A `\e' character followed by any other character is treated as an
1207 ordinary character, so they both are printed.
1208 .IP %%
1209 A literal percent sign.
1210 .IP %a
1211 File's last access time in the format returned by the C `ctime' function.
1212 .IP %A\fIk\fP
1213 File's last access time in the format specified by \fIk\fR, which is
1214 either `@' or a directive for the C `strftime' function.  The possible
1215 values for \fIk\fR are listed below; some of them might not be
1216 available on all systems, due to differences in `strftime' between
1217 systems.
1218 .RS
1219 .IP @
1220 seconds since Jan. 1, 1970, 00:00 GMT, with fractional part.
1221 .PP
1222 Time fields:
1223 .IP H
1224 hour (00..23)
1225 .IP I
1226 hour (01..12)
1227 .IP k
1228 hour ( 0..23)
1229 .IP l
1230 hour ( 1..12)
1231 .IP M
1232 minute (00..59)
1233 .IP p
1234 locale's AM or PM
1235 .IP r
1236 time, 12-hour (hh:mm:ss [AP]M)
1237 .IP S
1238 Second (00.00 .. 61.00).  There is a fractional part.
1239 .IP T
1240 time, 24-hour (hh:mm:ss)
1241 .IP +
1242 Date and time, separated by `+', for example
1243 `2004\-04\-28+22:22:05.0'.  This is a GNU extension.  The time is
1244 given in the current timezone (which may be affected by setting the TZ
1245 environment variable).  The seconds field includes a fractional part.
1246 .IP X
1247 locale's time representation (H:M:S)
1248 .IP Z
1249 time zone (e.g., EDT), or nothing if no time zone is determinable
1250 .PP
1251 Date fields:
1252 .IP a
1253 locale's abbreviated weekday name (Sun..Sat)
1254 .IP A
1255 locale's full weekday name, variable length (Sunday..Saturday)
1256 .IP b
1257 locale's abbreviated month name (Jan..Dec)
1258 .IP B
1259 locale's full month name, variable length (January..December)
1260 .IP c
1261 locale's date and time (Sat Nov 04 12:02:33 EST 1989).  The format is
1262 the same as for
1263 .BR ctime (3)
1264 and so to preserve compatibility with that format, there is no fractional part
1265 in the seconds field.
1266 .IP d
1267 day of month (01..31)
1268 .IP D
1269 date (mm/dd/yy)
1270 .IP h
1271 same as b
1272 .IP j
1273 day of year (001..366)
1274 .IP m
1275 month (01..12)
1276 .IP U
1277 week number of year with Sunday as first day of week (00..53)
1278 .IP w
1279 day of week (0..6)
1280 .IP W
1281 week number of year with Monday as first day of week (00..53)
1282 .IP x
1283 locale's date representation (mm/dd/yy)
1284 .IP y
1285 last two digits of year (00..99)
1286 .IP Y
1287 year (1970...)
1288 .RE
1289 .IP %b
1290 The amount of disk space used for this file in 512-byte blocks. Since disk
1291 space is allocated in multiples of the filesystem block size this is usually
1292 greater than %s/512, but it can also be smaller if the file is a sparse file.
1293 .IP %c
1294 File's last status change time in the format returned by the C `ctime'
1295 function.
1296 .IP %C\fIk\fP
1297 File's last status change time in the format specified by \fIk\fR,
1298 which is the same as for %A.
1299 .IP %d
1300 File's depth in the directory tree; 0 means the file is a command line
1301 argument.
1302 .IP %D
1303 The device number on which the file exists (the st_dev field of struct
1304 stat), in decimal.
1305 .IP %f
1306 File's name with any leading directories removed (only the last element).
1307 .IP %F
1308 Type of the filesystem the file is on; this value can be used for
1309 \-fstype.
1310 .IP %g
1311 File's group name, or numeric group ID if the group has no name.
1312 .IP %G
1313 File's numeric group ID.
1314 .IP %h
1315 Leading directories of file's name (all but the last element).
1316 If the file name contains no slashes (since it is in the current
1317 directory) the %h specifier expands to ".".
1318 .IP %H
1319 Command line argument under which file was found.
1320 .IP %i
1321 File's inode number (in decimal).
1322 .IP %k
1323 The amount of disk space used for this file in 1K blocks. Since disk space is
1324 allocated in multiples of the filesystem block size this is usually greater
1325 than %s/1024, but it can also be smaller if the file is a sparse file.
1326 .IP %l
1327 Object of symbolic link (empty string if file is not a symbolic link).
1328 .IP %m
1329 File's permission bits (in octal).  This option uses the `traditional'
1330 numbers which most Unix implementations use, but if your particular
1331 implementation uses an unusual ordering of octal permissions bits, you
1332 will see a difference between the actual value of the file's mode and
1333 the output of %m.   Normally you will want to have a leading
1334 zero on this number, and to do this, you should use the
1335 .B #
1336 flag (as in, for example, `%#m').
1337 .IP %M
1338 File's permissions (in symbolic form, as for
1339 .BR ls ).
1340 This directive is supported in findutils 4.2.5 and later.
1341 .IP %n
1342 Number of hard links to file.
1343 .IP %p
1344 File's name.
1345 .IP %P
1346 File's name with the name of the command line argument under which
1347 it was found removed.
1348 .IP %s
1349 File's size in bytes.
1350 .IP %S
1351 File's sparseness.  This is calculated as (BLOCKSIZE*st_blocks /
1352 st_size).  The exact value you will get for an ordinary file of a
1353 certain length is system-dependent.  However, normally sparse files
1354 will have values less than 1.0, and files which use indirect blocks
1355 may have a value which is greater than 1.0.   The value used for
1356 BLOCKSIZE is system-dependent, but is usually 512 bytes.   If the file
1357 size is zero, the value printed is undefined.  On systems which lack
1358 support for st_blocks, a file's sparseness is assumed to be 1.0.
1359 .IP %t
1360 File's last modification time in the format returned by the C `ctime'
1361 function.
1362 .IP %T\fIk\fP
1363 File's last modification time in the format specified by \fIk\fR,
1364 which is the same as for %A.
1365 .IP %u
1366 File's user name, or numeric user ID if the user has no name.
1367 .IP %U
1368 File's numeric user ID.
1369 .IP %y
1370 File's type (like in
1371 .BR "ls \-l" ),
1372 U=unknown type (shouldn't happen)
1373 .IP %Y
1374 File's type (like %y), plus follow symlinks: L=loop, N=nonexistent
1375 .IP %Z
1376 (SELinux only) file's security context.
1377 .PP
1378 A `%' character followed by any other character is discarded, but the
1379 other character is printed (don't rely on this, as further format
1380 characters may be introduced).  A `%' at the end of the format
1381 argument causes undefined behaviour since there is no following
1382 character.  In some locales, it may hide your door keys, while in
1383 others it may remove the final page from the novel you are reading.
1384
1385 The %m and %d directives support the
1386 .B #
1387 ,
1388 .B 0
1389 and
1390 .B +
1391 flags, but the other directives do not, even if they
1392 print numbers.  Numeric directives that do not support these flags
1393 include
1394 .BR G ,
1395 .BR U ,
1396 .BR b ,
1397 .BR D ,
1398 .B  k
1399 and
1400 .BR n .
1401 The `\-' format flag is supported and changes the alignment of a field
1402 from right-justified (which is the default) to left-justified.
1403 .PP
1404 See the
1405 .B UNUSUAL FILENAMES
1406 section for information about how unusual characters in filenames are handled.
1407
1408
1409 .RE
1410 .IP \-prune
1411 True; if the file is a directory, do not descend into it. If
1412 .B \-depth
1413 is given, false; no effect.  Because
1414 .B \-delete
1415 implies
1416 .BR \-depth ,
1417 you cannot usefully use
1418 .B \-prune
1419 and
1420 .B \-delete together.
1421
1422 .IP "\-quit"
1423 Exit immediately.  No child processes will be left running, but no more
1424 paths specified on the command line will be processed.  For example,
1425 .B find /tmp/foo /tmp/bar \-print \-quit
1426 will print only
1427 .BR /tmp/foo .
1428 Any command lines which have been built up with
1429 .B \-execdir ... {} +
1430 will be invoked before
1431 .B find
1432 exits.   The exit status may or may not be zero, depending on whether
1433 an error has already occurred.
1434
1435 .SS UNUSUAL FILENAMES
1436 Many of the actions of
1437 .B find
1438 result in the printing of data which is under the control of other
1439 users.  This includes file names, sizes, modification times and so
1440 forth.  File names are a potential problem since they can contain any
1441 character except `\e0' and `/'.  Unusual characters in file names can
1442 do unexpected and often undesirable things to your terminal (for
1443 example, changing the settings of your function keys on some
1444 terminals).  Unusual characters are handled differently by various
1445 actions, as described below.
1446
1447 .IP "\-print0, \-fprint0\"
1448 Always print the exact filename, unchanged, even if the output is
1449 going to a terminal.
1450
1451 .IP "\-ls, \-fls"
1452 Unusual characters are always escaped.  White space, backslash, and
1453 double quote characters are printed using C-style escaping (for
1454 example `\ef', `\e"').  Other unusual characters are printed using an
1455 octal escape.  Other printable characters (for
1456 .B \-ls
1457 and
1458 .B \-fls
1459 these are the characters between octal 041 and 0176) are printed as-is.
1460
1461 .IP "\-printf, \-fprintf"
1462 If the output is not going to a terminal, it is printed as-is.
1463 Otherwise, the result depends on which directive is in use.  The
1464 directives %D, %F, %g, %G, %H, %Y, and %y expand to values which are
1465 not under control of files' owners, and so are printed as-is.  The
1466 directives %a, %b, %c, %d, %i, %k, %m, %M, %n, %s, %t, %u and %U have
1467 values which are under the control of files' owners but which cannot
1468 be used to send arbitrary data to the terminal, and so these are
1469 printed as-is.  The directives %f, %h, %l, %p and %P are quoted.  This
1470 quoting is performed in the same way as for GNU
1471 .BR ls .
1472 This is not the same quoting mechanism as the one used for
1473 .B \-ls
1474 and
1475 .BR \-fls .
1476 If you are able to decide what format to use for the output of
1477 .B find
1478 then it is normally better to use `\e0' as a terminator
1479 than to use newline, as file names can contain white space and newline
1480 characters.  The setting of the `LC_CTYPE' environment
1481 variable is used to determine which characters need to be quoted.
1482
1483 .IP "\-print, \-fprint"
1484 Quoting is handled in the same way as for
1485 .B \-printf
1486 and
1487 .BR \-fprintf .
1488 If you are using
1489 .B find
1490 in a script or in a situation where the matched files might have
1491 arbitrary names, you should consider using
1492 .B \-print0
1493 instead of
1494 .BR \-print .
1495 .P
1496 The
1497 .B \-ok
1498 and
1499 .B \-okdir
1500 actions print the current filename as-is.  This may change in a future release.
1501
1502 .SS OPERATORS
1503 .P
1504 Listed in order of decreasing precedence:
1505
1506 .IP "( \fIexpr\fR )"
1507 Force precedence.  Since parentheses are special to the shell, you
1508 will normally need to quote them.  Many of the examples in this manual
1509 page use backslashes for this purpose: `\e(...\e)' instead of `(...)'.
1510
1511 .IP "! \fIexpr\fR"
1512 True if \fIexpr\fR is false.  This character will also usually need
1513 protection from interpretation by the shell.
1514
1515 .IP "\-not \fIexpr\fR"
1516 Same as ! \fIexpr\fR, but not POSIX compliant.
1517
1518 .IP "\fIexpr1 expr2\fR"
1519 Two expressions in a row are taken to be joined with an
1520 implied "and"; \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
1521
1522 .IP "\fIexpr1\fR \-a \fIexpr2\fR"
1523 Same as \fIexpr1 expr2\fR.
1524
1525 .IP "\fIexpr1\fR \-and \fIexpr2\fR"
1526 Same as \fIexpr1 expr2\fR, but not POSIX compliant.
1527
1528 .IP "\fIexpr1\fR \-o \fIexpr2\fR"
1529 Or; \fIexpr2\fR is not evaluated if \fIexpr1\fR is true.
1530
1531 .IP "\fIexpr1\fR \-or \fIexpr2\fR"
1532 Same as \fIexpr1\fR
1533 .B \-o
1534 \fIexpr2\fR, but not POSIX compliant.
1535
1536 .IP "\fIexpr1\fR , \fIexpr2\fR"
1537 List; both \fIexpr1\fR and \fIexpr2\fR are always evaluated.  The
1538 value of \fIexpr1\fR is discarded; the value of the list is the value
1539 of \fIexpr2\fR. The comma operator can be useful for searching for
1540 several different types of thing, but traversing the filesystem
1541 hierarchy only once.  The
1542 .B \-fprintf
1543 action can be used to list the various matched items into several
1544 different output files.
1545
1546
1547 .SH "STANDARDS CONFORMANCE"
1548 For closest compliance to the POSIX standard, you should set the
1549 POSIXLY_CORRECT environment variable.  The following options are
1550 specified in the POSIX standard (IEEE Std 1003.1, 2003 Edition):
1551
1552 .IP \fB\-H\fR
1553 This option is supported.
1554
1555 .IP \fB\-L\fR
1556 This option is supported.
1557
1558 .IP \fB\-name\fR
1559 This option is supported, but POSIX conformance depends on the
1560 POSIX conformance of the system's
1561 .BR fnmatch (3)
1562 library function.  As of findutils-4.2.2, shell metacharacters
1563 (`*', `?' or `[]' for example) will match a leading `.', because
1564 IEEE PASC interpretation 126 requires this.   This is a change from
1565 previous versions of findutils.
1566
1567 .IP \fB\-type\fR
1568 Supported.   POSIX specifies `b', `c', `d', `l', `p', `f' and `s'.
1569 GNU find also supports `D', representing a Door, where the OS provides these.
1570
1571 .IP \fB\-ok\fR
1572 Supported.
1573 Interpretation of the response is according to the "yes" and "no"
1574 patterns selected by setting the `LC_MESSAGES' environment variable.
1575 When the `POSIXLY_CORRECT' environment variable is set, these patterns
1576 are taken system's definition of a positive (yes) or negative (no)
1577 response. See the system's
1578 documentation for \fBnl_langinfo\fP(3), in particular YESEXPR and
1579 NOEXPR.    When `POSIXLY_CORRECT' is not set, the patterns are instead
1580 taken from
1581 .BR find 's
1582 own message catalogue.
1583
1584 .IP \fB\-newer\fR
1585 Supported.  If the file specified is a symbolic link, it is always
1586 dereferenced.  This is a change from previous behaviour, which used to
1587 take the relevant time from the symbolic link; see the HISTORY section
1588 below.
1589
1590 .IP \fB\-perm\fR
1591 Supported.  If the POSIXLY_CORRECT environment variable is not set,
1592 some mode arguments (for example +a+x) which are not valid in POSIX
1593 are supported for backward-compatibility.
1594
1595 .IP "Other predicates"
1596 The predicates
1597 .BR \-atime ,
1598 .BR \-ctime ,
1599 .BR \-depth ,
1600 .BR \-group ,
1601 .BR \-links ,
1602 .BR \-mtime ,
1603 .BR \-nogroup ,
1604 .BR \-nouser ,
1605 .BR \-print ,
1606 .BR \-prune ,
1607 .BR \-size ,
1608 .BR \-user
1609 and
1610 .B \-xdev
1611 `\-atime',
1612 `\-ctime',
1613 `\-depth',
1614 `\-group',
1615 `\-links',
1616 `\-mtime',
1617 `\-nogroup',
1618 `\-nouser',
1619 `\-perm',
1620 `\-print',
1621 `\-prune',
1622 `\-size',
1623 `\-user' and
1624 `\-xdev',
1625 are all supported.
1626
1627 .P
1628 The POSIX standard specifies parentheses `(', `)', negation `!' and the
1629 `and' and `or' operators (
1630 .BR \-a ,
1631 .BR \-o ).
1632 .P
1633 All other options, predicates, expressions and so forth are extensions
1634 beyond the POSIX standard.  Many of these extensions are not unique to
1635 GNU find, however.
1636 .P
1637 The POSIX standard requires that
1638 .B find
1639 detects loops:
1640 .IP
1641 The
1642 .B find
1643 utility shall detect infinite loops; that is, entering a
1644 previously visited directory that is an ancestor of the last file
1645 encountered. When it detects an infinite loop, find shall write a
1646 diagnostic message to standard error and shall either recover its
1647 position in the hierarchy or terminate.
1648 .P
1649 GNU
1650 .B find
1651 complies with these requirements.  The link count of
1652 directories which contain entries which are hard links to an ancestor
1653 will often be lower than they otherwise should be.  This can mean that
1654 GNU find will sometimes optimise away the visiting of a subdirectory
1655 which is actually a link to an ancestor.  Since
1656 .B find
1657 does not actually enter such a subdirectory, it is allowed to avoid
1658 emitting a diagnostic message.  Although this behaviour may be
1659 somewhat confusing, it is unlikely that anybody actually depends on
1660 this behaviour.  If the leaf optimisation has been turned off with
1661 .BR \-noleaf ,
1662 the directory entry will always be examined and the diagnostic message
1663 will be issued where it is appropriate.  Symbolic links cannot be used
1664 to create filesystem cycles as such, but if the
1665 .B \-L
1666 option or the
1667 .B \-follow
1668 option is in use, a diagnostic message is issued when
1669 .B find
1670 encounters a loop of symbolic links.  As with loops containing hard
1671 links, the leaf optimisation will often mean that
1672 .B find
1673 knows that it doesn't need to call
1674 .I stat()
1675 or
1676 .I chdir()
1677 on the symbolic link, so this diagnostic is frequently not necessary.
1678 .P
1679 The
1680 .B \-d
1681 option is supported for compatibility with various BSD systems,
1682 but you should use the POSIX-compliant option
1683 .B \-depth
1684 instead.
1685 .P
1686 The POSIXLY_CORRECT environment variable does not affect the behaviour
1687 of the
1688 .B \-regex
1689 or
1690 .B \-iregex
1691 tests because those tests aren't specified in the POSIX standard.
1692 .SH "ENVIRONMENT VARIABLES"
1693
1694 .IP LANG
1695 Provides a default value for the internationalization variables that
1696 are unset or null.
1697
1698 .IP LC_ALL
1699 If set to a non-empty string value, override the values of all the
1700 other internationalization variables.
1701
1702 .IP LC_COLLATE
1703 The POSIX standard specifies that this variable affects the pattern
1704 matching to be used for the
1705 .B \-name
1706 option.   GNU find uses the
1707 .BR fnmatch (3)
1708 library function, and so support for `LC_COLLATE' depends on the
1709 system library.    This variable also affects the interpretation of
1710 the response to
1711 .BR \-ok;
1712 while the `LC_MESSAGES' variable selects the actual pattern used to
1713 interpret the response to
1714 .BR \-ok ,
1715 the interpretation of any bracket expressions in the pattern will be
1716 affected by `LC_COLLATE'.
1717
1718 .IP LC_CTYPE
1719 This variable affects the treatment of character classes used in
1720 regular expressions and also with
1721 the
1722 .B \-name
1723 test, if the system's
1724 .BR fnmatch (3)
1725 library function supports this.  This variable also affects the
1726 interpretation of any character classes in the regular expressions
1727 used to interpret the response to the prompt issued by
1728 .BR \-ok .
1729 The `LC_CTYPE' environment variable will
1730 also affect which characters are considered to be unprintable when
1731 filenames are printed; see the section UNUSUAL FILENAMES.
1732
1733 .IP LC_MESSAGES
1734 Determines the locale to be used for internationalised messages.  If
1735 the `POSIXLY_CORRECT' environment variable is set, this also
1736 determines the interpretation of the response to the prompt made by the
1737 .BR \-ok
1738 action.
1739
1740 .IP NLSPATH
1741 Determines the location of the internationalisation message catalogues.
1742
1743 .IP PATH
1744 Affects the directories which are searched to find the executables
1745 invoked by
1746 .BR \-exec ,
1747 .BR \-execdir ,
1748 .B \-ok
1749 and
1750 .BR \-okdir .
1751
1752 .IP POSIXLY_CORRECT
1753 Determines the block size used by
1754 .B \-ls
1755 and
1756 .BR \-fls .
1757 If
1758 .B POSIXLY_CORRECT
1759 is set, blocks are units of 512 bytes.  Otherwise they are units of 1024 bytes.
1760 .IP
1761 Setting this variable also turns off
1762 warning messages (that is, implies
1763 .BR \-nowarn )
1764 by default, because POSIX requires that apart from
1765 the output for
1766 .BR \-ok ,
1767 all messages printed on stderr are diagnostics and must result in a
1768 non-zero exit status.
1769 .IP
1770 When POSIXLY_CORRECT is not set,
1771 .B \-perm
1772 +zzz
1773 is treated just like
1774 .B \-perm
1775 /zzz
1776 if
1777 +zzz is not a valid symbolic mode.  When POSIXLY_CORRECT is set, such
1778 constructs are treated as an error.
1779 .IP
1780 When POSIXLY_CORRECT is set, the response to the prompt made by the
1781 .B \-ok
1782 action is interpreted according to the system's message catalogue, as
1783 opposed to according to
1784 .BR find 's
1785 own message translations.
1786
1787 .IP TZ
1788 Affects the time zone used for some of the time-related format
1789 directives of
1790 .B \-printf
1791 and
1792 .BR \-fprintf .
1793 .SH "EXAMPLES"
1794 .nf
1795 .B find /tmp \-name core \-type f \-print | xargs /bin/rm \-f
1796
1797 .fi
1798 Find files named
1799 .B core
1800 in or below the directory
1801 .B /tmp
1802 and delete them.  Note that this will work incorrectly if there are
1803 any filenames containing newlines, single or double quotes, or spaces.
1804 .P
1805 .B find /tmp \-name core \-type f \-print0 | xargs \-0 /bin/rm \-f
1806
1807 .fi
1808 Find files named
1809 .B core
1810 in or below the directory
1811 .B /tmp
1812 and delete them, processing filenames in such a way that file or
1813 directory names containing single or double quotes, spaces or newlines
1814 are correctly handled.  The
1815 .B \-name
1816 test comes before the
1817 .B \-type
1818 test in order to avoid having to call
1819 .B stat(2)
1820 on every file.
1821
1822 .P
1823 .nf
1824 .B find . \-type f \-exec file \(aq{}\(aq \e\;
1825
1826 .fi
1827 Runs `file' on every file in or below the current directory.  Notice
1828 that the braces are enclosed in single quote marks to protect them
1829 from interpretation as shell script punctuation.  The semicolon is
1830 similarly protected by the use of a backslash, though single quotes
1831 could have been used in that case also.
1832
1833 .P
1834 .nf
1835 .B find / \e( \-perm \-4000 \-fprintf /root/suid.txt \(aq%#m %u %p\en\(aq \e) , \e
1836 .B  \e( \-size +100M \-fprintf /root/big.txt  \(aq%\-10s %p\en\(aq \e)
1837
1838 .fi
1839 Traverse the filesystem just once, listing setuid files and
1840 directories into
1841 .B /root/suid.txt
1842 and large files into
1843 .BR /root/big.txt .
1844
1845 .P
1846 .nf
1847 .B find $HOME  \-mtime 0
1848
1849 .fi
1850 Search for files in your home directory which have been modified in
1851 the last twenty-four hours.  This command works this way because the
1852 time since each file was last modified is divided by 24 hours and any
1853 remainder is discarded.  That means that to match
1854 .B \-mtime
1855 .BR 0 ,
1856 a file will have to have a modification in the past which is less than
1857 24 hours ago.
1858
1859 .P
1860 .nf
1861 .B find /sbin /usr/sbin -executable \e! -readable \-print
1862
1863 .fi
1864 Search for files which are executable but not readable.
1865
1866 .P
1867 .nf
1868 .B find . \-perm 664
1869
1870 .fi
1871 Search for files which have read and write permission for their owner,
1872 and group, but which other users can read but not write to.  Files
1873 which meet these criteria but have other permissions bits set (for
1874 example if someone can execute the file) will not be matched.
1875
1876 .P
1877 .nf
1878 .B find . \-perm \-664
1879
1880 .fi
1881 Search for files which have read and write permission for their owner
1882 and group, and which other users can read, without regard to the
1883 presence of any extra permission bits (for example the executable
1884 bit).  This will match a file which has mode 0777, for example.
1885
1886 .P
1887 .nf
1888 .B find . \-perm /222
1889
1890 .fi
1891 Search for files which are writable by somebody (their owner, or
1892 their group, or anybody else).
1893
1894 .P
1895 .nf
1896 .B find . \-perm /220
1897 .B find . \-perm /u+w,g+w
1898 .B find . \-perm /u=w,g=w
1899
1900 .fi
1901 All three of these commands do the same thing, but the first one uses
1902 the octal representation of the file mode, and the other two use the
1903 symbolic form.  These commands all search for files which are
1904 writable by either their owner or their group.  The files don't have
1905 to be writable by both the owner and group to be matched; either will
1906 do.
1907
1908 .P
1909 .nf
1910 .B find . \-perm \-220
1911 .B find . \-perm \-g+w,u+w
1912
1913 .fi
1914 Both these commands do the same thing; search for files which are
1915 writable by both their owner and their group.
1916
1917 .P
1918 .nf
1919 .B find . \-perm \-444 \-perm /222 ! \-perm /111
1920 .B find . \-perm \-a+r \-perm /a+w ! \-perm /a+x
1921
1922 .fi
1923 These two commands both search for files that are readable for
1924 everybody (
1925 .B \-perm \-444
1926 or
1927 .BR "\-perm \-a+r" ),
1928 have at least one write bit
1929 set (
1930 .B \-perm /222
1931 or
1932 .BR "\-perm /a+w" )
1933 but are not executable for anybody (
1934 .B ! \-perm /111
1935 and
1936 .B ! \-perm /a+x
1937 respectively).
1938
1939 .P
1940 .nf
1941 .B cd /source-dir
1942 .B find . \-name .snapshot \-prune \-o \e( \e! \-name "*~" \-print0 \e)|
1943 .B cpio \-pmd0   /dest-dir
1944
1945 .fi
1946 This command copies the contents of
1947 .B /source-dir
1948 to
1949 .BR /dest-dir ,
1950 but omits files and directories named
1951 .B .snapshot
1952 (and anything in them).  It also omits files or directories whose name
1953 ends in
1954 .BR ~ ,
1955 but not their contents.  The construct
1956 .B \-prune \-o \e( ... \-print0 \e)
1957 is quite common.  The idea here is that the expression before
1958 .B \-prune
1959 matches things which are to be pruned.  However, the
1960 .B \-prune
1961 action itself returns true, so the following
1962 .B \-o
1963 ensures that the right hand side is evaluated only for those
1964 directories which didn't get pruned (the contents of the pruned
1965 directories are not even visited, so their contents are irrelevant).
1966 The expression on the right hand side of the
1967 .B \-o
1968 is in parentheses only for clarity.  It emphasises that the
1969 .B \-print0
1970 action takes place only for things that didn't have
1971 .B \-prune
1972 applied to them.  Because the default `and' condition between tests
1973 binds more tightly than
1974 .BR \-o ,
1975 this is the default anyway, but the parentheses help to show
1976 what is going on.
1977
1978 .P
1979 .nf
1980 .B find repo/ -exec test -d {}/.svn \e; -or \e
1981 .B -exec test -d {}/.git \e; -or -exec test  -d {}/CVS \e; \e
1982 .B -print -prune
1983 .fi
1984
1985 Given the following directory of projects and their associated SCM
1986 administrative directories, perform an efficient search for the
1987 projects' roots:
1988
1989 .nf
1990 .B repo/project1/CVS
1991 .B repo/gnu/project2/.svn
1992 .B repo/gnu/project3/.svn
1993 .B repo/gnu/project3/src/.svn
1994 .B repo/project4/.git
1995
1996 .fi
1997 In this example,
1998 .B \-prune
1999 prevents unnecessary descent into directories that have already been
2000 discovered (for example we do not search project3/src because we
2001 already found project3/.svn), but ensures sibling directories
2002 (project2 and project3) are found.
2003
2004 .SH EXIT STATUS
2005 .PP
2006 .B find
2007 exits with status 0 if all files are processed successfully, greater
2008 than 0 if errors occur.   This is deliberately a very broad
2009 description, but if the return value is non-zero, you should not rely
2010 on the correctness of the results of
2011 .BR find .
2012
2013 .SH "SEE ALSO"
2014 \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1), \fBxargs\fP(1),
2015 \fBchmod\fP(1), \fBfnmatch\fP(3), \fBregex\fP(7), \fBstat\fP(2),
2016 \fBlstat\fP(2), \fBls\fP(1), \fBprintf\fP(3), \fBstrftime\fP(3),
2017 \fBctime\fP(3), \fBFinding Files\fP (on-line in Info, or printed).
2018 .SH "HISTORY"
2019 As of findutils-4.2.2, shell metacharacters (`*', `?' or `[]' for
2020 example) used in filename patterns will match a leading `.', because
2021 IEEE POSIX interpretation 126 requires this.
2022 .P
2023 The syntax
2024 \.B \-perm +MODE
2025 was deprecated in findutils-4.2.21, in favour of
2026 \.B \-perm
2027 .BR /MODE .
2028 As of findutils-4.3.3,
2029 .B \-perm /000
2030 now matches all files instead of none.
2031 .P
2032 Nanosecond-resolution
2033 timestamps were implemented in findutils-4.3.3.
2034 .P
2035 As of findutils-4.3.11, the
2036 .B \-delete
2037 action sets
2038 .BR find 's
2039 exit status to a nonzero value when it fails.
2040 However,
2041 .B find
2042 will not exit immediately.  Previously,
2043 .BR find 's
2044 exit status was unaffected by the failure of
2045 .BR \-delete .
2046 .TS
2047 l l l .
2048 Feature Added in        Also occurs in
2049 \-newerXY       4.3.3   BSD
2050 \-D     4.3.1
2051 \-O     4.3.1
2052 \-readable      4.3.0
2053 \-writable      4.3.0
2054 \-executable    4.3.0
2055 \-regextype     4.2.24
2056 \-exec ... +    4.2.12  POSIX
2057 \-execdir       4.2.12  BSD
2058 \-okdir 4.2.12
2059 \-samefile      4.2.11
2060 \-H     4.2.5   POSIX
2061 \-L     4.2.5   POSIX
2062 \-P     4.2.5   BSD
2063 \-delete        4.2.3
2064 \-quit  4.2.3
2065 \-d     4.2.3   BSD
2066 \-wholename     4.2.0
2067 \-iwholename    4.2.0
2068 \-ignore_readdir_race   4.2.0
2069 \-fls   4.0
2070 \-ilname        3.8
2071 \-iname 3.8
2072 \-ipath 3.8
2073 \-iregex        3.8
2074 .TE
2075 .SH "NON-BUGS"
2076 .nf
2077 .B $ find . \-name *.c \-print
2078 find: paths must precede expression
2079 Usage: find [\-H] [\-L] [\-P] [\-Olevel] [\-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
2080 .fi
2081 .P
2082 This happens because
2083 .I *.c
2084 has been expanded by the shell
2085 resulting in
2086 .B find
2087 actually receiving a command line like this:
2088 .nf
2089
2090 .B find . \-name bigram.c code.c frcode.c locate.c \-print
2091
2092 .fi
2093 That command is of course not going to work.  Instead of doing things
2094 this way, you should enclose the pattern in quotes or escape the wildcard:
2095 .nf
2096 .B $ find . \-name \(aq*.c\(aq \-print
2097 .B $ find . \-name \e*.c \-print
2098 .fi
2099
2100 .SH "BUGS"
2101 .P
2102 There are security problems inherent in the behaviour that the POSIX
2103 standard specifies for
2104 .BR find ,
2105 which therefore cannot be fixed.  For example, the
2106 .B \-exec
2107 action is
2108 inherently insecure, and
2109 .B \-execdir
2110 should be used instead.
2111 Please see \fBFinding Files\fP for more information.
2112 .P
2113 The environment variable
2114 .B  LC_COLLATE
2115 has no effect on the
2116 .B \-ok
2117 action.
2118 .P
2119 The best way to report a bug is to use the form at
2120 http://savannah.gnu.org/bugs/?group=findutils.
2121 The reason for this is that you will then be able to track progress in
2122 fixing the problem.   Other comments about \fBfind\fP(1) and about
2123 the findutils package in general can be sent to the
2124 .I bug\-findutils
2125 mailing list.  To join the list, send email to
2126 .IR bug\-findutils\-request@gnu.org .