Merged changes from the 4.2.x branch
[findutils.git] / find / find.1
blobccb94a32610833cda28ec91752c122fd0c39e947
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] [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 `!'.  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 three
44 `real' options `\-H', `\-L' and `\-P' must appear before the first
45 path name, if at all.
46 .IP \-P
47 Never follow symbolic links.  This is the default behaviour.  When 
48 .B find
49 examines or prints information a file, and the file is a symbolic
50 link, the information used shall be taken from the properties of the
51 symbolic link itself.  
53 .IP \-L
54 Follow symbolic links.  When 
55 .B find
56 examines or prints information about files, the information used shall
57 be taken from the properties of the file to which the link points, not
58 from the link itself (unless it is a broken symbolic link or 
59 .B find
60 is unable to examine the file to which the link points).  Use of this
61 option implies \-noleaf.  If you later use the \-P option, \-noleaf
62 will still be in effect.  If \-L is in effect and 
63 .B find 
64 discovers a symbolic link to a subdirectory during its search, 
65 the subdirectory pointed to by the symbolic link will be searched.
66 .IP
67 When the \-L option is in effect, the \-type predicate will always
68 match against the type of the file that a symbolic link points to
69 rather than the link itself (unless the symbolic link is broken).
70 Using \-L causes the \-lname and \-ilname predicates always to return
71 false.
73 .IP \-H
74 Do not follow symbolic links, except while processing the command
75 line arguments.  When
76 .B find
77 examines or prints information about files, the information used 
78 shall be taken from the properties of the symbolic link itself.   The
79 only exception to this behaviour is when a file specified on the
80 command line is a symbolic link, and the link can be resolved.  For
81 that situation, the information used is taken from whatever the link
82 points to (that is, the link is followed).  The information about the
83 link itself is used as a fallback if the file pointed to by the
84 symbolic link cannot be examined.  If \-H is in effect and one of the
85 paths specified on the command line is a symbolic link to a directory,
86 the contents of that directory will be examined (though of course
87 \-maxdepth 0 would prevent this).
89 If more than one of \-H, \-L and \-P is specified, each overrides the
90 others; the last one appearing on the command line takes effect.
91 Since it is the default, the \-P option should be considered to be in
92 effect unless either \-H or \-L is specified.
94 GNU 
95 .B find
96 frequently stats files during the processing of the command line
97 itself, before any searching has begun.  These options also affect how
98 those arguments are processed.  Specifically, there are a number of
99 tests that compare files listed on the command line against a file we
100 are currently considering.  In each case, the file specified on the
101 command line will have been examined and some of its properties will
102 have been saved.  If the named file is in fact a symbolic link, and
103 the \-P option is in effect (or if neither \-H nor \-L were
104 specified), the information used for the comparison will be taken from
105 the properties of the symbolic link.  Otherwise, it will be taken from
106 the properties of the file the link points to.  If
107 .B find 
108 cannot follow the link (for example because it has insufficient
109 privileges or the link points to a nonexistent file) the properties of
110 the link itself will be used.
112 When the \-H or \-L options are in effect, any symbolic links listed
113 as the argument of \-newer will be dereferenced, and the timestamp
114 will be taken from the file to which the symbolic link points.  The
115 same consideration applies to \-anewer and \-cnewer.
117 The \-follow option has a similar effect to \-L, though it takes
118 effect at the point where it appears (that is, if \-L is not used but
119 \-follow is, any symbolic links appearing after \-follow on the
120 command line will be dereferenced, and those before it will not).
123 .SH EXPRESSIONS
124 The expression is made up of options (which affect overall operation
125 rather than the processing of a specific file, and always return
126 true), tests (which return a true or false value), and actions (which
127 have side effects and return a true or false value), all separated by
128 operators.  \-and is assumed where the operator is omitted.  
130 If the expression contains no actions other than \-prune, \-print is
131 performed on all files for which the expression is true.
133 .SS OPTIONS
135 All options always return true.  Except for \-follow and \-daystart,
136 they always take effect, rather than being processed only when their
137 place in the expression is reached.  Therefore, for clarity, it is
138 best to place them at the beginning of the expression.  A warning is
139 issued if you don't do this.
140 .IP \-daystart
141 Measure times (for \-amin, \-atime, \-cmin, \-ctime, \-mmin, and \-mtime)
142 from the beginning of today rather than from 24 hours ago.  This
143 option only affects tests which appear later on the command line.
144 .IP \-depth
145 Process each directory's contents before the directory itself.
146 .IP \-d
147 A synonym for \-depth, for compatibility with FreeBSD, NetBSD, MacOS X and OpenBSD.
148 .IP \-follow
149 Deprecated; use the \-L option instead.  Dereference symbolic links.
150 Implies \-noleaf.  Unless the \-H or \-L option has been specified,
151 the position of the \-follow option changes the behaviour of the
152 \-newer predicate; any files listed as the argument of \-newer will be
153 dereferenced if they are symbolic links.  The same consideration
154 applies to \-anewer and \-cnewer.  Similarly, the \-type predicate
155 will always match against the type of the file that a symbolic link
156 points to rather than the link itself.  Using \-follow causes the
157 \-lname and \-ilname predicates always to return false.
158 .IP "\-help, \-\-help"
159 Print a summary of the command-line usage of
160 .B find
161 and exit.
162 .IP \-ignore_readdir_race
163 Normally, \fBfind\fR will emit an error message when it fails to stat a file.
164 If you give this option and a file is deleted between the time \fBfind\fR 
165 reads the name of the file from the directory and the time it tries to stat 
166 the file, no error message will be issued.    This also applies to files
167 or directories whose names are given on the command line.  This option takes
168 effect at the time the command line is read, which means that you cannot search
169 one part of the filesystem with this option on and part of it with this option
170 off (if you need to do that, you will need to issue two \fBfind\fR commands
171 instead, one with the option and one without it).
172 .IP "\-maxdepth \fIlevels\fR"
173 Descend at most \fIlevels\fR (a non-negative integer) levels of
174 directories below the command line arguments.  `\-maxdepth 0' means
175 only apply the tests and actions to the command line arguments.
176 .IP "\-mindepth \fIlevels\fR"
177 Do not apply any tests or actions at levels less than \fIlevels\fR (a
178 non-negative integer).  `\-mindepth 1' means process all files except
179 the command line arguments.
180 .IP \-mount
181 Don't descend directories on other filesystems.  An alternate name for
182 \-xdev, for compatibility with some other versions of
183 .BR find .
184 .IP \-noignore_readdir_race
185 Turns off the effect of \-ignore_readdir_race. 
186 .IP "\-noleaf"
187 Do not optimize by assuming that directories contain 2 fewer
188 subdirectories than their hard link count.  This option is needed when
189 searching filesystems that do not follow the Unix directory-link
190 convention, such as CD-ROM or MS-DOS filesystems or AFS volume mount
191 points.  Each directory on a normal Unix filesystem has at least 2
192 hard links: its name and its `.'  entry.  Additionally, its
193 subdirectories (if any) each have a `..'  entry linked to that
194 directory.  When
195 .B find
196 is examining a directory, after it has statted 2 fewer subdirectories
197 than the directory's link count, it knows that the rest of the entries
198 in the directory are non-directories (`leaf' files in the directory
199 tree).  If only the files' names need to be examined, there is no need
200 to stat them; this gives a significant increase in search speed.
201 .IP "\-readable, \-writable, \-executable"
202 Matches files which are readable, writable and executable,
203 respectively.  This takes into account access control lists and other
204 permissions artefacts which the \-perm test ignores.  This test makes
205 use of the
206 .BR access (2)
207 system call, and so can be fooled by NFS servers which do UID
208 mapping (or root-squashing), since many systems implement 
209 .BR access (2) 
210 in the client's kernel and so cannot make use of the UID mapping
211 information held on the server.
212 .IP "\-regextype \fItype\fR"
213 Changes the regular expression syntax understood by 
214 .B \-regex
215 and 
216 .B \-iregex
217 tests which occur later on the command line.  Currently-implemented
218 types are emacs (this is the default), posix-awk, posix-basic,
219 posix-egrep and posix-extended.
221 .IP "\-version, \-\-version"
222 Print the \fBfind\fR version number and exit.
223 .IP "\-warn, \-nowarn"
224 Turn warning messages on or off.  These warnings apply only to the
225 command line usage, not to any conditions that 
226 .B find 
227 might encounter when it searches directories.  The default behaviour
228 corresponds to \-warn if standard input is a tty, and to \-nowarn
229 otherwise.
230 .IP \-xdev
231 Don't descend directories on other filesystems.
233 .SS TESTS
235 Numeric arguments can be specified as
236 .IP \fI+n\fP
237 for greater than
238 .IR n ,
239 .IP \fI\-n\fP
240 for less than
241 .IR n ,
242 .IP \fIn\fP
243 for exactly
244 .IR n .
245 .IP "\-amin \fIn\fR"
246 File was last accessed \fIn\fR minutes ago.
247 .IP "\-anewer \fIfile\fR"
248 File was last accessed more recently than \fIfile\fR was modified.  If
249 \fIfile\fR is a symbolic link and the \-H option or the \-L option is
250 in effect, the access time of the file it points to is always
251 used.
252 .IP "\-atime \fIn\fR"
253 File was last accessed \fIn\fR*24 hours ago.  
254 When find figures out how many 24-hour periods ago the file 
255 was last accessed, any fractional part is ignored, so to match 
256 .B \-atime 
257 .BR +1 ,
258 a file has to have been accessed at least 
259 .I two
260 days ago.
261 .IP "\-cmin \fIn\fR"
262 File's status was last changed \fIn\fR minutes ago.
263 .IP "\-cnewer \fIfile\fR"
264 File's status was last changed more recently than \fIfile\fR was
265 modified.  If \fIfile\fR is a symbolic link and the \-H option or the
266 \-L option is in effect, the status-change time of the file it points
267 to is always used.
269 .IP "\-ctime \fIn\fR"
270 File's status was last changed \fIn\fR*24 hours ago.
271 See the comments for 
272 .B \-atime 
273 to understand how rounding affects the interpretation of file status
274 change times.
275 .IP \-empty
276 File is empty and is either a regular file or a directory.
277 .IP \-false
278 Always false.
279 .IP "\-fstype \fItype\fR"
280 File is on a filesystem of type \fItype\fR.  The valid filesystem
281 types vary among different versions of Unix; an incomplete list of
282 filesystem types that are accepted on some version of Unix or another
283 is: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K.  You can use \-printf
284 with the %F directive to see the types of your filesystems.
285 .IP "\-gid \fIn\fR"
286 File's numeric group ID is \fIn\fR.
287 .IP "\-group \fIgname\fR"
288 File belongs to group \fIgname\fR (numeric group ID allowed).
289 .IP "\-ilname \fIpattern\fR"
290 Like \-lname, but the match is case insensitive.
291 If the \-L option or the \-follow option is in effect, this test 
292 returns false unless the symbolic link is broken.
293 .IP "\-iname \fIpattern\fR"
294 Like \-name, but the match is case insensitive.  For example, the
295 patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo',
296 `fOo', etc.   In these patterns, unlike filename expansion by the
297 shell, an initial '.' can be matched by '*'.  That is, 
298 .B find \-name *bar 
299 will match the file `.foobar'.   Please note that you should quote
300 patterns as a matter of course, otherwise the shell will expand any
301 wildcard characters in them.
303 .IP "\-inum \fIn\fR"
304 File has inode number \fIn\fR.  It is normally easier to use the 
305 .B \-samefile
306 test instead.
307 .IP "\-ipath \fIpattern\fR"
308 Behaves in the same way as \-iwholename.  This option is deprecated,
309 so please do not use it.
310 .IP "\-iregex \fIpattern\fR"
311 Like \-regex, but the match is case insensitive.
312 .IP "\-iwholename \fIpattern\fR"
313 Like \-wholename, but the match is case insensitive.
314 .IP "\-links \fIn\fR"
315 File has \fIn\fR links.
316 .IP "\-lname \fIpattern\fR"
317 File is a symbolic link whose contents match shell pattern
318 \fIpattern\fR.  The metacharacters do not treat `/' or `.' specially.
319 If the \-L option or the \-follow option is in effect, this test 
320 returns false unless the symbolic link is broken.
321 .IP "\-mmin \fIn\fR"
322 File's data was last modified \fIn\fR minutes ago.
323 .IP "\-mtime \fIn\fR"
324 File's data was last modified \fIn\fR*24 hours ago.
325 See the comments for 
326 .B \-atime 
327 to understand how rounding affects the interpretation of file
328 modification times.
329 .IP "\-name \fIpattern\fR"
330 Base of file name (the path with the leading directories removed)
331 matches shell pattern \fIpattern\fR.  The metacharacters (`*', `?',
332 and `[]') match a `.' at the start of the base name (this is a change
333 in findutils-4.2.2; see section STANDARDS CONFORMANCE below).  To ignore a
334 directory and the files under it, use \-prune; see an example in the
335 description of \-wholename.  Braces are not recognised as being
336 special, despite the fact that some shells including Bash imbue braces
337 with a special meaning in shell patterns.  The filename matching is
338 performed with the use of the
339 .BR fnmatch (3) 
340 library function.   Don't forget to enclose the pattern in quotes 
341 in order to protect it from expansion by the shell.
343 .IP "\-newer \fIfile\fR"
344 File was modified more recently than \fIfile\fR.  If \fIfile\fR is a
345 symbolic link and the \-H option or the \-L option is in effect, the
346 modification time of the file it points to is always used.
347 .IP \-nouser
348 No user corresponds to file's numeric user ID.
349 .IP \-nogroup
350 No group corresponds to file's numeric group ID.
351 .IP "\-path \fIpattern\fR"
352 See \-wholename.   The predicate \-path is also supported by HP-UX 
353 .BR find .
354 .IP "\-perm \fImode\fR"
355 File's permission bits are exactly \fImode\fR (octal or symbolic).
356 Since an exact match is required, if you want to use this form for
357 symbolic modes, you may have to specify a rather complex mode string.
358 For example '\-perm g=w' will only match files which have mode 0020
359 (that is, ones for which group write permission is the only permission
360 set).  It is more likely that you will want to use the '/' or '-'
361 forms, for example '\-perm \-g=w', which matches any file with group
362 write permission.  See the
363 .B EXAMPLES 
364 section for some illustrative examples.
365 .IP "\-perm \-\fImode\fR"
366 All of the permission bits \fImode\fR are set for the file.
367 Symbolic modes are accepted in this form, and this is usually the way
368 in which would want to use them.  You must specify 'u', 'g' or 'o' if
369 you use a symbolic mode.   See the 
370 .B EXAMPLES 
371 section for some illustrative examples.
372 .IP "\-perm /\fImode\fR"
373 Any of the permission bits \fImode\fR are set for the file.  Symbolic
374 modes are accepted in this form.  You must specify 'u', 'g' or 'o' if
375 you use a symbolic mode.  See the
376 .B EXAMPLES 
377 section for some illustrative examples.
378 .IP "\-perm +\fImode\fR"
379 Deprecated, old way of searching for files with any of the permission
380 bits in \fImode\fR set.  You should use
381 .B \-perm \fI/mode\fR
382 instead. Trying to use the '+' syntax with symbolic modes will yield
383 surprising results.  For example, '+u+x' is a valid symbolic mode
384 (equivalent to +u,+x, i.e. 0111) and will therefore not be evaluated
386 .B \-perm +\fImode\fR
387 but instead as the exact mode specifier
388 .B \-perm \fImode\fR
389 and so it matches files with exact permissions 0111 instead of files with any
390 execute bit set.  If you found this paragraph confusing, you're not
391 alone - just use 
392 .B \-perm /\fImode\fR.
393 This form of the 
394 .B \-perm
395 test is deprecated because the POSIX specification requires the
396 interpretation of a leading '+' as being part of a symbolic mode, and
397 so we switched to using '/' instead.
399 .IP "\-regex \fIpattern\fR"
400 File name matches regular expression \fIpattern\fR.  This is a match
401 on the whole path, not a search.  For example, to match a file named
402 `./fubar3', you can use the regular expression `.*bar.' or `.*b.*3',
403 but not `f.*r3'.  The regular expressions understood by 
404 .B find 
405 are by default Emacs Regular Expressions, but this can be
406 changed with the 
407 .B \-regextype 
408 option.
409 .IP "\-samefile \fIname\fR"
410 File refers to the same inode as \fIname\fR.   When \-L is in effect,
411 this can include symbolic links.
412 .IP "\-size \fIn\fR[cwbkMG]"
413 File uses \fIn\fP units of space.  The following suffixes 
414 can be used:
416 .IP `b' 
417 for 512-byte blocks (this is the default if no suffix is used)
418 .IP `c' 
419 for bytes
420 .IP `w' 
421 for two-byte words
422 .IP `k' 
423 for Kilobytes (units of 1024 bytes)
424 .IP `M' 
425 for Megabytes (units of 1048576 bytes)
426 .IP `G' 
427 for Gigabytes (units of 1073741824 bytes)
430 The size does not count indirect blocks, but it does count blocks in
431 sparse files that are not actually allocated.  Bear in mind that the
432 `%k' and `%b' format specifiers of \-printf handle sparse files
433 differently.  The `b' suffix always denotes 512-byte blocks and never
434 1 Kilobyte blocks, which is different to the behaviour of \-ls.
436 .IP \-true
437 Always true.
438 .IP "\-type \fIc\fR"
439 File is of type \fIc\fR:
441 .IP b
442 block (buffered) special
443 .IP c
444 character (unbuffered) special
445 .IP d
446 directory
447 .IP p
448 named pipe (FIFO)
449 .IP f
450 regular file
451 .IP l
452 symbolic link; this is never true if the \-L option or the \-follow
453 option is in effect, unless the symbolic link is broken.  If you want
454 to search for symbolic links when \-L is in effect, use \-xtype.
455 .IP s
456 socket
457 .IP D
458 door (Solaris)
460 .IP "\-uid \fIn\fR"
461 File's numeric user ID is \fIn\fR.
462 .IP "\-used \fIn\fR"
463 File was last accessed \fIn\fR days after its status was last changed.
464 .IP "\-user \fIuname\fR"
465 File is owned by user \fIuname\fR (numeric user ID allowed).
466 .IP "\-wholename \fIpattern\fR"
467 File name matches shell pattern \fIpattern\fR.  The metacharacters do
468 not treat `/' or `.' specially; so, for example,
470 .in +1i
471 find . \-wholename './sr*sc'
473 .in -1i
474 will print an entry for a directory called './src/misc' (if one
475 exists).  To ignore a whole directory tree, use \-prune rather than
476 checking every file in the tree.  For example, to skip the
477 directory `src/emacs' and all files and directories under it, and
478 print the names of the other files found, do something like this:
480 .in +1i
481 find . \-wholename './src/emacs' \-prune \-o \-print
483 .in -1i
484 .IP "\-xtype \fIc\fR"
485 The same as \-type unless the file is a symbolic link.  For symbolic
486 links: if the \-H or \-P option was specified, true if the file is a
487 link to a file of type \fIc\fR; if the \-L option has been given, true
488 if \fIc\fR is `l'.  In other words, for symbolic links, \-xtype checks
489 the type of the file that \-type does not check.
491 .SS ACTIONS
492 .IP "\-delete\fR"
493 Delete files; true if removal succeeded.  If the removal failed, an
494 error message is issued.  Use of this action automatically turns on
495 the '\-depth' option.
497 .IP "\-exec \fIcommand\fR ;"
498 Execute \fIcommand\fR; true if 0 status is returned.  All following
499 arguments to
500 .B find
501 are taken to be arguments to the command until an argument consisting
502 of `;' is encountered.  The string `{}' is replaced by the current
503 file name being processed everywhere it occurs in the arguments to the
504 command, not just in arguments where it is alone, as in some versions
506 .BR find .
507 Both of these constructions might need to be escaped (with a `\e') or
508 quoted to protect them from expansion by the shell.  See the
509 .B EXAMPLES
510 section for examples of the use of the `\-exec' option.  The specified
511 command is run once for each matched file.
512 The command is executed in the starting directory.   There are
513 unavoidable security problems surrounding use of the \-exec option;
514 you should use the \-execdir option instead.  
516 .IP "\-exec \fIcommand\fR {} +"
517 This variant of the \-exec option runs the specified command on the
518 selected files, but the command line is built by appending each
519 selected file name at the end; the total number of invocations of the
520 command will be much less than the number of matched files.  The
521 command line is built in much the same way that
522 .B xargs
523 builds its command lines.  Only one instance of '{}' is allowed within
524 the command.  The command is executed in the starting directory.
526 .IP "\-execdir \fIcommand\fR ;"
527 .IP "\-execdir \fIcommand\fR {} +"
528 Like \-exec, but the specified command is run from the subdirectory
529 containing the matched file, which is not normally the directory in
530 which you started 
531 .BR find .
532 This a much more secure method for invoking commands, as it avoids
533 race conditions during resolution of the paths to the matched files.
534 As with the \-exec option, the '+' form of \-execdir will build a
535 command line to process more than one matched file, but any given
536 invocation of
537 .I command 
538 will only list files that exist in the same subdirectory.  If you use
539 this option, you must ensure that your 
540 .B $PATH
541 environment variable does not reference the current directory;
542 otherwise, an attacker can run any commands they like by leaving an
543 appropriately-named file in a directory in which you will run
544 \-execdir.
546 .IP "\-fls \fIfile\fR"
547 True; like \-ls but write to \fIfile\fR like \-fprint.
548 The output file is always created, even if the predicate is never
549 matched.  
550 See the
551 .B UNUSUAL FILENAMES
552 section for information about how unusual characters in filenames are handled.
554 .IP "\-fprint \fIfile\fR"
555 True; print the full file name into file \fIfile\fR.  If \fIfile\fR
556 does not exist when \fBfind\fR is run, it is created; if it does
557 exist, it is truncated.  The file names ``/dev/stdout'' and
558 ``/dev/stderr'' are handled specially; they refer to the standard
559 output and standard error output, respectively.
560 The output file is always created, even if the predicate is never matched.
561 See the
562 .B UNUSUAL FILENAMES
563 section for information about how unusual characters in filenames are handled.
564 .IP "\-fprint0 \fIfile\fR"
565 True; like \-print0 but write to \fIfile\fR like \-fprint.
566 The output file is always created, even if the predicate is never matched.
567 See the
568 .B UNUSUAL FILENAMES
569 section for information about how unusual characters in filenames are handled.
570 .IP "\-fprintf \fIfile\fR \fIformat\fR"
571 True; like \-printf but write to \fIfile\fR like \-fprint.
572 The output file is always created, even if the predicate is never matched.
573 See the
574 .B UNUSUAL FILENAMES
575 section for information about how unusual characters in filenames are handled.
576 .IP "\-ok \fIcommand\fR ;"
577 Like \-exec but ask the user first (on the standard input); if the
578 response does not start with `y' or `Y', do not run the command, and
579 return false.  If the command is run, its standard input is redirected
580 from
581 .BR /dev/null .
583 .IP \-print
584 True; print the full file name on the standard output, followed by a
585 newline.   If you are piping the output of 
586 .B find 
587 into another program and there is the faintest possibility that the files 
588 which you are searching for might contain a newline, then you should 
589 seriously consider using the `\-print0' option instead of `\-print'.
590 See the
591 .B UNUSUAL FILENAMES
592 section for information about how unusual characters in filenames are handled.
593 .IP "\-okdir \fIcommand\fR ;"
594 Like \-execdir but ask the user first (on the standard input); if the
595 response does not start with `y' or `Y', do not run the command, and
596 return false.  If the command is run, its standard input is redirected
597 from
598 .BR /dev/null .
599 .IP \-print0
600 True; print the full file name on the standard output, followed by a
601 null character (instead of the newline character that `\-print' uses).
602 This allows file names that contain newlines or other types of white
603 space to be correctly interpreted by programs that process the
604 \fBfind\fR output.  This option corresponds to the `\-0' option of
605 .BR xargs .
606 .IP "\-printf \fIformat\fR"
607 True; print \fIformat\fR on the standard output, interpreting `\e'
608 escapes and `%' directives.  Field widths and precisions can be
609 specified as with the `printf' C function.  Please note that many of
610 the fields are printed as %s rather than %d, and this may mean that
611 flags don't work as you might expect.  This also means that the `\-'
612 flag does work (it forces fields to be left-aligned).  Unlike \-print,
613 \-printf does not add a newline at the end of the string.  The escapes
614 and directives are:
616 .IP \ea
617 Alarm bell.
618 .IP \eb
619 Backspace.
620 .IP \ec
621 Stop printing from this format immediately and flush the output.
622 .IP \ef
623 Form feed.
624 .IP \en
625 Newline.
626 .IP \er
627 Carriage return.
628 .IP \et
629 Horizontal tab.
630 .IP \ev
631 Vertical tab.
632 .IP \e\0
633 ASCII NUL.
634 .IP \e\e
635 A literal backslash (`\e').
636 .IP \eNNN
637 The character whose ASCII code is NNN (octal).
639 A `\e' character followed by any other character is treated as an
640 ordinary character, so they both are printed.
641 .IP %%
642 A literal percent sign.
643 .IP %a
644 File's last access time in the format returned by the C `ctime' function.
645 .IP %A\fIk\fP
646 File's last access time in the format specified by \fIk\fR, which is
647 either `@' or a directive for the C `strftime' function.  The possible
648 values for \fIk\fR are listed below; some of them might not be
649 available on all systems, due to differences in `strftime' between
650 systems.  
652 .IP @
653 seconds since Jan. 1, 1970, 00:00 GMT.
655 Time fields:
656 .IP H
657 hour (00..23)
658 .IP I
659 hour (01..12)
660 .IP k
661 hour ( 0..23)
662 .IP l
663 hour ( 1..12)
664 .IP M
665 minute (00..59)
666 .IP p
667 locale's AM or PM
668 .IP r
669 time, 12-hour (hh:mm:ss [AP]M)
670 .IP S
671 second (00..61)
672 .IP T
673 time, 24-hour (hh:mm:ss)
674 .IP +
675 Date and time, separated by '+', for example `2004\-04\-28+22:22:05'.
676 The time is given in the current timezone (which may be affected by
677 setting the TZ environment variable).  This is a GNU extension.
678 .IP X
679 locale's time representation (H:M:S)
680 .IP Z
681 time zone (e.g., EDT), or nothing if no time zone is determinable
683 Date fields:
684 .IP a
685 locale's abbreviated weekday name (Sun..Sat)
686 .IP A
687 locale's full weekday name, variable length (Sunday..Saturday)
688 .IP b
689 locale's abbreviated month name (Jan..Dec)
690 .IP B
691 locale's full month name, variable length (January..December)
692 .IP c
693 locale's date and time (Sat Nov 04 12:02:33 EST 1989)
694 .IP d
695 day of month (01..31)
696 .IP D
697 date (mm/dd/yy)
698 .IP h
699 same as b
700 .IP j
701 day of year (001..366)
702 .IP m
703 month (01..12)
704 .IP U
705 week number of year with Sunday as first day of week (00..53)
706 .IP w
707 day of week (0..6)
708 .IP W
709 week number of year with Monday as first day of week (00..53)
710 .IP x
711 locale's date representation (mm/dd/yy)
712 .IP y
713 last two digits of year (00..99)
714 .IP Y
715 year (1970...)
717 .IP %b
718 The amount of disk space used for this file in 512-byte blocks. Since disk
719 space is allocated in multiples of the filesystem block size this is usually
720 greater than %s/1024, but it can also be smaller if the file is a sparse file.
721 .IP %c
722 File's last status change time in the format returned by the C `ctime'
723 function.
724 .IP %C\fIk\fP
725 File's last status change time in the format specified by \fIk\fR,
726 which is the same as for %A.
727 .IP %d
728 File's depth in the directory tree; 0 means the file is a command line
729 argument.
730 .IP %D
731 The device number on which the file exists (the st_dev field of struct
732 stat), in decimal.
733 .IP %f
734 File's name with any leading directories removed (only the last element).
735 .IP %F
736 Type of the filesystem the file is on; this value can be used for
737 \-fstype.
738 .IP %g
739 File's group name, or numeric group ID if the group has no name.
740 .IP %G
741 File's numeric group ID.
742 .IP %h
743 Leading directories of file's name (all but the last element).
744 If the file name contains no slashes (since it is in the current 
745 directory) the %h specifier expands to ".".
746 .IP %H
747 Command line argument under which file was found.
748 .IP %i
749 File's inode number (in decimal).
750 .IP %k
751 The amount of disk space used for this file in 1K blocks. Since disk space is
752 allocated in multiples of the filesystem block size this is usually greater
753 than %s/1024, but it can also be smaller if the file is a sparse file.
754 .IP %l
755 Object of symbolic link (empty string if file is not a symbolic link).
756 .IP %m
757 File's permission bits (in octal).  This option uses the 'traditional'
758 numbers which most Unix implementations use, but if your particular 
759 implementation uses an unusual ordering of octal permissions bits, you
760 will see a difference between the actual value of the file's mode and
761 the output of %m.   Normally you will want to have a leading
762 zero on this number, and to do this, you should use the 
763 .B #
764 flag (as in, for example, '%#m').
765 .IP %M 
766 File's permissions (in symbolic form, as for 
767 .BR ls ).  
768 This directive is supported in findutils 4.2.5 and later.
769 .IP %n
770 Number of hard links to file.
771 .IP %p
772 File's name.
773 .IP %P
774 File's name with the name of the command line argument under which
775 it was found removed.
776 .IP %s
777 File's size in bytes.
778 .IP %t
779 File's last modification time in the format returned by the C `ctime'
780 function.
781 .IP %T\fIk\fP
782 File's last modification time in the format specified by \fIk\fR, 
783 which is the same as for %A.
784 .IP %u
785 File's user name, or numeric user ID if the user has no name.
786 .IP %U
787 File's numeric user ID.
788 .IP %y
789 File's type (like in ls \-l), U=unknown type (shouldn't happen)
790 .IP %Y
791 File's type (like %y), plus follow symlinks: L=loop, N=nonexistent
793 A `%' character followed by any other character is discarded (but the
794 other character is printed).
796 The %m and %d directives support the 
797 .B #
799 .B 0 
800 and 
801 .B + 
802 flags, but the other directives do not, even if they
803 print numbers.  Numeric directives that do not support these flags
804 include 
805 .BR G , 
806 .BR U , 
807 .BR b , 
808 .BR D , 
809 .B  k 
810 and 
811 .BR n .
812 The `\-' format flag is supported and changes the alignment of a field
813 from right-justified (which is the default) to left-justified.
815 See the
816 .B UNUSUAL FILENAMES
817 section for information about how unusual characters in filenames are handled.
821 .IP \-prune
822 If \-depth is not given, true; if the file is a directory, do not descend
823 into it.
825 If \-depth is given, false; no effect.
827 .IP "\-quit"
828 Exit immediately.  No child processes will be left running, but no more
829 paths specified on the command line will be processed.  For example,
830 .B find /tmp/foo /tmp/bar \-print \-quit
831 will print only
832 .BR /tmp/foo .
833 Any command lines which have been built up with
834 .B \-execdir ... {} +
835 will be invoked before 
836 .B find
837 exits.   The exit status may or may not be zero, depending on whether
838 an error has already occurred.  
840 .IP \-ls
841 True; list current file in `ls \-dils' format on standard output.
842 The block counts are of 1K blocks, unless the environment variable
843 POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
844 See the
845 .B UNUSUAL FILENAMES
846 section for information about how unusual characters in filenames are handled.
849 .SS UNUSUAL FILENAMES
850 Many of the actions of 
851 .B find
852 result in the printing of data which is under the control of other
853 users.  This includes file names, sizes, modification times and so
854 forth.  File names are a potential problem since they can contain any
855 character except '\\0' and '/'.  Unusual characters in file names can
856 do unexpected and often undesirable things to your terminal (for
857 example, changing the settings of your function keys on some
858 terminals).  Unusual characters are handled differently by various
859 actions, as described below.
860 .IP "\-print0, \-fprint0\"
861 Always print the exact filename, unchanged, even if the output is
862 going to a terminal.
863 .IP "\-ls, \-fls"
864 Unusual characters are always escaped.  White space, backslash, and
865 double quote characters are printed using C-style escaping (for
866 example '\\f', '\\"').  Other unusual characters are printed using an
867 octal escape.  Other printable characters (for \-ls and \-fls these are
868 the characters between octal 041 and 0176) are printed as-is.
869 .IP "\-printf, \-fprintf"
870 If the output is not going to a terminal, it is printed as-is.
871 Otherwise, the result depends on which directive is in use.  The
872 directives %D, %F, %g, %G, %H, %Y, and %y expand to values which are
873 not under control of files' owners, and so are printed as-is.  The
874 directives %a, %b, %c, %d, %i, %k, %m, %M, %n, %s, %t, %u and %U have
875 values which are under the control of files' owners but which cannot
876 be used to send arbitrary data to the terminal, and so these are
877 printed as-is.  The directives %f, %h, %l, %p and %P are quoted.  This
878 quoting is performed in the same way as for GNU
879 .BR ls .   
880 This is not the same quoting mechanism as the one used for  \-ls and
881 \-fls.   If you are able to decide what format to use for the output 
882 of 
883 .B find
884 then it is normally better to use '\\0' as a terminator
885 than to use newline, as file names can contain white space and newline
886 characters.
887 .IP "\-print, \-fprint"
888 Quoting is handled in the same way as for \-printf and \-fprintf.
889 If you are using 
890 .B find
891 in a script or in a situation where the matched files might have
892 arbitrary names, you should consider using \-print0 instead of
893 \-print.
895 The \-ok and \-okdir actions print the current filename as-is.  This
896 may change in a future release.
897 .SS OPERATORS
899 Listed in order of decreasing precedence:
900 .IP "( \fIexpr\fR )"
901 Force precedence.
902 .IP "! \fIexpr\fR"
903 True if \fIexpr\fR is false.
904 .IP "\-not \fIexpr\fR"
905 Same as ! \fIexpr\fR, but not POSIX compliant.
906 .IP "\fIexpr1 expr2\fR"
907 Two expressions in a row are taken to be joined with an 
908 implied "and"; \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
909 .IP "\fIexpr1\fR \-a \fIexpr2\fR"
910 Same as \fIexpr1 expr2\fR.
911 .IP "\fIexpr1\fR \-and \fIexpr2\fR"
912 Same as \fIexpr1 expr2\fR, but not POSIX compliant.
913 .IP "\fIexpr1\fR \-o \fIexpr2\fR"
914 Or; \fIexpr2\fR is not evaluated if \fIexpr1\fR is true.
915 .IP "\fIexpr1\fR \-or \fIexpr2\fR"
916 Same as \fIexpr1\fR \-o \fIexpr2\fR, but not POSIX compliant.
917 .IP "\fIexpr1\fR , \fIexpr2\fR"
918 List; both \fIexpr1\fR and \fIexpr2\fR are always evaluated.
919 The value of \fIexpr1\fR is discarded; the value of the list is the
920 value of \fIexpr2\fR.   
921 The comma operator can be useful for searching for several
922 different types of thing, but traversing the filesystem hierarchy only
923 once.   The 
924 .B \-fprintf  
925 action can be used to list the various matched items into several
926 different output files.
929 .SH "STANDARDS CONFORMANCE"
930 The following options are specified in the POSIX standard 
931 (IEEE Std 1003.1, 2003 Edition):
932 .IP "\-H"
933 This option is supported.
934 .IP "\-L"
935 This option is supported.
936 .IP "\-name"
937 This option is supported, but POSIX conformance depends on the 
938 POSIX conformance of the system's 
939 .BR fnmatch (3) 
940 library function.  As of findutils-4.2.2, shell metacharacters
941 ('*'. '?' or '[]' for example) will match a leading '.', because 
942 IEEE PASC interpretation 126 requires this.   This is a change from
943 previous versions of findutils.
944 .IP "\-type"
945 Supported.   POSIX specifies `b', `c', `d', `l', `p', `f' and `s'.
946 GNU find also supports `D', representing a Door, where the OS provides these.
948 .IP "\-ok"
949 Supported.   Interpretation of the response is not locale-dependent
950 (see ENVIRONMENT VARIABLES).
952 .IP "\-newer"
953 Supported.  If the file specified is a symbolic link, it is always
954 dereferenced.  This is a change from previous behaviour, which used to 
955 take the relevant time from the symbolic link; see the HISTORY section
956 below.
958 .IP "Other predicates"
959 The predicates
960 `\-atime',
961 `\-ctime',
962 `\-depth',
963 `\-group',
964 `\-links',
965 `\-mtime',
966 `\-nogroup',
967 `\-nouser',
968 `\-perm',
969 `\-print',
970 `\-prune',
971 `\-size',
972 `\-user' and 
973 `\-xdev',
974 are all supported.
977 The POSIX standard specifies parentheses `(', `)', negation `!' and the
978 `and' and `or' operators (`\-a', `\-o').   
980 All other options, predicates, expressions and so forth are extensions 
981 beyond the POSIX standard.  Many of these extensions are not unique to 
982 GNU find, however.
984 The POSIX standard requires that 
986 The 
987 .B find
988 utility shall detect infinite loops; that is, entering a
989 previously visited directory that is an ancestor of the last file
990 encountered. When it detects an infinite loop, find shall write a
991 diagnostic message to standard error and shall either recover its
992 position in the hierarchy or terminate.
994 The link count of directories which contain entries which are hard
995 links to an ancestor will often be lower than they otherwise should
996 be.  This can mean that GNU find will sometimes optimise away the
997 visiting of a subdirectory which is actually a link to an ancestor.
998 Since 
999 .B find
1000 does not actually enter such a subdirectory, it is allowed to avoid
1001 emitting a diagnostic message.  Although this behaviour may be
1002 somewhat confusing, it is unlikely that anybody actually depends on
1003 this behaviour.  If the leaf optimisation has been turned off with
1004 .BR \-noleaf ,
1005 the directory entry will always be examined and the diagnostic message
1006 will be issued where it is appropriate.  Symbolic links cannot be used
1007 to create filesystem cycles as such, but if the \-L option or the
1008 \-follow option is in use, a diagnostic message is issued when 
1009 .B find 
1010 encounters a loop of symbolic links.  As with loops containing hard
1011 links, the leaf optimisation will often mean that 
1012 .B find
1013 knows that it doesn't need to call 
1014 .I stat()
1016 .I chdir() 
1017 on the symbolic link, so this diagnostic is frequently not necessary.
1019 The \-d option is supported for compatibility with various BSD systems,
1020 but you should use the POSIX-compliant option \-depth instead.
1022 The POSIXLY_CORRECT environment variable does not affect the behaviour
1023 of the \-regex or \-iregex tests because those tests aren't specified in
1024 the POSIX standard.
1025 .SH "ENVIRONMENT VARIABLES"
1026 .IP LANG
1027 Provides a default value for the internationalization variables that
1028 are unset or null.
1029 .IP LC_ALL
1030 If set to a non-empty string value, override the values of all the
1031 other internationalization variables.
1032 .IP LC_COLLATE
1033 The POSIX standard specifies that this variable affects the pattern
1034 matching to be used for the `\-name' option.   GNU find uses the 
1035 .BR fnmatch (3) 
1036 library function, and so support for `LC_COLLATE' depends on the
1037 system library.    
1039 POSIX also specifies that the `LC_COLLATE' environment 
1040 variable affects the interpretation of the user's response to the 
1041 query issued by `\-ok', but this is not the case for GNU find.
1042 .IP LC_CTYPE 
1043 This variable affects the treatment of character classes used with 
1044 the `\-name' option, if the system's 
1045 .BR fnmatch (3) 
1046 library function supports this.   It has no effect on the behaviour 
1047 of the `\-ok' expression.
1048 .IP LC_MESSAGES
1049 Determines the locale to be used for internationalised messages.
1050 .IP NLSPATH
1051 Determines the location of the internationalisation message catalogues.
1052 .IP PATH
1053 Affects the directories which are searched to find the executables 
1054 invoked by `\-exec', `\-execdir', `\-ok' and `\-okdir'.
1055 .IP POSIXLY_CORRECT
1056 Determines the block size used by `-ls'.
1057 .IP TZ
1058 Affects the time zone used for some of the time-related format
1059 directives of \-printf and \-fprintf.
1060 .SH "EXAMPLES"
1062 .B find /tmp \-name core \-type f \-print | xargs /bin/rm \-f
1065 Find files named 
1066 .B core
1067 in or below the directory 
1068 .B /tmp 
1069 and delete them.  Note that this will work incorrectly if there are 
1070 any filenames containing newlines, single or double quotes, or spaces.
1072 .B find /tmp \-name core \-type f \-print0 | xargs \-0 /bin/rm \-f
1075 Find files named 
1076 .B core
1077 in or below the directory 
1078 .B /tmp 
1079 and delete them, processing filenames in such a way that file or
1080 directory names containing single or double quotes, spaces or newlines
1081 are correctly handled.  The
1082 .B \-name 
1083 test comes before the 
1084 .B \-type
1085 test in order to avoid having to call 
1086 .B stat(2) 
1087 on every file.
1091 .B find . \-type f \-exec file '{}' \e\;
1094 Runs `file' on every file in or below the current directory.  Notice
1095 that the braces are enclosed in single quote marks to protect them
1096 from interpretation as shell script punctuation.   The semicolon is
1097 similarly protected by the use of a backslash, though ';' could have
1098 been used in that case also.
1102 .B find /  \t\e( \-perm \-4000 \-fprintf /root/suid.txt '%#m %u %p\en' \e) , \e
1103 .B       \t\t\e( \-size +100M \-fprintf /root/big.txt  '%\-10s %p\en' \e)
1106 Traverse the filesystem just once, listing setuid files and
1107 directories into
1108 .B /root/suid.txt
1109 and large files into 
1110 .BR /root/big.txt .
1114 .B find $HOME  \-mtime 0
1117 Search for files in your home directory which have been modified in
1118 the last twenty-four hours.  This command works this way because the
1119 time since each file was last modified is divided by 24 hours and any 
1120 remainder is discarded.  That means that to match 
1121 .B \-mtime 
1122 .BR 0 ,
1123 a file will have to have a modification in the past which is less than
1124 24 hours ago.
1128 .B find /sbin /usr/sbin -executable \e! -readable \-print
1131 Search for files which are executable but not readable.
1135 .B find . \-perm 664
1138 Search for files which have read and write permission for their owner,
1139 and group, but which other users can read but not write to.  Files
1140 which meet these criteria but have other permissions bits set (for
1141 example if someone can execute the file) will not be matched.
1145 .B find . \-perm -664
1148 Search for files which have read and write permission for their owner
1149 and group, and which other users can read, without regard to the
1150 presence of any extra permission bits (for example the executable
1151 bit).  This will match a file which has mode 0777, for example.
1155 .B find . \-perm /222
1158 Search for files which are writable by somebody (their owner, or
1159 their group, or anybody else).
1163 .B find . \-perm /220
1164 .B find . \-perm /u+w,g+w
1165 .B find . \-perm /u=w,g=w
1168 All three of these commands do the same thing, but the first one uses
1169 the octal representation of the file mode, and the other two use the
1170 symbolic form.  These commands all search for files which are
1171 writable by either their owner or their group.  The files don't have
1172 to be writable by both the owner and group to be matched; either will
1177 .B find . \-perm -220
1178 .B find . \-perm \-g+w,u+w
1181 Both these commands do the same thing; search for files which are
1182 writable by both their owner and their group.
1186 .B find . \-perm \-444 \-perm /222 ! \-perm /111
1187 .B find . \-perm \-a+r \-perm /a+w ! \-perm /a+x
1190 These two commands both search for files that are readable for
1191 everybody (\-perm \-444 or \-perm \-a+r), have at least on write bit
1192 set (\-perm /222 or \-perm /a+w) but are not executable for anybody (!
1193 \-perm /111 and ! \-perm /a+x respectively)
1195 .SH EXIT STATUS
1197 .B find
1198 exits with status 0 if all files are processed successfully, greater
1199 than 0 if errors occur.   This is deliberately a very broad
1200 description, but if the return value is non-zero, you should not rely
1201 on the correctness of the results of 
1202 .BR find .
1204 .SH "SEE ALSO"
1205 \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1), \fBxargs\fP(1),
1206 \fBchmod\fP(1), \fBfnmatch\fP(3), \fBregex\fP(7), \fBstat\fP(2),
1207 \fBlstat\fP(2), \fBls\fP(1), \fBprintf\fP(3), \fBstrftime\fP(3),
1208 \fBctime\fP(3), \fBFinding Files\fP (on-line in Info, or printed).
1209 .SH "HISTORY"
1210 As of findutils-4.2.2, shell metacharacters ('*'. '?' or '[]' for
1211 example) used in filename patterns will match a leading '.', because
1212 IEEE POSIX interpretation 126 requires this.
1213 .SH "NON-BUGS"
1215 .B $ find . \-name *.c \-print
1216 find: paths must precede expression
1217 Usage: find [-H] [-L] [-P] [path...] [expression]
1220 This happens because 
1221 .I *.c 
1222 has been expanded by the shell
1223 resulting in 
1224 .B find
1225 actually receiving a command line like this:
1228 .B find . \-name bigram.c code.c frcode.c locate.c \-print
1231 That command is of course not going to work.  Instead of doing things
1232 this way, you should enclose the pattern in quotes:
1234 .B $ find . \-name \'*.c\' \-print
1237 .SH "BUGS"
1239 There are security problems inherent in the behaviour that the POSIX
1240 standard specifies for
1241 .BR find ,
1242 which therefore cannot be fixed.  For example, the \-exec action is
1243 inherently insecure, and \-execdir should be used instead.  
1244 Please see \fBFinding Files\fP for more information. 
1245 .P 
1246 The best way to report a bug is to use the form at
1247 http://savannah.gnu.org/bugs/?group=findutils.  
1248 The reason for this is that you will then be able to track progress in
1249 fixing the problem.   Other comments about \fBfind\fP(1) and about
1250 the findutils package in general can be sent to the 
1251 .I bug\-findutils
1252 mailing list.  To join the list, send email to 
1253 .IR bug\-findutils\-request@gnu.org .