Understand the -exec ... {} \+ construction (for multiple
[findutils.git] / find / find.1
blobd96d49b61d738b5aef1f543e711ef2ecde634ad8
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 The `\-H', `\-L' and `\-P' options control the treatment of symbolic
22 links.  Command-line arguments following these are taken to be names
23 of files or directories to be examined, up to the first argument that
24 begins with `\-', `(', `)', `,', or `!'.  That argument and any
25 following arguments are taken to be the expression describing what is
26 to be searched for.  If no paths are given, the current directory is
27 used.  If no expression is given, the expression `\-print' is used
28 (but you should probably consider using `\-print0' instead, anyway).
29 .PP
30 This manual page talks about `options' within the expression list.
31 These options control the behaviour of 
32 .B find
33 but are specified immediately after the last path name.  The two
34 `real' options `\-H', `\-L' and `\-P' must appear before the first
35 path name, if at all.
36 .SH OPTIONS
37 .IP \-P
38 Never follow symbolic links.  This is the default behaviour.  When 
39 .B find
40 examines or prints information a file, and the file is a symbolic
41 link, the information used shall be taken from the properties of the
42 symbolic link itself.  
44 .IP \-L
45 Follow symbolic links.  When 
46 .B find
47 examines or prints information about files, the information used shall
48 be taken from the properties of the file to which the link points, not
49 from the link itself (unless it is a broken symbolic link or 
50 .B find
51 is unable to examine the file to which the link points).  Use of this
52 option implies \-noleaf.  If you later use the \-P option, \-noleaf
53 will still be in effect.
55 .IP \-H
56 Do not follow symbolic links, except those appearing on the command
57 line.  When
58 .B find
59 examines or prints information about files, the information used 
60 shall be taken from the properties of the symbolic link itself.   The
61 only exception to this behaviour is when a file specified on the
62 command line is a symbolic link, and the link can be resolved.  For
63 that situation, the information used is taken from whatever the link
64 points to (that is, the link is followed).  The information about the
65 link itself is used as a fallback if the file pointed to by the
66 symbolic link cannot be examined.
68 When the \-H option is in effect, the \-type predicate will always
69 match against the type of the file that a symbolic link points to
70 rather than the link itself (unless the symbolic link is broken).
71 Using \-H causes the \-lname and \-ilname predicates always to return
72 false.
74 If more than one of \-H, \-L and \-P are both specified, each
75 overrides the others; the last one appearing on the command line takes
76 effect.  Since it is the default, the \-P option should be considered
77 to be in effect unless either \-H or \-L is specified.
79 GNU 
80 .B find
81 frequently stats files during the processing of the command line
82 itself, before any searching has begun.  These options also affect how
83 those arguments are processed.  Specifically, there are a number of
84 tests that compare files listed on the command line against a file we
85 are currently considering.  In each case, the file specified on the
86 command line will have been examined and some of its properties will
87 have been saved.  If the named file is in fact a symbolic link, and
88 the \-P option is in effect (or if neither \-H nor \-L were
89 specified), the information used for the comparison will be taken from
90 the properties of the symbolic link.  Otherwise, it will be taken from
91 the properties of the file the link points to.  If
92 .B find 
93 cannot follow the link (for example because it has insufficient
94 privileges or the link points to a nonexistent file) the properties of
95 the link itself will be used.
97 When the \-H or \-L options are in effect, any symbolic links listed
98 as the argument of \-newer will be dereferenced, and the timestamp
99 will be taken from the file to which the symbolic link points.  The
100 same consideration applies to \-anewer and \-cnewer.
102 Similarly, when \-H or \-L is in effect, the \-type predicate will
103 always match against the type of the file that a symbolic link points
104 to rather than the link itself (unless the link is broken or cannot be
105 dereferenced).  Using \-H or \-L causes the \-lname and \-ilname
106 predicates always to return false (again, except in the case of broken
107 links).
109 The \-follow option has a similar effect to \-L, though it takes
110 effect at the point where it appears (that is, if \-L is not used but
111 \-follow is, any symbolic links appearing after it on the command line
112 will be dereferenced).
115 .SH EXPRESSIONS
116 The expression is made up of options (which affect overall operation
117 rather than the processing of a specific file, and always return true),
118 tests (which return a true or false value), and actions (which have side
119 effects and return a true or false value), all separated by operators.
120 \-and is assumed where the operator is omitted.  If the expression contains
121 no actions other than \-prune, \-print is performed on all files
122 for which the expression is true.
123 .SS OPTIONS
125 All options always return true.  Except for \-follow and \-daystart,
126 they always take effect, rather than being processed only when their
127 place in the expression is reached.  Therefore, for clarity, it is
128 best to place them at the beginning of the expression.  A warning is
129 issued if you don't do this.
130 .IP \-daystart
131 Measure times (for \-amin, \-atime, \-cmin, \-ctime, \-mmin, and \-mtime)
132 from the beginning of today rather than from 24 hours ago.  This
133 option only affects tests which appear later on the command line.
134 .IP \-depth
135 Process each directory's contents before the directory itself.
136 .IP \-d
137 A synonym for \-depth, for compatibility with FreeBSD, NetBSD, MacOS X and OpenBSD.
138 .IP \-follow
139 Deprecated; use the \-L option instead.  Dereference symbolic links.
140 Implies \-noleaf.  Unless the \-H or \-L option has been specified,
141 the position of the \-follow option changes the behaviour of the
142 \-newer predicate; any files listed as the argument of \-newer will be
143 dereferenced if they are symbolic links.  The same consideration
144 applies to \-anewer and \-cnewer.  Similarly, the \-type predicate
145 will always match against the type of the file that a symbolic link
146 points to rather than the link itself.  Using \-follow causes the
147 \-lname and \-ilname predicates always to return false.
148 .IP "\-help, \-\-help"
149 Print a summary of the command-line usage of
150 .B find
151 and exit.
152 .IP \-ignore_readdir_race
153 Normally, \fBfind\fR will emit an error message when it fails to stat a file.
154 If you give this option and a file is deleted between the time \fBfind\fR 
155 reads the name of the file from the directory and the time it tries to stat 
156 the file, nno error message will be issued.    This also applies to files
157 or directories whose names are given on the command line.  This option takes
158 effect at the time the command line is read, which means that you cannot search
159 one part of the filesystem with this option on and part of it with this option
160 off (if you need to do that, you will need to issue two \fBfind\fR commands
161 instead, one with the option and one without it).
162 .IP "\-maxdepth \fIlevels\fR"
163 Descend at most \fIlevels\fR (a non-negative integer) levels of
164 directories below the command line arguments.  `\-maxdepth 0' means
165 only apply the tests and actions to the command line arguments.
166 .IP "\-mindepth \fIlevels\fR"
167 Do not apply any tests or actions at levels less than \fIlevels\fR (a
168 non-negative integer).  `\-mindepth 1' means process all files except
169 the command line arguments.
170 .IP \-mount
171 Don't descend directories on other filesystems.  An alternate name for
172 \-xdev, for compatibility with some other versions of
173 .BR find .
174 .IP \-noignore_readdir_race
175 Turns off the effect of \-ignore_readdir_race. 
176 .IP "\-noleaf"
177 Do not optimize by assuming that directories contain 2 fewer
178 subdirectories than their hard link count.  This option is needed when
179 searching filesystems that do not follow the Unix directory-link
180 convention, such as CD-ROM or MS-DOS filesystems or AFS volume mount
181 points.  Each directory on a normal Unix filesystem has at least 2
182 hard links: its name and its `.'  entry.  Additionally, its
183 subdirectories (if any) each have a `..'  entry linked to that
184 directory.  When
185 .B find
186 is examining a directory, after it has statted 2 fewer subdirectories
187 than the directory's link count, it knows that the rest of the entries
188 in the directory are non-directories (`leaf' files in the directory
189 tree).  If only the files' names need to be examined, there is no need
190 to stat them; this gives a significant increase in search speed.
191 .IP "\-version, \-\-version"
192 Print the \fBfind\fR version number and exit.
193 .IP "\-warn, \-nowarn"
194 Turn warning messages on or off.  These warnings apply only to the
195 command line usage, not to any conditions that 
196 .B find 
197 might encounter when it searches directories.  The default behaviour
198 corresponds to \-warn if standard input is a tty, and to \-nowarn
199 otherwise.
200 .IP \-xdev
201 Don't descend directories on other filesystems.
203 .SS TESTS
205 Numeric arguments can be specified as
206 .IP \fI+n\fP
207 for greater than
208 .IR n ,
209 .IP \fI\-n\fP
210 for less than
211 .IR n ,
212 .IP \fIn\fP
213 for exactly
214 .IR n .
215 .IP "\-amin \fIn\fR"
216 File was last accessed \fIn\fR minutes ago.
217 .IP "\-anewer \fIfile\fR"
218 File was last accessed more recently than \fIfile\fR was modified.  If
219 \fIfile\fR is a symbolic link and the \-H option or the \-L option is
220 in effect, the access time of the file it points to is always
221 used.
222 .IP "\-atime \fIn\fR"
223 File was last accessed \fIn\fR*24 hours ago.  
224 When find figures out how many 24-hour preiods ago the file 
225 was last accessed, any fractional part is ignored, so to match 
226 .B \-atime 
227 .BR +1 ,
228 a file has to have been modified at least 
229 .I two
230 days ago.
231 .IP "\-cmin \fIn\fR"
232 File's status was last changed \fIn\fR minutes ago.
233 .IP "\-cnewer \fIfile\fR"
234 File's status was last changed more recently than \fIfile\fR was
235 modified.  If \fIfile\fR is a symbolic link and the \-H option or the
236 \-L option is in effect, the status-change time of the file it points
237 to is always used.
239 .IP "\-ctime \fIn\fR"
240 File's status was last changed \fIn\fR*24 hours ago.
241 See the comments for 
242 .B \-atime 
243 to understand how rounding affects the interpretation of file status
244 change times.
245 .IP \-empty
246 File is empty and is either a regular file or a directory.
247 .IP \-false
248 Always false.
249 .IP "\-fstype \fItype\fR"
250 File is on a filesystem of type \fItype\fR.  The valid filesystem
251 types vary among different versions of Unix; an incomplete list of
252 filesystem types that are accepted on some version of Unix or another
253 is: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K.  You can use \-printf
254 with the %F directive to see the types of your filesystems.
255 .IP "\-gid \fIn\fR"
256 File's numeric group ID is \fIn\fR.
257 .IP "\-group \fIgname\fR"
258 File belongs to group \fIgname\fR (numeric group ID allowed).
259 .IP "\-ilname \fIpattern\fR"
260 Like \-lname, but the match is case insensitive.
261 If the \-L option or the \-follow option is in effect, this test 
262 returns false unless the symbolic link is broken.
263 .IP "\-iname \fIpattern\fR"
264 Like \-name, but the match is case insensitive.  For example, the
265 patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo',
266 `fOo', etc.   In these patterns, unlike filename expansion by the
267 shell, an initial '.' can be matched by '*'.  That is, 
268 .B find \-name *bar 
269 will match the file `.foobar'.
271 .IP "\-inum \fIn\fR"
272 File has inode number \fIn\fR.  It is normally easier to use the 
273 .B \-samefile
274 test instead.
275 .IP "\-ipath \fIpattern\fR"
276 Behaves in the same way as \-iwholename.  This option is deprecated,
277 so please do not use it.
278 .IP "\-iregex \fIpattern\fR"
279 Like \-regex, but the match is case insensitive.
280 .IP "\-iwholename \fIpattern\fR"
281 Like \-wholename, but the match is case insensitive.
282 .IP "\-links \fIn\fR"
283 File has \fIn\fR links.
284 .IP "\-lname \fIpattern\fR"
285 File is a symbolic link whose contents match shell pattern
286 \fIpattern\fR.  The metacharacters do not treat `/' or `.' specially.
287 If the \-L option or the \-follow option is in effect, this test 
288 returns false unless the symbolic link is broken.
289 .IP "\-mmin \fIn\fR"
290 File's data was last modified \fIn\fR minutes ago.
291 .IP "\-mtime \fIn\fR"
292 File's data was last modified \fIn\fR*24 hours ago.
293 See the comments for 
294 .B \-atime 
295 to understand how rounding affects the interpretation of file
296 modification times.
297 .IP "\-name \fIpattern\fR"
298 Base of file name (the path with the leading directories removed)
299 matches shell pattern \fIpattern\fR.  The metacharacters (`*', `?',
300 and `[]') match a `.' at the start of the base name (this is a change
301 in findutils-4.2.2; see section STANDARDS CONFORMANCE below).  To ignore a
302 directory and the files under it, use \-prune; see an example in the
303 description of \-wholename.  Braces are not recognised as being
304 special, despite the fact that some shells including Bash ibmue braces
305 with a special meaning in shell patterns.  The filename matching is
306 performed with the use of the
307 .BR fnmatch (3) 
308 library function.
309 .IP "\-newer \fIfile\fR"
310 File was modified more recently than \fIfile\fR.  If \fIfile\fR is a
311 symbolic link and the \-H option or the \-L option is in effect, the
312 modification time of the file it points to is always used.
313 .IP \-nouser
314 No user corresponds to file's numeric user ID.
315 .IP \-nogroup
316 No group corresponds to file's numeric group ID.
317 .IP "\-path \fIpattern\fR"
318 See \-wholename.   The predicate \-path is also supported by HP-UX 
319 .BR find .
320 .IP "\-perm \fImode\fR"
321 File's permission bits are exactly \fImode\fR (octal or symbolic).
322 Since an exact match is required, if you want to use this form for
323 symbolic modes, you may have to specify a rather complex mode string.
324 For example '\-perm g=w' will only match files which have mode 0020
325 (that is, ones for which group write permission is the only permission
326 set).  It is more likely that you will want to use the '+' or '-'
327 forms, for example '\-perm -g=w', which matches any file with group
328 write permission.  See the
329 .B EXAMPLES 
330 section for some illustrative examples.
331 .IP "\-perm \-\fImode\fR"
332 All of the permission bits \fImode\fR are set for the file.
333 Symbolic modes are accepted in this form, and this is usually the way
334 in which would want to use them.  You must specify 'u', 'g' or 'o' if
335 you use a symbolic mode.   See the 
336 .B EXAMPLES 
337 section for some illustrative examples.
338 .IP "\-perm +\fImode\fR"
339 Any of the permission bits \fImode\fR are set for the file.  Symbolic
340 modes are accepted in this form.  You must specify 'u', 'g' or 'o' if
341 you use a symbolic mode.  See the
342 .B EXAMPLES 
343 section for some illustrative examples.
344 .IP "\-regex \fIpattern\fR"
345 File name matches regular expression \fIpattern\fR.  This is a match
346 on the whole path, not a search.  For example, to match a file named
347 `./fubar3', you can use the regular expression `.*bar.' or `.*b.*3',
348 but not `f.*r3'.  The regular expressions understood by 
349 .B find 
350 follow the conventions for the 
351 .B re_match 
352 system library function where this is present (i.e. on systems using
353 the GNU C Library).  On other systems, the implementation within
354 Gnulib is used; by default, Gnulib provides ``basic'' regular
355 expressions.
356 .IP "\-samefile \fIname\fR"
357 File refers to the same inode as \fIname\fR.   When -L is in effect,
358 this can include symbolic links.
359 .IP "\-size \fIn\fR[cwbkMG]"
360 File uses \fIn\fP units of space.  The following suffixes 
361 can be used:
363 .IP `b' 
364 for 512-byte blocks (this is the default if no suffix is used)
365 .IP `c' 
366 for bytes
367 .IP `w' 
368 for two-byte words
369 .IP `k' 
370 for Kilobytes (units of 1024 bytes)
371 .IP `M' 
372 for Megabytes (units of 1048576 bytes)
373 .IP `G' 
374 for Gigabytes (units of 1073741824 bytes)
377 The size does not count indirect blocks, but it does count blocks in
378 sparse files that are not actually allocated.  Bear in mind that the
379 `%k' and `%b' format specifiers of \-printf handle sparse files
380 differently.  The `b' suffix always denotes 512-byte blocks and never
381 1 Kilobyte blocks, which is different to the behaviour of \-ls.
383 .IP \-true
384 Always true.
385 .IP "\-type \fIc\fR"
386 File is of type \fIc\fR:
388 .IP b
389 block (buffered) special
390 .IP c
391 character (unbuffered) special
392 .IP d
393 directory
394 .IP p
395 named pipe (FIFO)
396 .IP f
397 regular file
398 .IP l
399 symbolic link (never true if the \-L option or the \-follow option is
400 in effect, unless the symbolic link is broken).
401 .IP s
402 socket
403 .IP D
404 door (Solaris)
406 .IP "\-uid \fIn\fR"
407 File's numeric user ID is \fIn\fR.
408 .IP "\-used \fIn\fR"
409 File was last accessed \fIn\fR days after its status was last changed.
410 .IP "\-user \fIuname\fR"
411 File is owned by user \fIuname\fR (numeric user ID allowed).
412 .IP "\-wholename \fIpattern\fR"
413 File name matches shell pattern \fIpattern\fR.  The metacharacters do
414 not treat `/' or `.' specially; so, for example,
416 .in +1i
417 find . \-wholename './sr*sc'
419 .in -1i
420 will print an entry for a directory called './src/misc' (if one
421 exists).  To ignore a whole directory tree, use \-prune rather than
422 checking every file in the tree.  For example, to skip the
423 directory `src/emacs' and all files and directories under it, and
424 print the names of the other files found, do something like this:
426 .in +1i
427 find . \-wholename './src/emacs' \-prune \-o \-print
429 .in -1i
430 .IP "\-xtype \fIc\fR"
431 The same as \-type unless the file is a symbolic link.  For symbolic
432 links: if the \-H or \-P option was specified, true if the file is a
433 link to a file of type \fIc\fR; if the \-L option has been given, true
434 if \fIc\fR is `l'.  In other words, for symbolic links, \-xtype checks
435 the type of the file that \-type does not check.
437 .SS ACTIONS
438 .IP "\-delete\fR"
439 Delete files; true if removal succeeded.  If the removal failed, an
440 error message is issued.
442 .IP "\-exec \fIcommand\fR ;"
443 Execute \fIcommand\fR; true if 0 status is returned.  All following
444 arguments to
445 .B find
446 are taken to be arguments to the command until an argument consisting
447 of `;' is encountered.  The string `{}' is replaced by the current
448 file name being processed everywhere it occurs in the arguments to the
449 command, not just in arguments where it is alone, as in some versions
451 .BR find .
452 Both of these constructions might need to be escaped (with a `\e') or
453 quoted to protect them from expansion by the shell.  See the
454 .B EXAMPLES
455 section for examples of the use of the `\-exec' option.
456 The command is executed in the starting directory.
458 .IP "\-exec \fIcommand\fR +"
459 This variant of \-exec is not yet supported, but is required by POSIX.
461 .IP "\-fls \fIfile\fR"
462 True; like \-ls but write to \fIfile\fR like \-fprint.
463 The output file is always created, even if the predicate is never matched.
464 .IP "\-fprint \fIfile\fR"
465 True; print the full file name into file \fIfile\fR.  If \fIfile\fR
466 does not exist when \fBfind\fR is run, it is created; if it does
467 exist, it is truncated.  The file names ``/dev/stdout'' and
468 ``/dev/stderr'' are handled specially; they refer to the standard
469 output and standard error output, respectively.
470 The output file is always created, even if the predicate is never matched.
471 .IP "\-fprint0 \fIfile\fR"
472 True; like \-print0 but write to \fIfile\fR like \-fprint.
473 The output file is always created, even if the predicate is never matched.
474 .IP "\-fprintf \fIfile\fR \fIformat\fR"
475 True; like \-printf but write to \fIfile\fR like \-fprint.
476 The output file is always created, even if the predicate is never matched.
477 .IP "\-ok \fIcommand\fR ;"
478 Like \-exec but ask the user first (on the standard input); if the
479 response does not start with `y' or `Y', do not run the command, and
480 return false.
481 .IP \-print
482 True; print the full file name on the standard output, followed by a
483 newline.   If you are piping the output of 
484 .B find 
485 into another program and there is the faintest possibility that the files 
486 which you are searching for might contain a newline, then you should 
487 seriously consider using the `\-print0' option instead of `\-print'.
489 .IP \-print0
490 True; print the full file name on the standard output, followed by a
491 null character (instead of the newline character that `\-print' uses).
492 This allows file names that contain newlines or other types of white
493 space to be correctly interpreted by programs that process the
494 \fBfind\fR output.  This option corresponds to the `\-0' option of
495 .BR xargs .
496 .IP "\-printf \fIformat\fR"
497 True; print \fIformat\fR on the standard output, interpreting `\e'
498 escapes and `%' directives.  Field widths and precisions can be
499 specified as with the `printf' C function.  Please note that many of
500 the fields are printed as %s rather than %d, and this may mean that
501 flags don't work as you might expect.  This also means that the `\-'
502 flag does work (it forces fields to be left-aligned).  Unlike \-print,
503 \-printf does not add a newline at the end of the string.  The escapes
504 and directives are:
506 .IP \ea
507 Alarm bell.
508 .IP \eb
509 Backspace.
510 .IP \ec
511 Stop printing from this format immediately and flush the output.
512 .IP \ef
513 Form feed.
514 .IP \en
515 Newline.
516 .IP \er
517 Carriage return.
518 .IP \et
519 Horizontal tab.
520 .IP \ev
521 Vertical tab.
522 .IP \e\0
523 ASCII NUL.
524 .IP \e\e
525 A literal backslash (`\e').
526 .IP \eNNN
527 The character whose ASCII code is NNN (octal).
529 A `\e' character followed by any other character is treated as an
530 ordinary character, so they both are printed.
531 .IP %%
532 A literal percent sign.
533 .IP %a
534 File's last access time in the format returned by the C `ctime' function.
535 .IP %A\fIk\fP
536 File's last access time in the format specified by \fIk\fR, which is
537 either `@' or a directive for the C `strftime' function.  The possible
538 values for \fIk\fR are listed below; some of them might not be
539 available on all systems, due to differences in `strftime' between
540 systems.  
542 .IP @
543 seconds since Jan. 1, 1970, 00:00 GMT.
545 Time fields:
546 .IP H
547 hour (00..23)
548 .IP I
549 hour (01..12)
550 .IP k
551 hour ( 0..23)
552 .IP l
553 hour ( 1..12)
554 .IP M
555 minute (00..59)
556 .IP p
557 locale's AM or PM
558 .IP r
559 time, 12-hour (hh:mm:ss [AP]M)
560 .IP S
561 second (00..61)
562 .IP T
563 time, 24-hour (hh:mm:ss)
564 .IP +
565 Date and time, separated by '+', for example `2004\-04\-28+22:22:05'.
566 The time is given in the current timezone (which may be affected by
567 setting the TZ environment variable).  This is a GNU extension.
568 .IP X
569 locale's time representation (H:M:S)
570 .IP Z
571 time zone (e.g., EDT), or nothing if no time zone is determinable
573 Date fields:
574 .IP a
575 locale's abbreviated weekday name (Sun..Sat)
576 .IP A
577 locale's full weekday name, variable length (Sunday..Saturday)
578 .IP b
579 locale's abbreviated month name (Jan..Dec)
580 .IP B
581 locale's full month name, variable length (January..December)
582 .IP c
583 locale's date and time (Sat Nov 04 12:02:33 EST 1989)
584 .IP d
585 day of month (01..31)
586 .IP D
587 date (mm/dd/yy)
588 .IP h
589 same as b
590 .IP j
591 day of year (001..366)
592 .IP m
593 month (01..12)
594 .IP U
595 week number of year with Sunday as first day of week (00..53)
596 .IP w
597 day of week (0..6)
598 .IP W
599 week number of year with Monday as first day of week (00..53)
600 .IP x
601 locale's date representation (mm/dd/yy)
602 .IP y
603 last two digits of year (00..99)
604 .IP Y
605 year (1970...)
607 .IP %b
608 File's size in 512-byte blocks (rounded up).
609 .IP %c
610 File's last status change time in the format returned by the C `ctime'
611 function.
612 .IP %C\fIk\fP
613 File's last status change time in the format specified by \fIk\fR,
614 which is the same as for %A.
615 .IP %d
616 File's depth in the directory tree; 0 means the file is a command line
617 argument.
618 .IP %D
619 The device number on which the file exists (the st_dev field of struct
620 stat), in decimal.
621 .IP %f
622 File's name with any leading directories removed (only the last element).
623 .IP %F
624 Type of the filesystem the file is on; this value can be used for
625 \-fstype.
626 .IP %g
627 File's group name, or numeric group ID if the group has no name.
628 .IP %G
629 File's numeric group ID.
630 .IP %h
631 Leading directories of file's name (all but the last element).
632 .IP %H
633 Command line argument under which file was found.
634 .IP %i
635 File's inode number (in decimal).
636 .IP %k
637 The amount of disk space used for this file in 1K blocks (rounded
638 up).  This is different from %s/1024 if the file is a sparse file.
639 .IP %l
640 Object of symbolic link (empty string if file is not a symbolic link).
641 .IP %m
642 File's permission bits (in octal).  This option uses the 'traditional'
643 numbers which most Unix implementations use, but if your particular 
644 implementation uses an unusual ordering of octal permissions bits, you
645 will see a difference between the actual value of the file's mode and
646 the output of %m.   Normally you will want to have a leading
647 zero on this number, and to do this, you should use the 
648 .B #
649 flag (as in, for example, '%#m').
650 .IP %n
651 Number of hard links to file.
652 .IP %p
653 File's name.
654 .IP %P
655 File's name with the name of the command line argument under which
656 it was found removed.
657 .IP %s
658 File's size in bytes.
659 .IP %t
660 File's last modification time in the format returned by the C `ctime'
661 function.
662 .IP %T\fIk\fP
663 File's last modification time in the format specified by \fIk\fR, 
664 which is the same as for %A.
665 .IP %u
666 File's user name, or numeric user ID if the user has no name.
667 .IP %U
668 File's numeric user ID.
669 .IP %y
670 File's type (like in ls \-l), U=unknown type (shouldn't happen)
671 .IP %Y
672 File's type (like %y), plus follow symlinks: L=loop, N=nonexistent
674 A `%' character followed by any other character is discarded (but the
675 other character is printed).
677 The %m and %d directives support the 
678 .B #
680 .B 0 
681 and 
682 .B + 
683 flags, but the other directives do not, even if they
684 print numbers.  Numeric directives that do not support these flags
685 include 
686 .BR G , 
687 .BR U , 
688 .BR b , 
689 .BR D , 
690 .B  k 
691 and 
692 .BR n .
693 The `\-' format flag is supported and changes the alignment of a field
694 from right-justified (which is the default) to left-justified.
698 .IP \-prune
699 If \-depth is not given, true; if the file is a directory, do not descend
700 into it.
702 If \-depth is given, false; no effect.
704 .IP "\-quit"
705 Exit immediately with return value zero.  No child proceses will be
706 left running, but no more paths specified on the command line will be 
707 processed.   For example,
708 .B find /tmp/foo /tmp/bar \-print \-quit
709 will print only
710 .BR /tmp/foo .
713 .IP \-ls
714 True; list current file in `ls \-dils' format on standard output.
715 The block counts are of 1K blocks, unless the environment variable
716 POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
718 .SS OPERATORS
720 Listed in order of decreasing precedence:
721 .IP "( \fIexpr\fR )"
722 Force precedence.
723 .IP "! \fIexpr\fR"
724 True if \fIexpr\fR is false.
725 .IP "\-not \fIexpr\fR"
726 Same as ! \fIexpr\fR.
727 .IP "\fIexpr1 expr2\fR"
728 And (implied); \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
729 .IP "\fIexpr1\fR \-a \fIexpr2\fR"
730 Same as \fIexpr1 expr2\fR.
731 .IP "\fIexpr1\fR \-and \fIexpr2\fR"
732 Same as \fIexpr1 expr2\fR.
733 .IP "\fIexpr1\fR \-o \fIexpr2\fR"
734 Or; \fIexpr2\fR is not evaluated if \fIexpr1\fR is true.
735 .IP "\fIexpr1\fR \-or \fIexpr2\fR"
736 Same as \fIexpr1\fR \-o \fIexpr2\fR.
737 .IP "\fIexpr1\fR , \fIexpr2\fR"
738 List; both \fIexpr1\fR and \fIexpr2\fR are always evaluated.
739 The value of \fIexpr1\fR is discarded; the value of the list is the
740 value of \fIexpr2\fR.   
741 The comma operator can be useful for searching for several
742 different types of thing, but traversing the filesystem hierarchy only
743 once.   The 
744 .B \-fprintf  
745 action can be used to list the various matched items into several
746 different output files.
749 .SH "STANDARDS CONFORMANCE"
750 The following options are specified in the POSIX standard 
751 (IEEE Std 1003.1, 2003 Edition):
752 .IP "\-H"
753 This option is supported.
754 .IP "\-L"
755 This option is supported.
756 .IP "\-name"
757 This option is supported, but POSIX conformance depends on the 
758 POSIX conformance of the system's 
759 .BR fnmatch (3) 
760 library function.  As of findutils-4.2.2, shell metacharacters
761 ('*'. '?' or '[]' for example) will match a leading '.', because 
762 IEEE PASC interpretation 126 requires this.   This is a change from
763 previous versions of findutils.
764 .IP "\-type"
765 Supported.   POSIX specifies `b', `c', `d', `l', `p', `f' and `s'.
766 GNU find also supports `D', representing a Door, where the OS provides these.
768 .IP "\-ok"
769 Supported.   Interpretation of the response is not locale-dependent
770 (see ENVIRONMENT VARIABLES).
772 .IP "\-exec"
773 Supported for the `{} ;' case, but the '{} +' variant is not supported yet.
775 .IP "\-newer"
776 Supported.  If the file specified is a symbolic link, it is always
777 dereferenced.  This is a change from previous behaviour, which used to 
778 take the relevant time from the symbolic link; see the HISTORY section
779 below.
781 .IP "Other predicates"
782 The predicates
783 `\-atime',
784 `\-ctime',
785 `\-depth',
786 `\-group',
787 `\-links',
788 `\-mtime',
789 `\-nogroup',
790 `\-nouser',
791 `\-perm',
792 `\-print',
793 `\-prune',
794 `\-size',
795 `\-user' and 
796 `\-xdev',
797 are all supported.
800 The POSIX standard specifies parentheses `(', `)', negation `!' and the
801 `and' and `or' operators (`\-a', `\-o').   
803 All other options, predicates, expressions and so forth are extensions 
804 beyond the POSIX standard.  Many of these extensions are not unique to 
805 GNU find, however.
807 The POSIX standard requires that 
809 The 
810 .B find
811 utility shall detect infinite loops; that is, entering a
812 previously visited directory that is an ancestor of the last file
813 encountered. When it detects an infinite loop, find shall write a
814 diagnostic message to standard error and shall either recover its
815 position in the hierarchy or terminate.
817 The link count of directories which contain entries which are hard
818 links to an ancestor will often be lower than they otherwise should
819 be.  This can mean that GNU find will sometimes optimise away the
820 visiting of a subdirectory which is actually a link to an ancestor.
821 Since 
822 .B find
823 does not actually enter such a subdirectory, it is allowed to avoid
824 emitting a diagnostic message.  Although this behaviour may be
825 somewhat confusing, it is unlikely that anybody actually depends on
826 this behaviour.  If the leaf optimisation has been turned off with
827 .BR -noleaf ,
828 the directory entry will always be examined and the diagnostic message
829 will be issued where it is appropriate.  Symbolic links cannot be used
830 to create filesystem cycles as such, but if the \-L option or the
831 \-follow option is in use, a diagnostic message is issued when 
832 .B find 
833 encounters a loop of symbolic links.  As with loops containing hard
834 links, the leaf optimisation will often mean that 
835 .B find
836 knows that it doesn't need to call 
837 .I stat()
839 .I chdir() 
840 on the symbolic link, so this diagnostic is frequently not necessary.
842 The \-d option is supported for comatibility with various BSD systems,
843 but you should use the POSIX-compliant predicate \-depth instead.
844 .SH "ENVIRONMENT VARIABLES"
845 .IP POSIXLY_CORRECT
846 Determines the block size used by `-ls'.
847 .IP LANG
848 Provides a default value for the internationalization variables that
849 are unset or null.
850 .IP LC_ALL
851 If set to a non-empty string value, override the values of all the
852 other internationalization variables.
853 .IP LC_COLLATE
854 The POSIX standard specifies that this variable affects the pattern
855 matching to be used for the `\-name' option.   GNU find uses the 
856 .BR fnmatch (3) 
857 library function, and so support for `LC_COLLATE' depends on the
858 system library.    
860 POSIX also specifies that the `LC_COLLATE' environment 
861 variable affects the interpretation of the user's response to the 
862 query issued by `\-ok', but this is not the case for GNU find.
863 .IP LC_CTYPE 
864 This variable affects the treatment of character classes used with 
865 the `\-name' option, if the system's 
866 .BR fnmatch (3) 
867 library function supports this.   It has no effect on the behaviour 
868 of the `\-ok' expression.
869 .IP LC_MESSAGES
870 Determines the locale to be used for internationalised messages.
871 .IP NLSPATH
872 Determines the location of the internationalisation message catalogues.
873 .IP PATH
874 Affects the directores which are searched to find the executables 
875 invoked by `\-exec' and `\-ok'.
876 .SH "EXAMPLES"
878 .B find /tmp \-name core \-type f \-print | xargs /bin/rm -f
881 Find files named 
882 .B core
883 in or below the directory 
884 .B /tmp 
885 and delete them.  Note that this will work incorrectly if there are 
886 any filenames containing newlines, single or double quotes, or spaces.
888 .B find /tmp \-name core \-type f \-print0 | xargs \-0 /bin/rm -f
891 Find files named 
892 .B core
893 in or below the directory 
894 .B /tmp 
895 and delete them, processing filenames in such a way that file or
896 directory names containing single or double quotes, spaces or newlines
897 are correctly handled.  The
898 .B \-name 
899 test comes before the 
900 .B \-type
901 test in order to avoid having to call 
902 .B stat(2) 
903 on every file.
907 .B find . \-type f \-exec file '{}' \e\;
910 Runs `file' on every file in or below the current directory.  Notice
911 that the braces are enclosed in single quote marks to protect them
912 from interpretation as shell script punctuation.   The semicolon is
913 similarly protected by the use of a backslash, though ';' could have
914 been used in that case also.
918 .B find /  \t( \-perm +4000 \-fprintf /root/suid.txt '%#m %u %p\en' ) , \e
919 .B         \t\t( \-size +100M \-fprintf /root/big.txt  '%\-10s %p\en'  )
922 Traverse the filesystem just once, listing setuid files and
923 directories into
924 .B /root/suid.txt
925 and large files into 
926 .BR /root/big/txt .
930 .B find $HOME  -mtime 0
933 Search for files in your home directory which have been modified in
934 the last twenty-four hours.  This command works this way because the
935 time since each file was last accessed is divided by 24 hours and any 
936 remainder is discarded.  That means that to match 
937 .B -atime 
938 .BR 0 ,
939 a file will have to have a modification in the past which is less than
940 24 hours ago.
945 .B find . -perm 664
948 Search for files which have read and write permission for their owner,
949 and group, but which the rest of the world can read but not write to.  
950 Files which meet these criteria but have other permissions bits set
951 (for example if someone can execute the file) will not be matched.
955 .B find . -perm -664
958 Search for files which have read and write permission for their owner,
959 and group, but which the rest of the world can read but not write to,
960 without regard to the presence of any extra permission bits (for
961 example the executable bit).  This will match a file which has mode
962 0777, for example.
966 .B find . -perm +222
969 Search for files which are writeable by somebody (their owner, or
970 their group, or anybody else).
974 .B find . -perm +022
975 .B find . -perm +g+w,o+w
976 .B find . -perm +g=w,o=w
979 All three of these commands do the same thing, but the first one uses
980 the octal representation of the file mode, and the other two use the
981 symbolic form.  These commands all search for files which are
982 writeable by either their owner or their group.  The files don't have
983 to be writeable by both the owner and group to be matched; either will
988 .B find . -perm -022
989 .B find . -perm -g+w,o+w
992 Both these commands do the same thing; search for files which are
993 writeable by both their owner and their group.
997 .SH EXIT STATUS
999 .B find
1000 exits with status 0 if all files are processed successfully, greater
1001 than 0 if errors occur.   This is deliberately a very broad
1002 description, but if the return value is non-zero, you should not rely
1003 on the correctness of the results of 
1004 .BR find .
1006 .SH "SEE ALSO"
1007 \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1), \fBxargs\fP(1)
1008 \fBFinding Files\fP (on-line in Info, or printed)
1009 .SH "HISTORY"
1010 As of findutils-4.2.2, shell metacharacters ('*'. '?' or '[]' for
1011 example) used in filename patterns will match a leading '.', because
1012 IEEE POSIX interpretation 126 requires this.
1014 .SH "BUGS"
1015 .P 
1016 The best way to report a bug is to use the form at
1017 http://savannah.gnu.org/bugs/?group=findutils.  
1018 The reason for this is that you will then be able to track progress in
1019 fixing the problem.   Other comments about \fBfind\fP(1) and about
1020 the findutils package in general can be sent to the 
1021 .I bug\-findutils
1022 mailing list.  To join the list, send email to 
1023 .IR bug\-findutils\-request@gnu.org .