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