cvsimport
[findutils.git] / find / find.1
blob1aa9da34c8b3929a4d5dbcfd8e7c1bd0a49745b1
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.  
748 If 
749 .B \-delete
750 fails, 
751 .BR find 's 
752 exit status will be nonzero
753 (when it eventually exits).  
754 Use of 
755 .B \-delete 
756 automatically turns on the 
757 .B \-depth 
758 option.   
760 .BR Warnings :
761 Don't forget that the find command line is 
762 evaluated as an expression, so putting \-delete first will make 
763 .B find
764 try to delete everything below the starting points you specified.
765 When testing a 
766 .B find
767 command line that you later intend to use with 
768 .BR \-delete , 
769 you should explicitly specify 
770 .B \-depth 
771 in order to avoid later surprises.  Because
772 .B \-delete 
773 implies 
774 .BR \-depth , 
775 you cannot usefully use 
776 .B \-prune 
777 and 
778 .B \-delete
779 together. 
781 .IP "\-exec \fIcommand\fR ;"
782 Execute \fIcommand\fR; true if 0 status is returned.  All following
783 arguments to
784 .B find
785 are taken to be arguments to the command until an argument consisting
786 of `;' is encountered.  The string `{}' is replaced by the current
787 file name being processed everywhere it occurs in the arguments to the
788 command, not just in arguments where it is alone, as in some versions
790 .BR find .
791 Both of these constructions might need to be escaped (with a `\e') or
792 quoted to protect them from expansion by the shell.  See the
793 .B EXAMPLES
794 section for examples of the use of the `\-exec' option.  The specified
795 command is run once for each matched file.
796 The command is executed in the starting directory.   There are
797 unavoidable security problems surrounding use of the \-exec action;
798 you should use the \-execdir option instead.  
800 .IP "\-exec \fIcommand\fR {} +"
801 This variant of the \-exec action runs the specified command on the
802 selected files, but the command line is built by appending each
803 selected file name at the end; the total number of invocations of the
804 command will be much less than the number of matched files.  The
805 command line is built in much the same way that
806 .B xargs
807 builds its command lines.  Only one instance of `{}' is allowed within
808 the command.  The command is executed in the starting directory.
810 .IP "\-execdir \fIcommand\fR ;"
811 .IP "\-execdir \fIcommand\fR {} +"
812 Like \-exec, but the specified command is run from the subdirectory
813 containing the matched file, which is not normally the directory in
814 which you started 
815 .BR find .
816 This a much more secure method for invoking commands, as it avoids
817 race conditions during resolution of the paths to the matched files.
818 As with the \-exec action, the `+' form of \-execdir will build a
819 command line to process more than one matched file, but any given
820 invocation of
821 .I command 
822 will only list files that exist in the same subdirectory.  If you use
823 this option, you must ensure that your 
824 .B $PATH
825 environment variable does not reference `.';
826 otherwise, an attacker can run any commands they like by leaving an
827 appropriately-named file in a directory in which you will run
828 \-execdir.  The same applies to having entries in 
829 .B $PATH
830 which are empty or which are not absolute directory names.
832 .IP "\-fls \fIfile\fR"
833 True; like \-ls but write to \fIfile\fR like \-fprint.
834 The output file is always created, even if the predicate is never
835 matched.  
836 See the
837 .B UNUSUAL FILENAMES
838 section for information about how unusual characters in filenames are handled.
840 .IP "\-fprint \fIfile\fR"
841 True; print the full file name into file \fIfile\fR.  If \fIfile\fR
842 does not exist when \fBfind\fR is run, it is created; if it does
843 exist, it is truncated.  The file names ``/dev/stdout'' and
844 ``/dev/stderr'' are handled specially; they refer to the standard
845 output and standard error output, respectively.
846 The output file is always created, even if the predicate is never matched.
847 See the
848 .B UNUSUAL FILENAMES
849 section for information about how unusual characters in filenames are handled.
851 .IP "\-fprint0 \fIfile\fR"
852 True; like \-print0 but write to \fIfile\fR like \-fprint.
853 The output file is always created, even if the predicate is never matched.
854 See the
855 .B UNUSUAL FILENAMES
856 section for information about how unusual characters in filenames are handled.
858 .IP "\-fprintf \fIfile\fR \fIformat\fR"
859 True; like \-printf but write to \fIfile\fR like \-fprint.
860 The output file is always created, even if the predicate is never matched.
861 See the
862 .B UNUSUAL FILENAMES
863 section for information about how unusual characters in filenames are handled.
865 .IP \-ls
866 True; list current file in `ls \-dils' format on standard output.
867 The block counts are of 1K blocks, unless the environment variable
868 POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
869 See the
870 .B UNUSUAL FILENAMES
871 section for information about how unusual characters in filenames are handled.
873 .IP "\-ok \fIcommand\fR ;"
874 Like \-exec but ask the user first (on the standard input); if the
875 response does not start with `y' or `Y', do not run the command, and
876 return false.  If the command is run, its standard input is redirected
877 from
878 .BR /dev/null .
880 .IP "\-okdir \fIcommand\fR ;"
881 Like \-execdir but ask the user first (on the standard input); if the
882 response does not start with `y' or `Y', do not run the command, and
883 return false.  If the command is run, its standard input is redirected
884 from
885 .BR /dev/null .
887 .IP \-print
888 True; print the full file name on the standard output, followed by a
889 newline.   If you are piping the output of 
890 .B find 
891 into another program and there is the faintest possibility that the files 
892 which you are searching for might contain a newline, then you should 
893 seriously consider using the `\-print0' option instead of `\-print'.
894 See the
895 .B UNUSUAL FILENAMES
896 section for information about how unusual characters in filenames are handled.
898 .IP \-print0
899 True; print the full file name on the standard output, followed by a
900 null character (instead of the newline character that `\-print' uses).
901 This allows file names that contain newlines or other types of white
902 space to be correctly interpreted by programs that process the
903 \fBfind\fR output.  This option corresponds to the `\-0' option of
904 .BR xargs .
906 .IP "\-printf \fIformat\fR"
907 True; print \fIformat\fR on the standard output, interpreting `\e'
908 escapes and `%' directives.  Field widths and precisions can be
909 specified as with the `printf' C function.  Please note that many of
910 the fields are printed as %s rather than %d, and this may mean that
911 flags don't work as you might expect.  This also means that the `\-'
912 flag does work (it forces fields to be left-aligned).  Unlike \-print,
913 \-printf does not add a newline at the end of the string.  The escapes
914 and directives are:
916 .IP \ea
917 Alarm bell.
918 .IP \eb
919 Backspace.
920 .IP \ec
921 Stop printing from this format immediately and flush the output.
922 .IP \ef
923 Form feed.
924 .IP \en
925 Newline.
926 .IP \er
927 Carriage return.
928 .IP \et
929 Horizontal tab.
930 .IP \ev
931 Vertical tab.
932 .IP \e\0
933 ASCII NUL.
934 .IP \e\e
935 A literal backslash (`\e').
936 .IP \eNNN
937 The character whose ASCII code is NNN (octal).
939 A `\e' character followed by any other character is treated as an
940 ordinary character, so they both are printed.
941 .IP %%
942 A literal percent sign.
943 .IP %a
944 File's last access time in the format returned by the C `ctime' function.
945 .IP %A\fIk\fP
946 File's last access time in the format specified by \fIk\fR, which is
947 either `@' or a directive for the C `strftime' function.  The possible
948 values for \fIk\fR are listed below; some of them might not be
949 available on all systems, due to differences in `strftime' between
950 systems.  
952 .IP @
953 seconds since Jan. 1, 1970, 00:00 GMT, with fractional part.
955 Time fields:
956 .IP H
957 hour (00..23)
958 .IP I
959 hour (01..12)
960 .IP k
961 hour ( 0..23)
962 .IP l
963 hour ( 1..12)
964 .IP M
965 minute (00..59)
966 .IP p
967 locale's AM or PM
968 .IP r
969 time, 12-hour (hh:mm:ss [AP]M)
970 .IP S
971 Second (00.00 .. 61.00).  There is a fractional part.
972 .IP T
973 time, 24-hour (hh:mm:ss)
974 .IP +
975 Date and time, separated by `+', for example
976 `2004\-04\-28+22:22:05.0'.  This is a GNU extension.  The time is
977 given in the current timezone (which may be affected by setting the TZ
978 environment variable).  The seconds field includes a fractional part.
979 .IP X
980 locale's time representation (H:M:S)
981 .IP Z
982 time zone (e.g., EDT), or nothing if no time zone is determinable
984 Date fields:
985 .IP a
986 locale's abbreviated weekday name (Sun..Sat)
987 .IP A
988 locale's full weekday name, variable length (Sunday..Saturday)
989 .IP b
990 locale's abbreviated month name (Jan..Dec)
991 .IP B
992 locale's full month name, variable length (January..December)
993 .IP c
994 locale's date and time (Sat Nov 04 12:02:33 EST 1989).  The format is
995 the same as for 
996 .BR ctime (3)
997 and so to preserve compatibility with that format, there is no fractional part
998 in the seconds field.
999 .IP d
1000 day of month (01..31)
1001 .IP D
1002 date (mm/dd/yy)
1003 .IP h
1004 same as b
1005 .IP j
1006 day of year (001..366)
1007 .IP m
1008 month (01..12)
1009 .IP U
1010 week number of year with Sunday as first day of week (00..53)
1011 .IP w
1012 day of week (0..6)
1013 .IP W
1014 week number of year with Monday as first day of week (00..53)
1015 .IP x
1016 locale's date representation (mm/dd/yy)
1017 .IP y
1018 last two digits of year (00..99)
1019 .IP Y
1020 year (1970...)
1022 .IP %b
1023 The amount of disk space used for this file in 512-byte blocks. Since disk
1024 space is allocated in multiples of the filesystem block size this is usually
1025 greater than %s/512, but it can also be smaller if the file is a sparse file.
1026 .IP %c
1027 File's last status change time in the format returned by the C `ctime'
1028 function.
1029 .IP %C\fIk\fP
1030 File's last status change time in the format specified by \fIk\fR,
1031 which is the same as for %A.
1032 .IP %d
1033 File's depth in the directory tree; 0 means the file is a command line
1034 argument.
1035 .IP %D
1036 The device number on which the file exists (the st_dev field of struct
1037 stat), in decimal.
1038 .IP %f
1039 File's name with any leading directories removed (only the last element).
1040 .IP %F
1041 Type of the filesystem the file is on; this value can be used for
1042 \-fstype.
1043 .IP %g
1044 File's group name, or numeric group ID if the group has no name.
1045 .IP %G
1046 File's numeric group ID.
1047 .IP %h
1048 Leading directories of file's name (all but the last element).
1049 If the file name contains no slashes (since it is in the current 
1050 directory) the %h specifier expands to ".".
1051 .IP %H
1052 Command line argument under which file was found.
1053 .IP %i
1054 File's inode number (in decimal).
1055 .IP %k
1056 The amount of disk space used for this file in 1K blocks. Since disk space is
1057 allocated in multiples of the filesystem block size this is usually greater
1058 than %s/1024, but it can also be smaller if the file is a sparse file.
1059 .IP %l
1060 Object of symbolic link (empty string if file is not a symbolic link).
1061 .IP %m
1062 File's permission bits (in octal).  This option uses the `traditional'
1063 numbers which most Unix implementations use, but if your particular 
1064 implementation uses an unusual ordering of octal permissions bits, you
1065 will see a difference between the actual value of the file's mode and
1066 the output of %m.   Normally you will want to have a leading
1067 zero on this number, and to do this, you should use the 
1068 .B #
1069 flag (as in, for example, `%#m').
1070 .IP %M 
1071 File's permissions (in symbolic form, as for 
1072 .BR ls ).  
1073 This directive is supported in findutils 4.2.5 and later.
1074 .IP %n
1075 Number of hard links to file.
1076 .IP %p
1077 File's name.
1078 .IP %P
1079 File's name with the name of the command line argument under which
1080 it was found removed.
1081 .IP %s
1082 File's size in bytes.
1083 .IP %S 
1084 File's sparseness.  This is calculated as (BLOCKSIZE*st_blocks /
1085 st_size).  The exact value you will get for an ordinary file of a
1086 certain length is system-dependent.  However, normally sparse files
1087 will have values less than 1.0, and files which use indirect blocks
1088 may have a value which is greater than 1.0.   The value used for
1089 BLOCKSIZE is system-dependent, but is usually 512 bytes.   If the file
1090 size is zero, the value printed is undefined.  On systems which lack
1091 support for st_blocks, a file's sparseness is assumed to be 1.0.
1092 .IP %t
1093 File's last modification time in the format returned by the C `ctime'
1094 function.
1095 .IP %T\fIk\fP
1096 File's last modification time in the format specified by \fIk\fR, 
1097 which is the same as for %A.
1098 .IP %u
1099 File's user name, or numeric user ID if the user has no name.
1100 .IP %U
1101 File's numeric user ID.
1102 .IP %y
1103 File's type (like in ls \-l), U=unknown type (shouldn't happen)
1104 .IP %Y
1105 File's type (like %y), plus follow symlinks: L=loop, N=nonexistent
1107 A `%' character followed by any other character is discarded, but the
1108 other character is printed (don't rely on this, as further format
1109 characters may be introduced).  A `%' at the end of the format
1110 argument causes undefined behaviour since there is no following
1111 character.  In some locales, it may hide your door keys, while in
1112 others it may remove the final page from the novel you are reading.
1114 The %m and %d directives support the 
1115 .B #
1117 .B 0 
1118 and 
1119 .B + 
1120 flags, but the other directives do not, even if they
1121 print numbers.  Numeric directives that do not support these flags
1122 include 
1123 .BR G , 
1124 .BR U , 
1125 .BR b , 
1126 .BR D , 
1127 .B  k 
1128 and 
1129 .BR n .
1130 The `\-' format flag is supported and changes the alignment of a field
1131 from right-justified (which is the default) to left-justified.
1133 See the
1134 .B UNUSUAL FILENAMES
1135 section for information about how unusual characters in filenames are handled.
1139 .IP \-prune
1140 True; if the file is a directory, do not descend into it. If \-depth
1141 is given, false; no effect.  Because \-delete implies \-depth, you
1142 cannot usefully use \-prune and \-delete together. 
1144 .IP "\-quit"
1145 Exit immediately.  No child processes will be left running, but no more
1146 paths specified on the command line will be processed.  For example,
1147 .B find /tmp/foo /tmp/bar \-print \-quit
1148 will print only
1149 .BR /tmp/foo .
1150 Any command lines which have been built up with
1151 .B \-execdir ... {} +
1152 will be invoked before 
1153 .B find
1154 exits.   The exit status may or may not be zero, depending on whether
1155 an error has already occurred.  
1157 .SS UNUSUAL FILENAMES
1158 Many of the actions of 
1159 .B find
1160 result in the printing of data which is under the control of other
1161 users.  This includes file names, sizes, modification times and so
1162 forth.  File names are a potential problem since they can contain any
1163 character except `\e0' and `/'.  Unusual characters in file names can
1164 do unexpected and often undesirable things to your terminal (for
1165 example, changing the settings of your function keys on some
1166 terminals).  Unusual characters are handled differently by various
1167 actions, as described below.
1169 .IP "\-print0, \-fprint0\"
1170 Always print the exact filename, unchanged, even if the output is
1171 going to a terminal.
1173 .IP "\-ls, \-fls"
1174 Unusual characters are always escaped.  White space, backslash, and
1175 double quote characters are printed using C-style escaping (for
1176 example `\ef', `\e"').  Other unusual characters are printed using an
1177 octal escape.  Other printable characters (for \-ls and \-fls these are
1178 the characters between octal 041 and 0176) are printed as-is.
1180 .IP "\-printf, \-fprintf"
1181 If the output is not going to a terminal, it is printed as-is.
1182 Otherwise, the result depends on which directive is in use.  The
1183 directives %D, %F, %g, %G, %H, %Y, and %y expand to values which are
1184 not under control of files' owners, and so are printed as-is.  The
1185 directives %a, %b, %c, %d, %i, %k, %m, %M, %n, %s, %t, %u and %U have
1186 values which are under the control of files' owners but which cannot
1187 be used to send arbitrary data to the terminal, and so these are
1188 printed as-is.  The directives %f, %h, %l, %p and %P are quoted.  This
1189 quoting is performed in the same way as for GNU
1190 .BR ls .   
1191 This is not the same quoting mechanism as the one used for  \-ls and
1192 \-fls.   If you are able to decide what format to use for the output 
1193 of 
1194 .B find
1195 then it is normally better to use `\e0' as a terminator
1196 than to use newline, as file names can contain white space and newline
1197 characters.
1199 .IP "\-print, \-fprint"
1200 Quoting is handled in the same way as for \-printf and \-fprintf.
1201 If you are using 
1202 .B find
1203 in a script or in a situation where the matched files might have
1204 arbitrary names, you should consider using \-print0 instead of
1205 \-print.
1207 The \-ok and \-okdir actions print the current filename as-is.  This
1208 may change in a future release.
1209 .SS OPERATORS
1211 Listed in order of decreasing precedence:
1213 .IP "( \fIexpr\fR )"
1214 Force precedence.  Since parentheses are special to the shell, you
1215 will normally need to quote them.  Many of the examples in this manual
1216 page use backslashes for this purpose: `\e(...\e)' instead of `(...)'.
1218 .IP "! \fIexpr\fR"
1219 True if \fIexpr\fR is false.  This character will also usually need
1220 protection from interpretation by the shell.
1222 .IP "\-not \fIexpr\fR"
1223 Same as ! \fIexpr\fR, but not POSIX compliant.
1225 .IP "\fIexpr1 expr2\fR"
1226 Two expressions in a row are taken to be joined with an 
1227 implied "and"; \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
1229 .IP "\fIexpr1\fR \-a \fIexpr2\fR"
1230 Same as \fIexpr1 expr2\fR.
1232 .IP "\fIexpr1\fR \-and \fIexpr2\fR"
1233 Same as \fIexpr1 expr2\fR, but not POSIX compliant.
1235 .IP "\fIexpr1\fR \-o \fIexpr2\fR"
1236 Or; \fIexpr2\fR is not evaluated if \fIexpr1\fR is true.
1238 .IP "\fIexpr1\fR \-or \fIexpr2\fR"
1239 Same as \fIexpr1\fR \-o \fIexpr2\fR, but not POSIX compliant.
1241 .IP "\fIexpr1\fR , \fIexpr2\fR"
1242 List; both \fIexpr1\fR and \fIexpr2\fR are always evaluated.  The
1243 value of \fIexpr1\fR is discarded; the value of the list is the value
1244 of \fIexpr2\fR. The comma operator can be useful for searching for
1245 several different types of thing, but traversing the filesystem
1246 hierarchy only once.  The
1247 .B \-fprintf  
1248 action can be used to list the various matched items into several
1249 different output files.
1252 .SH "STANDARDS CONFORMANCE"
1253 For closest compliance to the POSIX standard, you should set the
1254 POSIXLY_CORRECT environment variable.  The following options are
1255 specified in the POSIX standard (IEEE Std 1003.1, 2003 Edition):
1257 .IP \fB\-H\fR
1258 This option is supported.
1260 .IP \fB\-L\fR
1261 This option is supported.
1263 .IP \fB\-name\fR
1264 This option is supported, but POSIX conformance depends on the 
1265 POSIX conformance of the system's 
1266 .BR fnmatch (3) 
1267 library function.  As of findutils-4.2.2, shell metacharacters
1268 (`*', `?' or `[]' for example) will match a leading `.', because 
1269 IEEE PASC interpretation 126 requires this.   This is a change from
1270 previous versions of findutils.
1272 .IP \fB\-type\fR
1273 Supported.   POSIX specifies `b', `c', `d', `l', `p', `f' and `s'.
1274 GNU find also supports `D', representing a Door, where the OS provides these.
1276 .IP \fB\-ok\fR
1277 Supported.   Interpretation of the response is not locale-dependent
1278 (see ENVIRONMENT VARIABLES).
1280 .IP \fB\-newer\fR
1281 Supported.  If the file specified is a symbolic link, it is always
1282 dereferenced.  This is a change from previous behaviour, which used to 
1283 take the relevant time from the symbolic link; see the HISTORY section
1284 below.
1286 .IP \fB\-perm\fR
1287 Supported.  If the POSIXLY_CORRECT environment variable is not set,
1288 some mode arguments (for example +a+x) which are not valid in POSIX
1289 are supported for backward-compatibility.
1291 .IP "Other predicates"
1292 The predicates
1293 .BR \-atime ,
1294 .BR \-ctime ,
1295 .BR \-depth ,
1296 .BR \-group ,
1297 .BR \-links ,
1298 .BR \-mtime ,
1299 .BR \-nogroup ,
1300 .BR \-nouser ,
1301 .BR \-print ,
1302 .BR \-prune ,
1303 .BR \-size ,
1304 .BR \-user  
1305 and 
1306 .B \-xdev
1307 are all supported.
1310 The POSIX standard specifies parentheses `(', `)', negation `!' and the
1311 `and' and `or' operators (`\-a', `\-o').   
1313 All other options, predicates, expressions and so forth are extensions 
1314 beyond the POSIX standard.  Many of these extensions are not unique to 
1315 GNU find, however.
1317 The POSIX standard requires that 
1318 .B find 
1319 detects loops:
1321 The 
1322 .B find
1323 utility shall detect infinite loops; that is, entering a
1324 previously visited directory that is an ancestor of the last file
1325 encountered. When it detects an infinite loop, find shall write a
1326 diagnostic message to standard error and shall either recover its
1327 position in the hierarchy or terminate.
1329 GNU 
1330 .B find 
1331 complies with these requirements.  The link count of
1332 directories which contain entries which are hard links to an ancestor
1333 will often be lower than they otherwise should be.  This can mean that
1334 GNU find will sometimes optimise away the visiting of a subdirectory
1335 which is actually a link to an ancestor.  Since
1336 .B find
1337 does not actually enter such a subdirectory, it is allowed to avoid
1338 emitting a diagnostic message.  Although this behaviour may be
1339 somewhat confusing, it is unlikely that anybody actually depends on
1340 this behaviour.  If the leaf optimisation has been turned off with
1341 .BR \-noleaf ,
1342 the directory entry will always be examined and the diagnostic message
1343 will be issued where it is appropriate.  Symbolic links cannot be used
1344 to create filesystem cycles as such, but if the \-L option or the
1345 \-follow option is in use, a diagnostic message is issued when 
1346 .B find 
1347 encounters a loop of symbolic links.  As with loops containing hard
1348 links, the leaf optimisation will often mean that 
1349 .B find
1350 knows that it doesn't need to call 
1351 .I stat()
1353 .I chdir() 
1354 on the symbolic link, so this diagnostic is frequently not necessary.
1356 The \-d option is supported for compatibility with various BSD systems,
1357 but you should use the POSIX-compliant option \-depth instead.
1359 The POSIXLY_CORRECT environment variable does not affect the behaviour
1360 of the \-regex or \-iregex tests because those tests aren't specified in
1361 the POSIX standard.
1362 .SH "ENVIRONMENT VARIABLES"
1364 .IP LANG
1365 Provides a default value for the internationalization variables that
1366 are unset or null.
1368 .IP LC_ALL
1369 If set to a non-empty string value, override the values of all the
1370 other internationalization variables.
1372 .IP LC_COLLATE
1373 The POSIX standard specifies that this variable affects the pattern
1374 matching to be used for the `\-name' option.   GNU find uses the 
1375 .BR fnmatch (3) 
1376 library function, and so support for `LC_COLLATE' depends on the
1377 system library.    
1380 POSIX also specifies that the `LC_COLLATE' environment 
1381 variable affects the interpretation of the user's response to the 
1382 query issued by `\-ok', but this is not the case for GNU find.
1384 .IP LC_CTYPE 
1385 This variable affects the treatment of character classes used with 
1386 the `\-name' test, if the system's 
1387 .BR fnmatch (3) 
1388 library function supports this.   It has no effect on the behaviour 
1389 of the `\-ok' expression.
1391 .IP LC_MESSAGES
1392 Determines the locale to be used for internationalised messages.
1394 .IP NLSPATH
1395 Determines the location of the internationalisation message catalogues.
1397 .IP PATH
1398 Affects the directories which are searched to find the executables 
1399 invoked by `\-exec', `\-execdir', `\-ok' and `\-okdir'.
1401 .IP POSIXLY_CORRECT
1402 Determines the block size used by 
1403 .B \-ls
1404 and 
1405 .BR \-fls . 
1406 If 
1407 .B POSIXLY_CORRECT
1408 is set, blocks are units of 512 bytes.  Otherwise
1409 they are units of 1024 bytes.   
1411 Setting this variable also turns off
1412 warning messages (that is, implies
1413 .BR \-nowarn )
1414 by default, because POSIX requires that apart from
1415 the output for 
1416 .BR \-ok ,
1417 all messages printed on stderr are diagnositcs and must result in a
1418 non-zero exit status.
1420 When POSIXLY_CORRECT is not set, 
1421 .B \-perm
1422 +zzz
1423 is treated just like 
1424 .B \-perm 
1425 /zzz
1426 if 
1427 +zzz is not a valid symbolic mode.  When POSIXLY_CORRECT is set, such
1428 constructs are treated as an error.
1430 .IP TZ
1431 Affects the time zone used for some of the time-related format
1432 directives of \-printf and \-fprintf.
1433 .SH "EXAMPLES"
1435 .B find /tmp \-name core \-type f \-print | xargs /bin/rm \-f
1438 Find files named 
1439 .B core
1440 in or below the directory 
1441 .B /tmp 
1442 and delete them.  Note that this will work incorrectly if there are 
1443 any filenames containing newlines, single or double quotes, or spaces.
1445 .B find /tmp \-name core \-type f \-print0 | xargs \-0 /bin/rm \-f
1448 Find files named 
1449 .B core
1450 in or below the directory 
1451 .B /tmp 
1452 and delete them, processing filenames in such a way that file or
1453 directory names containing single or double quotes, spaces or newlines
1454 are correctly handled.  The
1455 .B \-name 
1456 test comes before the 
1457 .B \-type
1458 test in order to avoid having to call 
1459 .B stat(2) 
1460 on every file.
1464 .B find . \-type f \-exec file \(aq{}\(aq \e\;
1467 Runs `file' on every file in or below the current directory.  Notice
1468 that the braces are enclosed in single quote marks to protect them
1469 from interpretation as shell script punctuation.  The semicolon is
1470 similarly protected by the use of a backslash, though single quotes
1471 could have been used in that case also.
1475 .B find /  \e
1476 .B \e( \-perm \-4000 \-fprintf /root/suid.txt "%#m %u %p\en" \e) , \e
1477 .B \e( \-size +100M \-fprintf /root/big.txt  "%\-10s %p\en" \e)
1480 Traverse the filesystem just once, listing setuid files and
1481 directories into
1482 .B /root/suid.txt
1483 and large files into 
1484 .BR /root/big.txt .
1488 .B find $HOME  \-mtime 0
1491 Search for files in your home directory which have been modified in
1492 the last twenty-four hours.  This command works this way because the
1493 time since each file was last modified is divided by 24 hours and any 
1494 remainder is discarded.  That means that to match 
1495 .B \-mtime 
1496 .BR 0 ,
1497 a file will have to have a modification in the past which is less than
1498 24 hours ago.
1502 .B find /sbin /usr/sbin -executable \e! -readable \-print
1505 Search for files which are executable but not readable.
1509 .B find . \-perm 664
1512 Search for files which have read and write permission for their owner,
1513 and group, but which other users can read but not write to.  Files
1514 which meet these criteria but have other permissions bits set (for
1515 example if someone can execute the file) will not be matched.
1519 .B find . \-perm \-664
1522 Search for files which have read and write permission for their owner
1523 and group, and which other users can read, without regard to the
1524 presence of any extra permission bits (for example the executable
1525 bit).  This will match a file which has mode 0777, for example.
1529 .B find . \-perm /222
1532 Search for files which are writable by somebody (their owner, or
1533 their group, or anybody else).
1537 .B find . \-perm /220
1538 .B find . \-perm /u+w,g+w
1539 .B find . \-perm /u=w,g=w
1542 All three of these commands do the same thing, but the first one uses
1543 the octal representation of the file mode, and the other two use the
1544 symbolic form.  These commands all search for files which are
1545 writable by either their owner or their group.  The files don't have
1546 to be writable by both the owner and group to be matched; either will
1551 .B find . \-perm \-220
1552 .B find . \-perm \-g+w,u+w
1555 Both these commands do the same thing; search for files which are
1556 writable by both their owner and their group.
1560 .B find . \-perm \-444 \-perm /222 ! \-perm /111
1561 .B find . \-perm \-a+r \-perm /a+w ! \-perm /a+x
1564 These two commands both search for files that are readable for
1565 everybody (\-perm \-444 or \-perm \-a+r), have at least on write bit
1566 set (\-perm /222 or \-perm /a+w) but are not executable for anybody (!
1567 \-perm /111 and ! \-perm /a+x respectively)
1571 .B cd /source-dir
1572 .B find . \-name .snapshot \-prune \-o \e( \e! \-name "*~" \-print0 \e)|
1573 .B cpio \-pmd0   /dest-dir
1575 .fi 
1576 This command copies the contents of 
1577 .B /source-dir
1578 to 
1579 .BR /dest-dir ,
1580 but omits files and directories named 
1581 .B .snapshot 
1582 (and anything in them).  It also omits files or directories whose name
1583 ends in
1584 .BR ~ ,
1585 but not their contents.  The construct 
1586 .B \-prune \-o \e( ... \-print0 \e)
1587 is quite common.  The idea here is that the expression before 
1588 .B \-prune 
1589 matches things which are to be pruned.  However, the 
1590 .B \-prune 
1591 action itself returns true, so the following 
1592 .B \-o 
1593 ensures that the right hand side is evaluated only for those
1594 directories which didn't get pruned (the contents of the pruned
1595 directories are not even visited, so their contents are irrelevant).
1596 The expression on the right hand side of the 
1597 .B \-o
1598 is in parentheses only for clarity.  It emphasises that the
1599 .B \-print0 
1600 action takes place only for things that didn't have 
1601 .B \-prune 
1602 applied to them.  Because the default `and' condition between tests
1603 binds more tightly than 
1604 .BR \-o ,
1605 this is the default anyway, but the parentheses help to show
1606 what is going on.
1608 .SH EXIT STATUS
1610 .B find
1611 exits with status 0 if all files are processed successfully, greater
1612 than 0 if errors occur.   This is deliberately a very broad
1613 description, but if the return value is non-zero, you should not rely
1614 on the correctness of the results of 
1615 .BR find .
1617 .SH "SEE ALSO"
1618 \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1), \fBxargs\fP(1),
1619 \fBchmod\fP(1), \fBfnmatch\fP(3), \fBregex\fP(7), \fBstat\fP(2),
1620 \fBlstat\fP(2), \fBls\fP(1), \fBprintf\fP(3), \fBstrftime\fP(3),
1621 \fBctime\fP(3), \fBFinding Files\fP (on-line in Info, or printed).
1622 .SH "HISTORY"
1623 As of findutils-4.2.2, shell metacharacters (`*', `?' or `[]' for
1624 example) used in filename patterns will match a leading `.', because
1625 IEEE POSIX interpretation 126 requires this.
1627 The syntax 
1628 \.B \-perm +MODE 
1629 was deprecated in findutils-4.2.21, in favour of
1630 \.B \-perm 
1631 .BR /MODE .
1632 As of findutils-4.3.3, 
1633 .B \-perm /000
1634 now matches all files instead of none.  
1636 Nanosecond-resolution
1637 timestamps were implemented in findutils-4.3.3.
1639 As of findutils-4.3.11, the 
1640 .B \-delete 
1641 action sets 
1642 .BR find 's 
1643 exit status to a nonzero value when it fails.
1644 However, 
1645 .B find
1646 will not exit immediately.  Previously, 
1647 .BR find 's 
1648 exit status was unaffected by the failure of 
1649 .BR \-delete .
1651 l l l .
1652 Feature Added in        Also occurs in 
1653 \-newerXY       4.3.3   BSD
1654 \-D     4.3.1
1655 \-O     4.3.1
1656 \-readable      4.3.0
1657 \-writable      4.3.0
1658 \-executable    4.3.0
1659 \-regextype     4.2.24
1660 \-exec ... +    4.2.12  POSIX
1661 \-execdir       4.2.12  BSD
1662 \-okdir 4.2.12
1663 \-samefile      4.2.11
1664 \-H     4.2.5   POSIX
1665 \-L     4.2.5   POSIX
1666 \-P     4.2.5   BSD
1667 \-delete        4.2.3   
1668 \-quit  4.2.3
1669 \-d     4.2.3   BSD
1670 \-wholename     4.2.0
1671 \-iwholename    4.2.0
1672 \-ignore_readdir_race   4.2.0
1673 \-fls   4.0
1674 \-ilname        3.8
1675 \-iname 3.8
1676 \-ipath 3.8
1677 \-iregex        3.8
1679 .SH "NON-BUGS"
1681 .B $ find . \-name *.c \-print
1682 find: paths must precede expression
1683 Usage: find [\-H] [\-L] [\-P] [\-Olevel] [\-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
1686 This happens because 
1687 .I *.c 
1688 has been expanded by the shell
1689 resulting in 
1690 .B find
1691 actually receiving a command line like this:
1694 .B find . \-name bigram.c code.c frcode.c locate.c \-print
1697 That command is of course not going to work.  Instead of doing things
1698 this way, you should enclose the pattern in quotes or escape the wildcard:
1700 .B $ find . \-name \e*.c \-print
1703 .SH "BUGS"
1705 There are security problems inherent in the behaviour that the POSIX
1706 standard specifies for
1707 .BR find ,
1708 which therefore cannot be fixed.  For example, the \-exec action is
1709 inherently insecure, and \-execdir should be used instead.  
1710 Please see \fBFinding Files\fP for more information. 
1712 The environment variable 
1713 .B  LC_COLLATE
1714 has no effect on the 
1715 .B \-ok 
1716 action.
1717 .P 
1718 The best way to report a bug is to use the form at
1719 http://savannah.gnu.org/bugs/?group=findutils.  
1720 The reason for this is that you will then be able to track progress in
1721 fixing the problem.   Other comments about \fBfind\fP(1) and about
1722 the findutils package in general can be sent to the 
1723 .I bug\-findutils
1724 mailing list.  To join the list, send email to 
1725 .IR bug\-findutils\-request@gnu.org .