cvsimport
[findutils.git] / find / find.1
blobd7f40cf9087ec60de2fc217f3fa0f951ea754a2d
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 seach directories that are writable by other users), you
25 should read the "Security Considerations" chapter of the findutils
26 documentation, which is called \fBFinding Files\fP and comes with
27 findutils.   That document also includes a lot more detail 
28 and discussion than this manual page, so you may find it a more useful 
29 source of information.
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.  
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.
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).
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.
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.
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 .
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).
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
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.
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.
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 .IP 3
257 At this optimisation level, the full cost-based query optimiser is
258 enabled.  The order of tests is modified so that cheap (i.e. fast)
259 tests are performed first and more expensive ones are performed later,
260 if necessary.  Within each cost band, predicates are evaluated earlier
261 or later according to whether they are likely to succeed or not.  For 
262 .BR \-o ,
263 predicates which are likely to succeed are evaluated earlier, and for 
264 .BR \-a ,
265 predicates which are likely to fail are evaluated earlier.
268 The cost-based optimiser has a fixed idea of how likely any given test
269 is to succeed.  In some cases the probability takes account of the
270 specific nature of the test (for example, 
271 .B \-type f
272 is assumed to be more likely to succeed than 
273 .BR "\-type c" ).
274 The cost-based optimiser is currently being evaluated.   If it does
275 not actually improve the performance of 
276 .BR find ,
277 it will be removed again.  Conversely, optimisations that prove to be
278 reliable, robust and effective may be enabled at lower optimisation
279 levels over time.  However, the default behaviour (i.e. optimisation
280 level 1) will not be changed in the 4.3.x release series.  The
281 findutils test suite runs all the tests on 
282 .B find
283 at each optimisation level and ensures that the result is the same.
285 .SH EXPRESSIONS
286 The expression is made up of options (which affect overall operation
287 rather than the processing of a specific file, and always return
288 true), tests (which return a true or false value), and actions (which
289 have side effects and return a true or false value), all separated by
290 operators.  
291 .B \-and
292 is assumed where the operator is omitted.  
294 If the expression contains no actions other than 
295 .BR \-prune , 
296 .B \-print
298 performed on all files for which the expression is true.
300 .SS OPTIONS
302 All options always return true.  Except for 
303 .BR \-daystart , 
304 .B \-follow
306 .BR \-regextype , 
307 the options affect all tests, including tests specified
308 before the option.  This is because the options are processed when the
309 command line is parsed, while the tests don't do anything until files
310 are examined.  The 
311 .BR \-daystart , 
312 .B \-follow 
313 and 
314 .B \-regextype
315 options are different in this respect, and have an effect only on tests which
316 appear later in the command line.  Therefore, for clarity, it is best
317 to place them at the beginning of the expression.  A warning is issued
318 if you don't do this.
320 .IP \-d
321 A synonym for \-depth, for compatibility with FreeBSD, NetBSD, MacOS X and OpenBSD.
323 .IP \-daystart
324 Measure times (for 
325 .BR \-amin , 
326 .BR \-atime , 
327 .BR \-cmin , 
328 .BR \-ctime , 
329 .BR \-mmin , 
330 and 
331 .BR \-mtime )
332 from the beginning of today rather than from 24 hours ago.  This
333 option only affects tests which appear later on the command line.
335 .IP \-depth
336 Process each directory's contents before the directory itself.  The
337 \-delete action also implies 
338 .BR \-depth .
340 .IP \-follow
341 Deprecated; use the 
342 .B \-L 
343 option instead.  Dereference symbolic links.
344 Implies 
345 .BR \-noleaf .  
346 The 
347 .B \-follow 
348 option affects only those tests which
349 appear after it on the command line.  Unless the 
350 .B \-H
351 or 
352 .B \-L 
353 option has
354 been specified, the position of the 
355 .B \-follow 
356 option changes the behaviour of the 
357 .B \-newer 
358 predicate; any files listed as the argument
359 of 
360 .B \-newer
361 will be dereferenced if they are symbolic links.  The same
362 consideration applies to 
363 .BR \-newerXY , 
364 .B \-anewer 
365 and 
366 .BR \-cnewer .  
367 Similarly, the 
368 .B \-type 
369 predicate will always match against the type of the file
370 that a symbolic link points to rather than the link itself.  Using
371 .B \-follow 
372 causes the 
373 .B \-lname and
374 .B \-ilname 
375 predicates always to return false.
377 .IP "\-help, \-\-help"
378 Print a summary of the command-line usage of
379 .B find
380 and exit.
382 .IP \-ignore_readdir_race
383 Normally, \fBfind\fR will emit an error message when it fails to stat a file.
384 If you give this option and a file is deleted between the time \fBfind\fR 
385 reads the name of the file from the directory and the time it tries to stat 
386 the file, no error message will be issued.    This also applies to files
387 or directories whose names are given on the command line.  This option takes
388 effect at the time the command line is read, which means that you cannot search
389 one part of the filesystem with this option on and part of it with this option
390 off (if you need to do that, you will need to issue two \fBfind\fR commands
391 instead, one with the option and one without it).
393 .IP "\-maxdepth \fIlevels\fR"
394 Descend at most \fIlevels\fR (a non-negative integer) levels of
395 directories below the command line arguments.  
396 .B \-maxdepth 0
397  means only apply the tests and actions to the command line arguments.
399 .IP "\-mindepth \fIlevels\fR"
400 Do not apply any tests or actions at levels less than \fIlevels\fR (a
401 non-negative integer).  
402 .B \-mindepth 1
403 means process all files except the command line arguments.
405 .IP \-mount
406 Don't descend directories on other filesystems.  An alternate name for
407 .BR \-xdev , 
408 for compatibility with some other versions of
409 .BR find .
411 .IP \-noignore_readdir_race
412 Turns off the effect of 
413 .BR \-ignore_readdir_race . 
415 .IP "\-noleaf"
416 Do not optimize by assuming that directories contain 2 fewer
417 subdirectories than their hard link count.  This option is needed when
418 searching filesystems that do not follow the Unix directory-link
419 convention, such as CD-ROM or MS-DOS filesystems or AFS volume mount
420 points.  Each directory on a normal Unix filesystem has at least 2
421 hard links: its name and its `.'  entry.  Additionally, its
422 subdirectories (if any) each have a `..'  entry linked to that
423 directory.  When
424 .B find
425 is examining a directory, after it has statted 2 fewer subdirectories
426 than the directory's link count, it knows that the rest of the entries
427 in the directory are non-directories (`leaf' files in the directory
428 tree).  If only the files' names need to be examined, there is no need
429 to stat them; this gives a significant increase in search speed.
431 .IP "\-regextype \fItype\fR"
432 Changes the regular expression syntax understood by 
433 .B \-regex
434 and 
435 .B \-iregex
436 tests which occur later on the command line.  Currently-implemented
437 types are emacs (this is the default), posix-awk, posix-basic,
438 posix-egrep and posix-extended.
440 .IP "\-version, \-\-version"
441 Print the \fBfind\fR version number and exit.
443 .IP "\-warn, \-nowarn"
444 Turn warning messages on or off.  These warnings apply only to the
445 command line usage, not to any conditions that 
446 .B find 
447 might encounter when it searches directories.  The default behaviour
448 corresponds to 
449 .B \-warn 
450 if standard input is a tty, and to 
451 .B \-nowarn
452 otherwise.
454 .IP \-xdev
455 Don't descend directories on other filesystems.
457 .SS TESTS
458 Some tests, for example
459 .B \-newerXY
460 and 
461 .BR -samefile ,
462 allow comparison between the file currently being examined and some
463 reference file specified on the command line.  When these tests are
464 used, the interpretation of the reference file is determined by the 
465 options 
466 .BR \-H , 
467 .B \-L 
468 and 
469 .B \-P
470 and any previous 
471 .BR \-follow ,
472 but the reference file is only examined once, at the time the command
473 line is parsed.  If the reference file cannot be examined (for
474 example, the 
475 .BR stat (2) 
476 system call fails for it), an error message is issued, and 
477 .B find
478 exits with a nonzero status.
480 Numeric arguments can be specified as
481 .IP \fI+n\fP
482 for greater than
483 .IR n ,
484 .IP \fI\-n\fP
485 for less than
486 .IR n ,
487 .IP \fIn\fP
488 for exactly
489 .IR n .
492 .IP "\-amin \fIn\fR"
493 File was last accessed \fIn\fR minutes ago.
495 .IP "\-anewer \fIfile\fR"
496 File was last accessed more recently than \fIfile\fR was modified.  If
497 \fIfile\fR is a symbolic link and the 
498 .B \-H 
499 option or the 
500 .B \-L 
501 option is in effect, the access time of the file it points to is
502 always used.
504 .IP "\-atime \fIn\fR"
505 File was last accessed \fIn\fR*24 hours ago.  
506 When find figures out how many 24-hour periods ago the file 
507 was last accessed, any fractional part is ignored, so to match 
508 .B \-atime 
509 .BR +1 ,
510 a file has to have been accessed at least 
511 .I two
512 days ago.
514 .IP "\-cmin \fIn\fR"
515 File's status was last changed \fIn\fR minutes ago.
517 .IP "\-cnewer \fIfile\fR"
518 File's status was last changed more recently than \fIfile\fR was
519 modified.  If \fIfile\fR is a symbolic link and the 
520 .B \-H 
521 option or the
522 .B \-L 
523 option is in effect, the status-change time of the file it points
524 to is always used.
526 .IP "\-ctime \fIn\fR"
527 File's status was last changed \fIn\fR*24 hours ago.
528 See the comments for 
529 .B \-atime 
530 to understand how rounding affects the interpretation of file status
531 change times.
533 .IP \-empty
534 File is empty and is either a regular file or a directory.
536 .IP \-executable
537 Matches files which are executable and directories which are
538 searchable (in a file name resolution sense).  This takes into account
539 access control lists and other permissions artefacts which the
540 .B \-perm 
541 test ignores.  This test makes use of the
542 .BR access (2)
543 system call, and so can be fooled by NFS servers which do UID
544 mapping (or root-squashing), since many systems implement 
545 .BR access (2) 
546 in the client's kernel and so cannot make use of the UID mapping
547 information held on the server.  Because this test is based only on
548 the result of the 
549 .BR access (2)
550 system call, there is no guarantee that a file for which this test
551 succeeds can actually be executed.
553 .IP \-false
554 Always false.
556 .IP "\-fstype \fItype\fR"
557 File is on a filesystem of type \fItype\fR.  The valid filesystem
558 types vary among different versions of Unix; an incomplete list of
559 filesystem types that are accepted on some version of Unix or another
560 is: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K.  You can use 
561 .B \-printf
562 with the %F directive to see the types of your filesystems.
564 .IP "\-gid \fIn\fR"
565 File's numeric group ID is \fIn\fR.
567 .IP "\-group \fIgname\fR"
568 File belongs to group \fIgname\fR (numeric group ID allowed).
570 .IP "\-ilname \fIpattern\fR"
571 Like 
572 .BR \-lname , 
573 but the match is case insensitive.
574 If the 
575 .B \-L 
576 option or the 
577 .B \-follow 
578 option is in effect, this test returns false unless the symbolic link
579 is broken. 
581 .IP "\-iname \fIpattern\fR"
582 Like 
583 .BR \-name , 
584 but the match is case insensitive.  For example, the
585 patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo',
586 `fOo', etc.   In these patterns, unlike filename expansion by the
587 shell, an initial '.' can be matched by `*'.  That is, 
588 .B find \-name *bar 
589 will match the file `.foobar'.   Please note that you should quote
590 patterns as a matter of course, otherwise the shell will expand any
591 wildcard characters in them.
593 .IP "\-inum \fIn\fR"
594 File has inode number \fIn\fR.  It is normally easier to use the 
595 .B \-samefile
596 test instead.
598 .IP "\-ipath \fIpattern\fR"
599 Behaves in the same way as 
600 .BR \-iwholename .  
601 This option is deprecated, so please do not use it.
603 .IP "\-iregex \fIpattern\fR"
604 Like 
605 .BR \-regex , 
606 but the match is case insensitive.
608 .IP "\-iwholename \fIpattern\fR"
609 Like 
610 .BR \-wholename , 
611 but the match is case insensitive.
613 .IP "\-links \fIn\fR"
614 File has \fIn\fR links.
616 .IP "\-lname \fIpattern\fR"
617 File is a symbolic link whose contents match shell pattern
618 \fIpattern\fR.  The metacharacters do not treat `/' or `.' specially.
619 If the 
620 .B \-L 
621 option or the 
622 .B \-follow 
623 option is in effect, this test returns false unless the symbolic link
624 is broken. 
626 .IP "\-mmin \fIn\fR"
627 File's data was last modified \fIn\fR minutes ago.
629 .IP "\-mtime \fIn\fR"
630 File's data was last modified \fIn\fR*24 hours ago.
631 See the comments for 
632 .B \-atime 
633 to understand how rounding affects the interpretation of file
634 modification times.
636 .IP "\-name \fIpattern\fR"
637 Base of file name (the path with the leading directories removed)
638 matches shell pattern \fIpattern\fR.  The metacharacters (`*', `?',
639 and `[]') match a `.' at the start of the base name (this is a change
640 in findutils-4.2.2; see section STANDARDS CONFORMANCE below).  To ignore a
641 directory and the files under it, use 
642 .BR \-prune ; 
643 see an example in the
644 description of 
645 .BR \-path .  
646 Braces are not recognised as being
647 special, despite the fact that some shells including Bash imbue braces
648 with a special meaning in shell patterns.  The filename matching is
649 performed with the use of the
650 .BR fnmatch (3) 
651 library function.   Don't forget to enclose the pattern in quotes 
652 in order to protect it from expansion by the shell.
654 .IP "\-newer \fIfile\fR"
655 File was modified more recently than \fIfile\fR.  If \fIfile\fR is a
656 symbolic link and the 
657 .B \-H 
658 option or the 
659 .B \-L 
660 option is in effect, the
661 modification time of the file it points to is always used.
663 .IP "\-newerXY \fIreference\fR"
664 Compares the timestamp of the current file with \fIreference\fR.  
665 The 
666 .I reference 
667 argument is normally the name of a file (and one of its timestamps is
668 used for the comparison) but it may also be a string describing an
669 absolute time.  
670 .I X 
671 and 
672 .I Y 
673 are placeholders for other letters, and these letters select which
674 time belonging to 
675 how 
676 .I reference 
677 is used for the comparison.
683 llw(2i).
684 a       The access time of the file \fIreference\fR 
685 B       The birth time of the file \fIreference\fR
686 c       The inode status change time of \fIreference\fR
687 m       The modification time of the file \fIreference\fR
688 t       \fIreference\fR is interpreted directly as a time
691 Some combinations are invalid; for example, it is invalid for
692 .I X 
693 to be 
694 .IR t .
695 Some combinations are not implemented on all systems; for example 
696 .I B
697 is not supported on all systems.  If an invalid or unsupported
698 combination of 
699 .I XY 
700 is specified, a fatal error results.  Time specifications are
701 interpreted as for the argument to the 
702 .B \-d 
703 option of GNU 
704 .BR date .
705 If you try to use the birth time of a reference file, and the birth
706 time cannot be determined, a fatal error message results.  If you
707 specify a test which refers to the birth time of files being examined,
708 this test will fail for any files where the birth time is unknown.
710 .IP \-nogroup
711 No group corresponds to file's numeric group ID.
713 .IP \-nouser
714 No user corresponds to file's numeric user ID.
716 .IP "\-path \fIpattern\fR"
717 File name matches shell pattern \fIpattern\fR.  The metacharacters do
718 not treat `/' or `.' specially; so, for example,
720 .in +1i
721 find . \-path "./sr*sc"
723 .in -1i
724 will print an entry for a directory called `./src/misc' (if one
725 exists).  To ignore a whole directory tree, use 
726 .B \-prune
727 rather than
728 checking every file in the tree.  For example, to skip the
729 directory `src/emacs' and all files and directories under it, and
730 print the names of the other files found, do something like this:
732 .in +1i
733 find . \-path ./src/emacs \-prune \-o \-print
735 .in -1i
736 Note that the pattern match test applies to the whole file name,
737 starting from one of the start points named on the command line.  It
738 would only make sense to use an absolute path name here if the
739 relevant start point is also an absolute path.  This means that this
740 command will never match anything:
742 .in +1i
743 find bar \-path /foo/bar/myfile \-print
745 .in -1i
746 The predicate 
747 .B \-path
748 is also supported by HP-UX
749 .B find 
750 and will be in a forthcoming version of the POSIX standard.
752 .IP "\-perm \fImode\fR"
753 File's permission bits are exactly \fImode\fR (octal or symbolic).
754 Since an exact match is required, if you want to use this form for
755 symbolic modes, you may have to specify a rather complex mode string.
756 For example 
757 .B \-perm g=w
758 will only match files which have mode 0020
759 (that is, ones for which group write permission is the only permission
760 set).  It is more likely that you will want to use the `/' or `-'
761 forms, for example 
762 .BR "\-perm \-g=w" ,
763 which matches any file with group write permission.  See the
764 .B EXAMPLES 
765 section for some illustrative examples.
767 .IP "\-perm \-\fImode\fR"
768 All of the permission bits \fImode\fR are set for the file.
769 Symbolic modes are accepted in this form, and this is usually the way
770 in which would want to use them.  You must specify `u', `g' or `o' if
771 you use a symbolic mode.   See the 
772 .B EXAMPLES 
773 section for some illustrative examples.
775 .IP "\-perm /\fImode\fR"
776 Any of the permission bits \fImode\fR are set for the file.  Symbolic
777 modes are accepted in this form.  You must specify `u', `g' or `o' if
778 you use a symbolic mode.  See the
779 .B EXAMPLES 
780 section for some illustrative examples.  If no permission bits in 
781 .I mode
782 are set, this test currently matches no files.  However, it will soon
783 be changed to match any file (the idea is to be more consistent with
784 the behaviour of 
785 .B \-perm 
786 .BR \-000 ).
788 .IP "\-perm +\fImode\fR"
789 Deprecated, old way of searching for files with any of the permission
790 bits in \fImode\fR set.  You should use
791 .B \-perm \fI/mode\fR
792 instead. Trying to use the `+' syntax with symbolic modes will yield
793 surprising results.  For example, `+u+x' is a valid symbolic mode
794 (equivalent to +u,+x, i.e. 0111) and will therefore not be evaluated
796 .B \-perm +\fImode\fR
797 but instead as the exact mode specifier
798 .B \-perm \fImode\fR
799 and so it matches files with exact permissions 0111 instead of files with any
800 execute bit set.  If you found this paragraph confusing, you're not
801 alone - just use 
802 .B \-perm /\fImode\fR.
803 This form of the 
804 .B \-perm
805 test is deprecated because the POSIX specification requires the
806 interpretation of a leading `+' as being part of a symbolic mode, and
807 so we switched to using `/' instead.
809 .IP \-readable
810 Matches files which are readable.  This takes into account access
811 control lists and other permissions artefacts which the
812 .B \-perm 
813 test ignores.  This test makes use of the
814 .BR access (2)
815 system call, and so can be fooled by NFS servers which do UID
816 mapping (or root-squashing), since many systems implement 
817 .BR access (2) 
818 in the client's kernel and so cannot make use of the UID mapping
819 information held on the server.
821 .IP "\-regex \fIpattern\fR"
822 File name matches regular expression \fIpattern\fR.  This is a match
823 on the whole path, not a search.  For example, to match a file named
824 `./fubar3', you can use the regular expression `.*bar.' or `.*b.*3',
825 but not `f.*r3'.  The regular expressions understood by 
826 .B find 
827 are by default Emacs Regular Expressions, but this can be
828 changed with the 
829 .B \-regextype 
830 option.
832 .IP "\-samefile \fIname\fR"
833 File refers to the same inode as \fIname\fR.   When 
834 .B \-L 
835 is in effect, this can include symbolic links.
837 .IP "\-size \fIn\fR[cwbkMG]"
838 File uses \fIn\fP units of space.  The following suffixes 
839 can be used:
841 .IP `b' 
842 for 512-byte blocks (this is the default if no suffix is used)
843 .IP `c' 
844 for bytes
845 .IP `w' 
846 for two-byte words
847 .IP `k' 
848 for Kilobytes (units of 1024 bytes)
849 .IP `M' 
850 for Megabytes (units of 1048576 bytes)
851 .IP `G' 
852 for Gigabytes (units of 1073741824 bytes)
855 The size does not count indirect blocks, but it does count blocks in
856 sparse files that are not actually allocated.  Bear in mind that the
857 `%k' and `%b' format specifiers of 
858 .B \-printf 
859 handle sparse files
860 differently.  The `b' suffix always denotes 512-byte blocks and never
861 1 Kilobyte blocks, which is different to the behaviour of 
862 .BR \-ls .
864 .IP \-true
865 Always true.
867 .IP "\-type \fIc\fR"
868 File is of type \fIc\fR:
870 .IP b
871 block (buffered) special
872 .IP c
873 character (unbuffered) special
874 .IP d
875 directory
876 .IP p
877 named pipe (FIFO)
878 .IP f
879 regular file
880 .IP l
881 symbolic link; this is never true if the 
882 .B \-L 
883 option or the 
884 .B \-follow
885 option is in effect, unless the symbolic link is broken.  If you want
886 to search for symbolic links when 
887 .B \-L 
888 is in effect, use
889 .BR \-xtype .
890 .IP s
891 socket
892 .IP D
893 door (Solaris)
895 .IP "\-uid \fIn\fR"
896 File's numeric user ID is \fIn\fR.
898 .IP "\-used \fIn\fR"
899 File was last accessed \fIn\fR days after its status was last changed.
901 .IP "\-user \fIuname\fR"
902 File is owned by user \fIuname\fR (numeric user ID allowed).
904 .IP "\-wholename \fIpattern\fR"
905 See \-path.    This alternative is less portable than 
906 .BR \-path .
908 .IP "\-writable"
909 Matches files which are writable.  This takes into account access
910 control lists and other permissions artefacts which the
911 .B \-perm 
912 test ignores.  This test makes use of the
913 .BR access (2)
914 system call, and so can be fooled by NFS servers which do UID
915 mapping (or root-squashing), since many systems implement 
916 .BR access (2) 
917 in the client's kernel and so cannot make use of the UID mapping
918 information held on the server.
920 .IP "\-xtype \fIc\fR"
921 The same as 
922 .B \-type
923 unless the file is a symbolic link.  For symbolic
924 links: if the 
925 .B \-H 
926 or 
927 .B \-P 
928 option was specified, true if the file is a
929 link to a file of type \fIc\fR; if the 
930 .B \-L
931 option has been given, true
932 if \fIc\fR is `l'.  In other words, for symbolic links, 
933 .B \-xtype 
934 checks the type of the file that 
935 .B \-type
936 does not check.
938 .SS ACTIONS
939 .IP "\-delete\fR"
940 Delete files; true if removal succeeded.  If the removal failed, an
941 error message is issued.  
942 If 
943 .B \-delete
944 fails, 
945 .BR find 's 
946 exit status will be nonzero
947 (when it eventually exits).  
948 Use of 
949 .B \-delete 
950 automatically turns on the 
951 .B \-depth 
952 option.   
954 .BR Warnings :
955 Don't forget that the find command line is 
956 evaluated as an expression, so putting 
957 .B \-delete 
958 first will make 
959 .B find
960 try to delete everything below the starting points you specified.
961 When testing a 
962 .B find
963 command line that you later intend to use with 
964 .BR \-delete , 
965 you should explicitly specify 
966 .B \-depth 
967 in order to avoid later surprises.  Because
968 .B \-delete 
969 implies 
970 .BR \-depth , 
971 you cannot usefully use 
972 .B \-prune 
973 and 
974 .B \-delete
975 together. 
977 .IP "\-exec \fIcommand\fR ;"
978 Execute \fIcommand\fR; true if 0 status is returned.  All following
979 arguments to
980 .B find
981 are taken to be arguments to the command until an argument consisting
982 of `;' is encountered.  The string `{}' is replaced by the current
983 file name being processed everywhere it occurs in the arguments to the
984 command, not just in arguments where it is alone, as in some versions
986 .BR find .
987 Both of these constructions might need to be escaped (with a `\e') or
988 quoted to protect them from expansion by the shell.  See the
989 .B EXAMPLES
990 section for examples of the use of the 
991 .B \-exec
992 option.  The specified
993 command is run once for each matched file.
994 The command is executed in the starting directory.   There are
995 unavoidable security problems surrounding use of the 
996 .B \-exec
997 action;
998 you should use the
999 .B \-execdir
1000 option instead.  
1002 .IP "\-exec \fIcommand\fR {} +"
1003 This variant of the 
1004 .B \-exec
1005 action runs the specified command on the
1006 selected files, but the command line is built by appending each
1007 selected file name at the end; the total number of invocations of the
1008 command will be much less than the number of matched files.  The
1009 command line is built in much the same way that
1010 .B xargs
1011 builds its command lines.  Only one instance of `{}' is allowed within
1012 the command.  The command is executed in the starting directory.
1014 .IP "\-execdir \fIcommand\fR ;"
1015 .IP "\-execdir \fIcommand\fR {} +"
1016 Like 
1017 .BR \-exec ,
1018 but the specified command is run from the subdirectory
1019 containing the matched file, which is not normally the directory in
1020 which you started 
1021 .BR find .
1022 This a much more secure method for invoking commands, as it avoids
1023 race conditions during resolution of the paths to the matched files.
1024 As with the 
1025 .B \-exec
1026 action, the `+' form of 
1027 .B \-execdir
1028 will build a
1029 command line to process more than one matched file, but any given
1030 invocation of
1031 .I command 
1032 will only list files that exist in the same subdirectory.  If you use
1033 this option, you must ensure that your 
1034 .B $PATH
1035 environment variable does not reference `.';
1036 otherwise, an attacker can run any commands they like by leaving an
1037 appropriately-named file in a directory in which you will run
1038 .BR \-execdir .  
1039 The same applies to having entries in 
1040 .B $PATH
1041 which are empty or which are not absolute directory names.
1043 .IP "\-fls \fIfile\fR"
1044 True; like 
1045 .B \-ls
1046 but write to \fIfile\fR like 
1047 .BR \-fprint .
1048 The output file is always created, even if the predicate is never
1049 matched.  
1050 See the
1051 .B UNUSUAL FILENAMES
1052 section for information about how unusual characters in filenames are handled.
1054 .IP "\-fprint \fIfile\fR"
1055 True; print the full file name into file \fIfile\fR.  If \fIfile\fR
1056 does not exist when \fBfind\fR is run, it is created; if it does
1057 exist, it is truncated.  The file names ``/dev/stdout'' and
1058 ``/dev/stderr'' are handled specially; they refer to the standard
1059 output and standard error output, respectively.
1060 The output file is always created, even if the predicate is never matched.
1061 See the
1062 .B UNUSUAL FILENAMES
1063 section for information about how unusual characters in filenames are handled.
1065 .IP "\-fprint0 \fIfile\fR"
1066 True; like 
1067 .B \-print0 
1068 but write to \fIfile\fR like 
1069 .BR \-fprint .
1070 The output file is always created, even if the predicate is never matched.
1071 See the
1072 .B UNUSUAL FILENAMES
1073 section for information about how unusual characters in filenames are handled.
1075 .IP "\-fprintf \fIfile\fR \fIformat\fR"
1076 True; like 
1077 .B \-printf 
1078 but write to \fIfile\fR like 
1079 .BR \-fprint .
1080 The output file is always created, even if the predicate is never matched.
1081 See the
1082 .B UNUSUAL FILENAMES
1083 section for information about how unusual characters in filenames are handled.
1085 .IP \-ls
1086 True; list current file in 
1087 .B ls \-dils
1088 format on standard output.
1089 The block counts are of 1K blocks, unless the environment variable
1090 POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
1091 See the
1092 .B UNUSUAL FILENAMES
1093 section for information about how unusual characters in filenames are handled.
1095 .IP "\-ok \fIcommand\fR ;"
1096 Like 
1097 .B \-exec
1098 but ask the user first (on the standard input); if the
1099 response does not start with `y' or `Y', do not run the command, and
1100 return false.  If the command is run, its standard input is redirected
1101 from
1102 .BR /dev/null .
1104 .IP "\-okdir \fIcommand\fR ;"
1105 Like 
1106 .B \-execdir
1107 but ask the user first (on the standard input); if the
1108 response does not start with `y' or `Y', do not run the command, and
1109 return false.  If the command is run, its standard input is redirected
1110 from
1111 .BR /dev/null .
1113 .IP \-print
1114 True; print the full file name on the standard output, followed by a
1115 newline.   If you are piping the output of 
1116 .B find 
1117 into another program and there is the faintest possibility that the files 
1118 which you are searching for might contain a newline, then you should 
1119 seriously consider using the 
1120 .B \-print0
1121 option instead of 
1122 .BR \-print .
1123 See the
1124 .B UNUSUAL FILENAMES
1125 section for information about how unusual characters in filenames are handled.
1127 .IP \-print0
1128 True; print the full file name on the standard output, followed by a
1129 null character (instead of the newline character that 
1130 .B \-print
1131 uses).
1132 This allows file names that contain newlines or other types of white
1133 space to be correctly interpreted by programs that process the
1134 \fBfind\fR output.  This option corresponds to the 
1135 .B \-0
1136 option of
1137 .BR xargs .
1139 .IP "\-printf \fIformat\fR"
1140 True; print \fIformat\fR on the standard output, interpreting `\e'
1141 escapes and `%' directives.  Field widths and precisions can be
1142 specified as with the `printf' C function.  Please note that many of
1143 the fields are printed as %s rather than %d, and this may mean that
1144 flags don't work as you might expect.  This also means that the `\-'
1145 flag does work (it forces fields to be left-aligned).  Unlike 
1146 .BR \-print ,
1147 .B \-printf
1148 does not add a newline at the end of the string.  The escapes
1149 and directives are:
1151 .IP \ea
1152 Alarm bell.
1153 .IP \eb
1154 Backspace.
1155 .IP \ec
1156 Stop printing from this format immediately and flush the output.
1157 .IP \ef
1158 Form feed.
1159 .IP \en
1160 Newline.
1161 .IP \er
1162 Carriage return.
1163 .IP \et
1164 Horizontal tab.
1165 .IP \ev
1166 Vertical tab.
1167 .IP \e\0
1168 ASCII NUL.
1169 .IP \e\e
1170 A literal backslash (`\e').
1171 .IP \eNNN
1172 The character whose ASCII code is NNN (octal).
1174 A `\e' character followed by any other character is treated as an
1175 ordinary character, so they both are printed.
1176 .IP %%
1177 A literal percent sign.
1178 .IP %a
1179 File's last access time in the format returned by the C `ctime' function.
1180 .IP %A\fIk\fP
1181 File's last access time in the format specified by \fIk\fR, which is
1182 either `@' or a directive for the C `strftime' function.  The possible
1183 values for \fIk\fR are listed below; some of them might not be
1184 available on all systems, due to differences in `strftime' between
1185 systems.  
1187 .IP @
1188 seconds since Jan. 1, 1970, 00:00 GMT, with fractional part.
1190 Time fields:
1191 .IP H
1192 hour (00..23)
1193 .IP I
1194 hour (01..12)
1195 .IP k
1196 hour ( 0..23)
1197 .IP l
1198 hour ( 1..12)
1199 .IP M
1200 minute (00..59)
1201 .IP p
1202 locale's AM or PM
1203 .IP r
1204 time, 12-hour (hh:mm:ss [AP]M)
1205 .IP S
1206 Second (00.00 .. 61.00).  There is a fractional part.
1207 .IP T
1208 time, 24-hour (hh:mm:ss)
1209 .IP +
1210 Date and time, separated by `+', for example
1211 `2004\-04\-28+22:22:05.0'.  This is a GNU extension.  The time is
1212 given in the current timezone (which may be affected by setting the TZ
1213 environment variable).  The seconds field includes a fractional part.
1214 .IP X
1215 locale's time representation (H:M:S)
1216 .IP Z
1217 time zone (e.g., EDT), or nothing if no time zone is determinable
1219 Date fields:
1220 .IP a
1221 locale's abbreviated weekday name (Sun..Sat)
1222 .IP A
1223 locale's full weekday name, variable length (Sunday..Saturday)
1224 .IP b
1225 locale's abbreviated month name (Jan..Dec)
1226 .IP B
1227 locale's full month name, variable length (January..December)
1228 .IP c
1229 locale's date and time (Sat Nov 04 12:02:33 EST 1989).  The format is
1230 the same as for 
1231 .BR ctime (3)
1232 and so to preserve compatibility with that format, there is no fractional part
1233 in the seconds field.
1234 .IP d
1235 day of month (01..31)
1236 .IP D
1237 date (mm/dd/yy)
1238 .IP h
1239 same as b
1240 .IP j
1241 day of year (001..366)
1242 .IP m
1243 month (01..12)
1244 .IP U
1245 week number of year with Sunday as first day of week (00..53)
1246 .IP w
1247 day of week (0..6)
1248 .IP W
1249 week number of year with Monday as first day of week (00..53)
1250 .IP x
1251 locale's date representation (mm/dd/yy)
1252 .IP y
1253 last two digits of year (00..99)
1254 .IP Y
1255 year (1970...)
1257 .IP %b
1258 The amount of disk space used for this file in 512-byte blocks. Since disk
1259 space is allocated in multiples of the filesystem block size this is usually
1260 greater than %s/512, but it can also be smaller if the file is a sparse file.
1261 .IP %c
1262 File's last status change time in the format returned by the C `ctime'
1263 function.
1264 .IP %C\fIk\fP
1265 File's last status change time in the format specified by \fIk\fR,
1266 which is the same as for %A.
1267 .IP %d
1268 File's depth in the directory tree; 0 means the file is a command line
1269 argument.
1270 .IP %D
1271 The device number on which the file exists (the st_dev field of struct
1272 stat), in decimal.
1273 .IP %f
1274 File's name with any leading directories removed (only the last element).
1275 .IP %F
1276 Type of the filesystem the file is on; this value can be used for
1277 \-fstype.
1278 .IP %g
1279 File's group name, or numeric group ID if the group has no name.
1280 .IP %G
1281 File's numeric group ID.
1282 .IP %h
1283 Leading directories of file's name (all but the last element).
1284 If the file name contains no slashes (since it is in the current 
1285 directory) the %h specifier expands to ".".
1286 .IP %H
1287 Command line argument under which file was found.
1288 .IP %i
1289 File's inode number (in decimal).
1290 .IP %k
1291 The amount of disk space used for this file in 1K blocks. Since disk space is
1292 allocated in multiples of the filesystem block size this is usually greater
1293 than %s/1024, but it can also be smaller if the file is a sparse file.
1294 .IP %l
1295 Object of symbolic link (empty string if file is not a symbolic link).
1296 .IP %m
1297 File's permission bits (in octal).  This option uses the `traditional'
1298 numbers which most Unix implementations use, but if your particular 
1299 implementation uses an unusual ordering of octal permissions bits, you
1300 will see a difference between the actual value of the file's mode and
1301 the output of %m.   Normally you will want to have a leading
1302 zero on this number, and to do this, you should use the 
1303 .B #
1304 flag (as in, for example, `%#m').
1305 .IP %M 
1306 File's permissions (in symbolic form, as for 
1307 .BR ls ).  
1308 This directive is supported in findutils 4.2.5 and later.
1309 .IP %n
1310 Number of hard links to file.
1311 .IP %p
1312 File's name.
1313 .IP %P
1314 File's name with the name of the command line argument under which
1315 it was found removed.
1316 .IP %s
1317 File's size in bytes.
1318 .IP %S 
1319 File's sparseness.  This is calculated as (BLOCKSIZE*st_blocks /
1320 st_size).  The exact value you will get for an ordinary file of a
1321 certain length is system-dependent.  However, normally sparse files
1322 will have values less than 1.0, and files which use indirect blocks
1323 may have a value which is greater than 1.0.   The value used for
1324 BLOCKSIZE is system-dependent, but is usually 512 bytes.   If the file
1325 size is zero, the value printed is undefined.  On systems which lack
1326 support for st_blocks, a file's sparseness is assumed to be 1.0.
1327 .IP %t
1328 File's last modification time in the format returned by the C `ctime'
1329 function.
1330 .IP %T\fIk\fP
1331 File's last modification time in the format specified by \fIk\fR, 
1332 which is the same as for %A.
1333 .IP %u
1334 File's user name, or numeric user ID if the user has no name.
1335 .IP %U
1336 File's numeric user ID.
1337 .IP %y
1338 File's type (like in 
1339 .BR "ls \-l" ), 
1340 U=unknown type (shouldn't happen)
1341 .IP %Y
1342 File's type (like %y), plus follow symlinks: L=loop, N=nonexistent
1344 A `%' character followed by any other character is discarded, but the
1345 other character is printed (don't rely on this, as further format
1346 characters may be introduced).  A `%' at the end of the format
1347 argument causes undefined behaviour since there is no following
1348 character.  In some locales, it may hide your door keys, while in
1349 others it may remove the final page from the novel you are reading.
1351 The %m and %d directives support the 
1352 .B #
1354 .B 0 
1355 and 
1356 .B + 
1357 flags, but the other directives do not, even if they
1358 print numbers.  Numeric directives that do not support these flags
1359 include 
1360 .BR G , 
1361 .BR U , 
1362 .BR b , 
1363 .BR D , 
1364 .B  k 
1365 and 
1366 .BR n .
1367 The `\-' format flag is supported and changes the alignment of a field
1368 from right-justified (which is the default) to left-justified.
1370 See the
1371 .B UNUSUAL FILENAMES
1372 section for information about how unusual characters in filenames are handled.
1376 .IP \-prune
1377 True; if the file is a directory, do not descend into it. If 
1378 .B \-depth
1379 is given, false; no effect.  Because 
1380 .B \-delete
1381 implies 
1382 .BR \-depth , 
1383 you cannot usefully use 
1384 .B \-prune 
1385 and 
1386 .B \-delete together. 
1388 .IP "\-quit"
1389 Exit immediately.  No child processes will be left running, but no more
1390 paths specified on the command line will be processed.  For example,
1391 .B find /tmp/foo /tmp/bar \-print \-quit
1392 will print only
1393 .BR /tmp/foo .
1394 Any command lines which have been built up with
1395 .B \-execdir ... {} +
1396 will be invoked before 
1397 .B find
1398 exits.   The exit status may or may not be zero, depending on whether
1399 an error has already occurred.  
1401 .SS UNUSUAL FILENAMES
1402 Many of the actions of 
1403 .B find
1404 result in the printing of data which is under the control of other
1405 users.  This includes file names, sizes, modification times and so
1406 forth.  File names are a potential problem since they can contain any
1407 character except `\e0' and `/'.  Unusual characters in file names can
1408 do unexpected and often undesirable things to your terminal (for
1409 example, changing the settings of your function keys on some
1410 terminals).  Unusual characters are handled differently by various
1411 actions, as described below.
1413 .IP "\-print0, \-fprint0\"
1414 Always print the exact filename, unchanged, even if the output is
1415 going to a terminal.
1417 .IP "\-ls, \-fls"
1418 Unusual characters are always escaped.  White space, backslash, and
1419 double quote characters are printed using C-style escaping (for
1420 example `\ef', `\e"').  Other unusual characters are printed using an
1421 octal escape.  Other printable characters (for 
1422 .B \-ls 
1423 and 
1424 .B \-fls 
1425 these are the characters between octal 041 and 0176) are printed as-is.
1427 .IP "\-printf, \-fprintf"
1428 If the output is not going to a terminal, it is printed as-is.
1429 Otherwise, the result depends on which directive is in use.  The
1430 directives %D, %F, %g, %G, %H, %Y, and %y expand to values which are
1431 not under control of files' owners, and so are printed as-is.  The
1432 directives %a, %b, %c, %d, %i, %k, %m, %M, %n, %s, %t, %u and %U have
1433 values which are under the control of files' owners but which cannot
1434 be used to send arbitrary data to the terminal, and so these are
1435 printed as-is.  The directives %f, %h, %l, %p and %P are quoted.  This
1436 quoting is performed in the same way as for GNU
1437 .BR ls .   
1438 This is not the same quoting mechanism as the one used for
1439 .B \-ls 
1441 .BR \-fls .   
1442 If you are able to decide what format to use for the output of 
1443 .B find
1444 then it is normally better to use `\e0' as a terminator
1445 than to use newline, as file names can contain white space and newline
1446 characters.
1448 .IP "\-print, \-fprint"
1449 Quoting is handled in the same way as for 
1450 .B \-printf
1451 and 
1452 .BR \-fprintf .
1453 If you are using 
1454 .B find
1455 in a script or in a situation where the matched files might have
1456 arbitrary names, you should consider using 
1457 .B \-print0 
1458 instead of
1459 .BR \-print .
1461 The 
1462 .B \-ok 
1463 and 
1464 .B \-okdir
1465 actions print the current filename as-is.  This may change in a future release.
1466 .SS OPERATORS
1468 Listed in order of decreasing precedence:
1470 .IP "( \fIexpr\fR )"
1471 Force precedence.  Since parentheses are special to the shell, you
1472 will normally need to quote them.  Many of the examples in this manual
1473 page use backslashes for this purpose: `\e(...\e)' instead of `(...)'.
1475 .IP "! \fIexpr\fR"
1476 True if \fIexpr\fR is false.  This character will also usually need
1477 protection from interpretation by the shell.
1479 .IP "\-not \fIexpr\fR"
1480 Same as ! \fIexpr\fR, but not POSIX compliant.
1482 .IP "\fIexpr1 expr2\fR"
1483 Two expressions in a row are taken to be joined with an 
1484 implied "and"; \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
1486 .IP "\fIexpr1\fR \-a \fIexpr2\fR"
1487 Same as \fIexpr1 expr2\fR.
1489 .IP "\fIexpr1\fR \-and \fIexpr2\fR"
1490 Same as \fIexpr1 expr2\fR, but not POSIX compliant.
1492 .IP "\fIexpr1\fR \-o \fIexpr2\fR"
1493 Or; \fIexpr2\fR is not evaluated if \fIexpr1\fR is true.
1495 .IP "\fIexpr1\fR \-or \fIexpr2\fR"
1496 Same as \fIexpr1\fR 
1497 .B \-o 
1498 \fIexpr2\fR, but not POSIX compliant.
1500 .IP "\fIexpr1\fR , \fIexpr2\fR"
1501 List; both \fIexpr1\fR and \fIexpr2\fR are always evaluated.  The
1502 value of \fIexpr1\fR is discarded; the value of the list is the value
1503 of \fIexpr2\fR. The comma operator can be useful for searching for
1504 several different types of thing, but traversing the filesystem
1505 hierarchy only once.  The
1506 .B \-fprintf  
1507 action can be used to list the various matched items into several
1508 different output files.
1511 .SH "STANDARDS CONFORMANCE"
1512 For closest compliance to the POSIX standard, you should set the
1513 POSIXLY_CORRECT environment variable.  The following options are
1514 specified in the POSIX standard (IEEE Std 1003.1, 2003 Edition):
1516 .IP \fB\-H\fR
1517 This option is supported.
1519 .IP \fB\-L\fR
1520 This option is supported.
1522 .IP \fB\-name\fR
1523 This option is supported, but POSIX conformance depends on the 
1524 POSIX conformance of the system's 
1525 .BR fnmatch (3) 
1526 library function.  As of findutils-4.2.2, shell metacharacters
1527 (`*', `?' or `[]' for example) will match a leading `.', because 
1528 IEEE PASC interpretation 126 requires this.   This is a change from
1529 previous versions of findutils.
1531 .IP \fB\-type\fR
1532 Supported.   POSIX specifies `b', `c', `d', `l', `p', `f' and `s'.
1533 GNU find also supports `D', representing a Door, where the OS provides these.
1535 .IP \fB\-ok\fR
1536 Supported.   Interpretation of the response is not locale-dependent
1537 (see ENVIRONMENT VARIABLES).
1539 .IP \fB\-newer\fR
1540 Supported.  If the file specified is a symbolic link, it is always
1541 dereferenced.  This is a change from previous behaviour, which used to 
1542 take the relevant time from the symbolic link; see the HISTORY section
1543 below.
1545 .IP \fB\-perm\fR
1546 Supported.  If the POSIXLY_CORRECT environment variable is not set,
1547 some mode arguments (for example +a+x) which are not valid in POSIX
1548 are supported for backward-compatibility.
1550 .IP "Other predicates"
1551 The predicates
1552 .BR \-atime ,
1553 .BR \-ctime ,
1554 .BR \-depth ,
1555 .BR \-group ,
1556 .BR \-links ,
1557 .BR \-mtime ,
1558 .BR \-nogroup ,
1559 .BR \-nouser ,
1560 .BR \-print ,
1561 .BR \-prune ,
1562 .BR \-size ,
1563 .BR \-user  
1564 and 
1565 .B \-xdev
1566 are all supported.
1569 The POSIX standard specifies parentheses `(', `)', negation `!' and the
1570 `and' and `or' operators (
1571 .BR \-a , 
1572 .BR \-o ).   
1574 All other options, predicates, expressions and so forth are extensions 
1575 beyond the POSIX standard.  Many of these extensions are not unique to 
1576 GNU find, however.
1578 The POSIX standard requires that 
1579 .B find 
1580 detects loops:
1582 The 
1583 .B find
1584 utility shall detect infinite loops; that is, entering a
1585 previously visited directory that is an ancestor of the last file
1586 encountered. When it detects an infinite loop, find shall write a
1587 diagnostic message to standard error and shall either recover its
1588 position in the hierarchy or terminate.
1590 GNU 
1591 .B find 
1592 complies with these requirements.  The link count of
1593 directories which contain entries which are hard links to an ancestor
1594 will often be lower than they otherwise should be.  This can mean that
1595 GNU find will sometimes optimise away the visiting of a subdirectory
1596 which is actually a link to an ancestor.  Since
1597 .B find
1598 does not actually enter such a subdirectory, it is allowed to avoid
1599 emitting a diagnostic message.  Although this behaviour may be
1600 somewhat confusing, it is unlikely that anybody actually depends on
1601 this behaviour.  If the leaf optimisation has been turned off with
1602 .BR \-noleaf ,
1603 the directory entry will always be examined and the diagnostic message
1604 will be issued where it is appropriate.  Symbolic links cannot be used
1605 to create filesystem cycles as such, but if the 
1606 .B \-L
1607 option or the
1608 .B \-follow
1609 option is in use, a diagnostic message is issued when 
1610 .B find 
1611 encounters a loop of symbolic links.  As with loops containing hard
1612 links, the leaf optimisation will often mean that 
1613 .B find
1614 knows that it doesn't need to call 
1615 .I stat()
1617 .I chdir() 
1618 on the symbolic link, so this diagnostic is frequently not necessary.
1620 The 
1621 .B \-d
1622 option is supported for compatibility with various BSD systems,
1623 but you should use the POSIX-compliant option 
1624 .B \-depth
1625 instead.
1627 The POSIXLY_CORRECT environment variable does not affect the behaviour
1628 of the 
1629 .B \-regex 
1630 or 
1631 .B \-iregex 
1632 tests because those tests aren't specified in the POSIX standard.
1633 .SH "ENVIRONMENT VARIABLES"
1635 .IP LANG
1636 Provides a default value for the internationalization variables that
1637 are unset or null.
1639 .IP LC_ALL
1640 If set to a non-empty string value, override the values of all the
1641 other internationalization variables.
1643 .IP LC_COLLATE
1644 The POSIX standard specifies that this variable affects the pattern
1645 matching to be used for the 
1646 .B \-name
1647 option.   GNU find uses the 
1648 .BR fnmatch (3) 
1649 library function, and so support for `LC_COLLATE' depends on the
1650 system library.    
1653 POSIX also specifies that the `LC_COLLATE' environment 
1654 variable affects the interpretation of the user's response to the 
1655 query issued by 
1656 .BR \-ok' , 
1657 but this is not the case for GNU find.
1659 .IP LC_CTYPE 
1660 This variable affects the treatment of character classes used with 
1661 the 
1662 .B \-name
1663 test, if the system's 
1664 .BR fnmatch (3) 
1665 library function supports this.   It has no effect on the behaviour 
1666 of the 
1667 .B \-ok
1668 expression.
1670 .IP LC_MESSAGES
1671 Determines the locale to be used for internationalised messages.
1673 .IP NLSPATH
1674 Determines the location of the internationalisation message catalogues.
1676 .IP PATH
1677 Affects the directories which are searched to find the executables 
1678 invoked by 
1679 .BR \-exec , 
1680 .BR \-execdir , 
1681 .B \-ok
1682 and 
1683 .BR \-okdir .
1685 .IP POSIXLY_CORRECT
1686 Determines the block size used by 
1687 .B \-ls
1688 and 
1689 .BR \-fls . 
1690 If 
1691 .B POSIXLY_CORRECT
1692 is set, blocks are units of 512 bytes.  Otherwise
1693 they are units of 1024 bytes.   
1695 Setting this variable also turns off
1696 warning messages (that is, implies
1697 .BR \-nowarn )
1698 by default, because POSIX requires that apart from
1699 the output for 
1700 .BR \-ok ,
1701 all messages printed on stderr are diagnositcs and must result in a
1702 non-zero exit status.
1704 When POSIXLY_CORRECT is not set, 
1705 .B \-perm
1706 +zzz
1707 is treated just like 
1708 .B \-perm 
1709 /zzz
1710 if 
1711 +zzz is not a valid symbolic mode.  When POSIXLY_CORRECT is set, such
1712 constructs are treated as an error.
1714 .IP TZ
1715 Affects the time zone used for some of the time-related format
1716 directives of 
1717 .B \-printf 
1718 and 
1719 .BR \-fprintf .
1720 .SH "EXAMPLES"
1722 .B find /tmp \-name core \-type f \-print | xargs /bin/rm \-f
1725 Find files named 
1726 .B core
1727 in or below the directory 
1728 .B /tmp 
1729 and delete them.  Note that this will work incorrectly if there are 
1730 any filenames containing newlines, single or double quotes, or spaces.
1732 .B find /tmp \-name core \-type f \-print0 | xargs \-0 /bin/rm \-f
1735 Find files named 
1736 .B core
1737 in or below the directory 
1738 .B /tmp 
1739 and delete them, processing filenames in such a way that file or
1740 directory names containing single or double quotes, spaces or newlines
1741 are correctly handled.  The
1742 .B \-name 
1743 test comes before the 
1744 .B \-type
1745 test in order to avoid having to call 
1746 .B stat(2) 
1747 on every file.
1751 .B find . \-type f \-exec file \(aq{}\(aq \e\;
1754 Runs `file' on every file in or below the current directory.  Notice
1755 that the braces are enclosed in single quote marks to protect them
1756 from interpretation as shell script punctuation.  The semicolon is
1757 similarly protected by the use of a backslash, though single quotes
1758 could have been used in that case also.
1762 .B find /  \e
1763 .B \e( \-perm \-4000 \-fprintf /root/suid.txt "%#m %u %p\en" \e) , \e
1764 .B \e( \-size +100M \-fprintf /root/big.txt  "%\-10s %p\en" \e)
1767 Traverse the filesystem just once, listing setuid files and
1768 directories into
1769 .B /root/suid.txt
1770 and large files into 
1771 .BR /root/big.txt .
1775 .B find $HOME  \-mtime 0
1778 Search for files in your home directory which have been modified in
1779 the last twenty-four hours.  This command works this way because the
1780 time since each file was last modified is divided by 24 hours and any 
1781 remainder is discarded.  That means that to match 
1782 .B \-mtime 
1783 .BR 0 ,
1784 a file will have to have a modification in the past which is less than
1785 24 hours ago.
1789 .B find /sbin /usr/sbin -executable \e! -readable \-print
1792 Search for files which are executable but not readable.
1796 .B find . \-perm 664
1799 Search for files which have read and write permission for their owner,
1800 and group, but which other users can read but not write to.  Files
1801 which meet these criteria but have other permissions bits set (for
1802 example if someone can execute the file) will not be matched.
1806 .B find . \-perm \-664
1809 Search for files which have read and write permission for their owner
1810 and group, and which other users can read, without regard to the
1811 presence of any extra permission bits (for example the executable
1812 bit).  This will match a file which has mode 0777, for example.
1816 .B find . \-perm /222
1819 Search for files which are writable by somebody (their owner, or
1820 their group, or anybody else).
1824 .B find . \-perm /220
1825 .B find . \-perm /u+w,g+w
1826 .B find . \-perm /u=w,g=w
1829 All three of these commands do the same thing, but the first one uses
1830 the octal representation of the file mode, and the other two use the
1831 symbolic form.  These commands all search for files which are
1832 writable by either their owner or their group.  The files don't have
1833 to be writable by both the owner and group to be matched; either will
1838 .B find . \-perm \-220
1839 .B find . \-perm \-g+w,u+w
1842 Both these commands do the same thing; search for files which are
1843 writable by both their owner and their group.
1847 .B find . \-perm \-444 \-perm /222 ! \-perm /111
1848 .B find . \-perm \-a+r \-perm /a+w ! \-perm /a+x
1851 These two commands both search for files that are readable for
1852 everybody (
1853 .B \-perm \-444 
1854 or 
1855 .BR "\-perm \-a+r" ), 
1856 have at least one write bit
1857 set (
1858 .B \-perm /222 
1859 or 
1860 .BR "\-perm /a+w" ) 
1861 but are not executable for anybody (
1862 .B ! \-perm /111 
1863 and 
1864 .B ! \-perm /a+x 
1865 respectively).
1869 .B cd /source-dir
1870 .B find . \-name .snapshot \-prune \-o \e( \e! \-name "*~" \-print0 \e)|
1871 .B cpio \-pmd0   /dest-dir
1873 .fi 
1874 This command copies the contents of 
1875 .B /source-dir
1876 to 
1877 .BR /dest-dir ,
1878 but omits files and directories named 
1879 .B .snapshot 
1880 (and anything in them).  It also omits files or directories whose name
1881 ends in
1882 .BR ~ ,
1883 but not their contents.  The construct 
1884 .B \-prune \-o \e( ... \-print0 \e)
1885 is quite common.  The idea here is that the expression before 
1886 .B \-prune 
1887 matches things which are to be pruned.  However, the 
1888 .B \-prune 
1889 action itself returns true, so the following 
1890 .B \-o 
1891 ensures that the right hand side is evaluated only for those
1892 directories which didn't get pruned (the contents of the pruned
1893 directories are not even visited, so their contents are irrelevant).
1894 The expression on the right hand side of the 
1895 .B \-o
1896 is in parentheses only for clarity.  It emphasises that the
1897 .B \-print0 
1898 action takes place only for things that didn't have 
1899 .B \-prune 
1900 applied to them.  Because the default `and' condition between tests
1901 binds more tightly than 
1902 .BR \-o ,
1903 this is the default anyway, but the parentheses help to show
1904 what is going on.
1906 .SH EXIT STATUS
1908 .B find
1909 exits with status 0 if all files are processed successfully, greater
1910 than 0 if errors occur.   This is deliberately a very broad
1911 description, but if the return value is non-zero, you should not rely
1912 on the correctness of the results of 
1913 .BR find .
1915 .SH "SEE ALSO"
1916 \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1), \fBxargs\fP(1),
1917 \fBchmod\fP(1), \fBfnmatch\fP(3), \fBregex\fP(7), \fBstat\fP(2),
1918 \fBlstat\fP(2), \fBls\fP(1), \fBprintf\fP(3), \fBstrftime\fP(3),
1919 \fBctime\fP(3), \fBFinding Files\fP (on-line in Info, or printed).
1920 .SH "HISTORY"
1921 As of findutils-4.2.2, shell metacharacters (`*', `?' or `[]' for
1922 example) used in filename patterns will match a leading `.', because
1923 IEEE POSIX interpretation 126 requires this.
1925 The syntax 
1926 \.B \-perm +MODE 
1927 was deprecated in findutils-4.2.21, in favour of
1928 \.B \-perm 
1929 .BR /MODE .
1930 As of findutils-4.3.3, 
1931 .B \-perm /000
1932 now matches all files instead of none.  
1934 Nanosecond-resolution
1935 timestamps were implemented in findutils-4.3.3.
1937 As of findutils-4.3.11, the 
1938 .B \-delete 
1939 action sets 
1940 .BR find 's 
1941 exit status to a nonzero value when it fails.
1942 However, 
1943 .B find
1944 will not exit immediately.  Previously, 
1945 .BR find 's 
1946 exit status was unaffected by the failure of 
1947 .BR \-delete .
1949 l l l .
1950 Feature Added in        Also occurs in 
1951 \-newerXY       4.3.3   BSD
1952 \-D     4.3.1
1953 \-O     4.3.1
1954 \-readable      4.3.0
1955 \-writable      4.3.0
1956 \-executable    4.3.0
1957 \-regextype     4.2.24
1958 \-exec ... +    4.2.12  POSIX
1959 \-execdir       4.2.12  BSD
1960 \-okdir 4.2.12
1961 \-samefile      4.2.11
1962 \-H     4.2.5   POSIX
1963 \-L     4.2.5   POSIX
1964 \-P     4.2.5   BSD
1965 \-delete        4.2.3   
1966 \-quit  4.2.3
1967 \-d     4.2.3   BSD
1968 \-wholename     4.2.0
1969 \-iwholename    4.2.0
1970 \-ignore_readdir_race   4.2.0
1971 \-fls   4.0
1972 \-ilname        3.8
1973 \-iname 3.8
1974 \-ipath 3.8
1975 \-iregex        3.8
1977 .SH "NON-BUGS"
1979 .B $ find . \-name *.c \-print
1980 find: paths must precede expression
1981 Usage: find [\-H] [\-L] [\-P] [\-Olevel] [\-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
1984 This happens because 
1985 .I *.c 
1986 has been expanded by the shell
1987 resulting in 
1988 .B find
1989 actually receiving a command line like this:
1992 .B find . \-name bigram.c code.c frcode.c locate.c \-print
1995 That command is of course not going to work.  Instead of doing things
1996 this way, you should enclose the pattern in quotes or escape the wildcard:
1998 .B $ find . \-name \e*.c \-print
2001 .SH "BUGS"
2003 There are security problems inherent in the behaviour that the POSIX
2004 standard specifies for
2005 .BR find ,
2006 which therefore cannot be fixed.  For example, the 
2007 .B \-exec
2008 action is
2009 inherently insecure, and 
2010 .B \-execdir
2011 should be used instead.  
2012 Please see \fBFinding Files\fP for more information. 
2014 The environment variable 
2015 .B  LC_COLLATE
2016 has no effect on the 
2017 .B \-ok 
2018 action.
2019 .P 
2020 The best way to report a bug is to use the form at
2021 http://savannah.gnu.org/bugs/?group=findutils.  
2022 The reason for this is that you will then be able to track progress in
2023 fixing the problem.   Other comments about \fBfind\fP(1) and about
2024 the findutils package in general can be sent to the 
2025 .I bug\-findutils
2026 mailing list.  To join the list, send email to 
2027 .IR bug\-findutils\-request@gnu.org .