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