Fixed Savannah bug #9923, in which get_short() returns large positive
[findutils.git] / find / find.1
blobe7d976b938fbb411fef7d6c6b99bb1c15c844eef
1 .TH FIND 1 \" -*- nroff -*-
2 .SH NAME
3 find \- search for files in a directory hierarchy
4 .SH SYNOPSIS
5 .B find
6 [path...] [expression]
7 .SH DESCRIPTION
8 This manual page
9 documents the GNU version of
10 .BR find .
11 .B find
12 searches the directory tree rooted at each given file name by
13 evaluating the given expression from left to right, according to the
14 rules of precedence (see section OPERATORS), until the outcome is
15 known (the left hand side is false for \fIand\fR operations, true for
16 \fIor\fR), at which point
17 .B find
18 moves on to the next file name.
19 .PP
20 The first argument that begins with `\-', `(', `)', `,', or `!' is taken
21 to be the beginning of the expression; any arguments before it are
22 paths to search, and any arguments after it are the rest of the
23 expression.  If no paths are given, the current directory is used.  If
24 no expression is given, the expression `\-print' is used (but you
25 should probably consider using `\-print0' instead, anyway).
27 .SH EXPRESSIONS
29 The expression is made up of options (which affect overall operation
30 rather than the processing of a specific file, and always return true),
31 tests (which return a true or false value), and actions (which have side
32 effects and return a true or false value), all separated by operators.
33 \-and is assumed where the operator is omitted.  If the expression contains
34 no actions other than \-prune, \-print is performed on all files
35 for which the expression is true.
36 .SS OPTIONS
38 All options always return true.  They always take effect, rather than
39 being processed only when their place in the expression is reached.
40 Therefore, for clarity, it is best to place them at the beginning of
41 the expression.
42 .IP \-daystart
43 Measure times (for \-amin, \-atime, \-cmin, \-ctime, \-mmin, and \-mtime)
44 from the beginning of today rather than from 24 hours ago.
45 .IP \-depth
46 Process each directory's contents before the directory itself.
47 .IP \-follow
48 Dereference symbolic links.  Implies \-noleaf.
49 .IP "\-help, \-\-help"
50 Print a summary of the command-line usage of
51 .B find
52 and exit.
53 .IP "\-maxdepth \fIlevels\fR"
54 Descend at most \fIlevels\fR (a non-negative integer) levels of
55 directories below the command line arguments.  `\-maxdepth 0' means
56 only apply the tests and actions to the command line arguments.
57 .IP "\-mindepth \fIlevels\fR"
58 Do not apply any tests or actions at levels less than \fIlevels\fR (a
59 non-negative integer).  `\-mindepth 1' means process all files except
60 the command line arguments.
61 .IP \-mount
62 Don't descend directories on other filesystems.  An alternate name for
63 \-xdev, for compatibility with some other versions of
64 .BR find .
65 .IP "\-noleaf"
66 Do not optimize by assuming that directories contain 2 fewer
67 subdirectories than their hard link count.  This option is needed when
68 searching filesystems that do not follow the Unix directory-link
69 convention, such as CD-ROM or MS-DOS filesystems or AFS volume mount
70 points.  Each directory on a normal Unix filesystem has at least 2
71 hard links: its name and its `.'  entry.  Additionally, its
72 subdirectories (if any) each have a `..'  entry linked to that
73 directory.  When
74 .B find
75 is examining a directory, after it has statted 2 fewer subdirectories
76 than the directory's link count, it knows that the rest of the entries
77 in the directory are non-directories (`leaf' files in the directory
78 tree).  If only the files' names need to be examined, there is no need
79 to stat them; this gives a significant increase in search speed.
80 .IP "\-version, \-\-version"
81 Print the \fBfind\fR version number and exit.
82 .IP \-xdev
83 Don't descend directories on other filesystems.
84 .SS TESTS
86 Numeric arguments can be specified as
87 .IP \fI+n\fP
88 for greater than
89 .IR n ,
90 .IP \fI\-n\fP
91 for less than
92 .IR n ,
93 .IP \fIn\fP
94 for exactly
95 .IR n .
96 .IP "\-amin \fIn\fR"
97 File was last accessed \fIn\fR minutes ago.
98 .IP "\-anewer \fIfile\fR"
99 File was last accessed more recently than \fIfile\fR was modified.
100 \-anewer is affected by \-follow only if \-follow comes before
101 \-anewer on the command line.
102 .IP "\-atime \fIn\fR"
103 File was last accessed \fIn\fR*24 hours ago.
104 .IP "\-cmin \fIn\fR"
105 File's status was last changed \fIn\fR minutes ago.
106 .IP "\-cnewer \fIfile\fR"
107 File's status was last changed more recently than \fIfile\fR was modified.
108 \-cnewer is affected by \-follow only if \-follow comes before
109 \-cnewer on the command line.
110 .IP "\-ctime \fIn\fR"
111 File's status was last changed \fIn\fR*24 hours ago.
112 .IP \-empty
113 File is empty and is either a regular file or a directory.
114 .IP \-false
115 Always false.
116 .IP "\-fstype \fItype\fR"
117 File is on a filesystem of type \fItype\fR.  The valid filesystem
118 types vary among different versions of Unix; an incomplete list of
119 filesystem types that are accepted on some version of Unix or another
120 is: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K.  You can use \-printf
121 with the %F directive to see the types of your filesystems.
122 .IP "\-gid \fIn\fR"
123 File's numeric group ID is \fIn\fR.
124 .IP "\-group \fIgname\fR"
125 File belongs to group \fIgname\fR (numeric group ID allowed).
126 .IP "\-ilname \fIpattern\fR"
127 Like \-lname, but the match is case insensitive.
128 .IP "\-iname \fIpattern\fR"
129 Like \-name, but the match is case insensitive.  For example, the
130 patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo',
131 `fOo', etc.
132 .IP "\-inum \fIn\fR"
133 File has inode number \fIn\fR.
134 .IP "\-ipath \fIpattern\fR"
135 Like \-path, but the match is case insensitive.
136 .IP "\-iregex \fIpattern\fR"
137 Like \-regex, but the match is case insensitive.
138 .IP "\-links \fIn\fR"
139 File has \fIn\fR links.
140 .IP "\-lname \fIpattern\fR"
141 File is a symbolic link whose contents match shell pattern
142 \fIpattern\fR.  The metacharacters do not treat `/' or `.' specially.
143 .IP "\-mmin \fIn\fR"
144 File's data was last modified \fIn\fR minutes ago.
145 .IP "\-mtime \fIn\fR"
146 File's data was last modified \fIn\fR*24 hours ago.
147 .IP "\-name \fIpattern\fR"
148 Base of file name (the path with the leading directories removed)
149 matches shell pattern \fIpattern\fR.  The metacharacters (`*', `?',
150 and `[]') do not match a `.' at the start of the base name.  To ignore
151 a directory and the files under it, use \-prune; see an example in the
152 description of \-path.  Braces are not recognised as being special,
153 despite the fact that some shells including Bash ibmue braces with 
154 a special meaning in shell patterns.   The filename matching is
155 performed with the use of the 
156 .BR fnmatch (3) 
157 library function.
158 .IP "\-newer \fIfile\fR"
159 File was modified more recently than \fIfile\fR.
160 \-newer is affected by \-follow only if \-follow comes before
161 \-newer on the command line.
162 .IP \-nouser
163 No user corresponds to file's numeric user ID.
164 .IP \-nogroup
165 No group corresponds to file's numeric group ID.
166 .IP "\-path \fIpattern\fR"
167 File name matches shell pattern \fIpattern\fR.  The metacharacters do
168 not treat `/' or `.' specially; so, for example,
170 .in +1i
171 find . \-path './sr*sc'
173 .in -1i
174 will print an entry for a directory called './src/misc' (if one
175 exists).  To ignore a whole directory tree, use \-prune rather than
176 checking every file in the tree.  For example, to skip the
177 directory `src/emacs' and all files and directories under it, and
178 print the names of the other files found, do something like this:
180 .in +1i
181 find . \-path './src/emacs' -prune -o -print
183 .in -1i
184 .IP "\-perm \fImode\fR"
185 File's permission bits are exactly \fImode\fR (octal or symbolic).
186 Symbolic modes use mode 0 as a point of departure.
187 .IP "\-perm \-\fImode\fR"
188 All of the permission bits \fImode\fR are set for the file.
189 .IP "\-perm +\fImode\fR"
190 Any of the permission bits \fImode\fR are set for the file.
191 .IP "\-regex \fIpattern\fR"
192 File name matches regular expression \fIpattern\fR.  This is a match
193 on the whole path, not a search.  For example, to match a file named
194 `./fubar3', you can use the regular expression `.*bar.' or `.*b.*3',
195 but not `b.*r3'.  The regular expressions understood by 
196 .B find 
197 follow the conventions for the 
198 .B re_match 
199 system library function where this is present (i.e. on systems using
200 the GNU C Library).  On other systems, the implementation within
201 Gnulib is used; by default, Gnulib provides "basic" regular
202 expressions.
203 .IP "\-size \fIn\fR[cwbkMG]"
204 File uses \fIn\fP units of space.  The following suffixes 
205 can be used:
207 .IP `b' 
208 for 512-byte blocks (this is the default if no suffix is used)
209 .IP `c' 
210 for bytes
211 .IP `w' 
212 for two-byte words
213 .IP `k' 
214 for Kilobytes (units of 1024 bytes)
215 .IP `M' 
216 for Megabytes (units of 1048576 bytes)
217 .IP `G' 
218 for Gigabytes (units of 1073741824 bytes)
221 The size does not count indirect blocks, but it does count blocks in
222 sparse files that are not actually allocated.  Bear in mind that the
223 `%k' and `%b' format specifiers of \-printf handle sparse files
224 differently.  The `b' suffix always denotes 512-byte blocks and never
225 1 Kilobyte blocks, which is different to the behaviour of \-ls.
227 .IP \-true
228 Always true.
229 .IP "\-type \fIc\fR"
230 File is of type \fIc\fR:
232 .IP b
233 block (buffered) special
234 .IP c
235 character (unbuffered) special
236 .IP d
237 directory
238 .IP p
239 named pipe (FIFO)
240 .IP f
241 regular file
242 .IP l
243 symbolic link
244 .IP s
245 socket
246 .IP D
247 door (Solaris)
249 .IP "\-uid \fIn\fR"
250 File's numeric user ID is \fIn\fR.
251 .IP "\-used \fIn\fR"
252 File was last accessed \fIn\fR days after its status was last changed.
253 .IP "\-user \fIuname\fR"
254 File is owned by user \fIuname\fR (numeric user ID allowed).
255 .IP "\-xtype \fIc\fR"
256 The same as \-type unless the file is a symbolic link.  For symbolic
257 links: if \-follow has not been given, true if the file is a link to a
258 file of type \fIc\fR; if \-follow has been given, true if \fIc\fR is
259 `l'.  In other words, for symbolic links, \-xtype checks the type of
260 the file that \-type does not check.
261 .SS ACTIONS
262 .IP "\-exec \fIcommand\fR ;"
263 Execute \fIcommand\fR; true if 0 status is returned.  All following
264 arguments to
265 .B find
266 are taken to be arguments to the command until an argument consisting
267 of `;' is encountered.  The string `{}' is replaced by the current
268 file name being processed everywhere it occurs in the arguments to the
269 command, not just in arguments where it is alone, as in some versions
271 .BR find .
272 Both of these constructions might need to be escaped (with a `\e') or
273 quoted to protect them from expansion by the shell.  See the
274 .B EXAMPLES
275 section for examples of the use of the `-exec' option.
276 The command is
277 executed in the starting directory.
279 .IP "\-fls \fIfile\fR"
280 True; like \-ls but write to \fIfile\fR like \-fprint.
281 The output file is always created, even if the predicate is never matched.
282 .IP "\-fprint \fIfile\fR"
283 True; print the full file name into file \fIfile\fR.  If \fIfile\fR
284 does not exist when \fBfind\fR is run, it is created; if it does
285 exist, it is truncated.  The file names ``/dev/stdout'' and
286 ``/dev/stderr'' are handled specially; they refer to the standard
287 output and standard error output, respectively.
288 The output file is always created, even if the predicate is never matched.
289 .IP "\-fprint0 \fIfile\fR"
290 True; like \-print0 but write to \fIfile\fR like \-fprint.
291 The output file is always created, even if the predicate is never matched.
292 .IP "\-fprintf \fIfile\fR \fIformat\fR"
293 True; like \-printf but write to \fIfile\fR like \-fprint.
294 The output file is always created, even if the predicate is never matched.
295 .IP "\-ok \fIcommand\fR ;"
296 Like \-exec but ask the user first (on the standard input); if the
297 response does not start with `y' or `Y', do not run the command, and
298 return false.
299 .IP \-print
300 True; print the full file name on the standard output, followed by a
301 newline.   If you are piping the output of 
302 .B find 
303 into another program and there is the faintest possibility that the files 
304 which you are searching for might contain a newline, then you should 
305 seriously consider using the `\-print0' option instead of `\-print'.
307 .IP \-print0
308 True; print the full file name on the standard output, followed by a
309 null character (instead of the newline character that `-print' uses).
310 This allows file names that contain newlines or other types of white
311 space to be correctly interpreted by programs that process the
312 \fBfind\fR output.  This option corresponds to the `\-0' option of
313 .BR xargs .
314 .IP "\-printf \fIformat\fR"
315 True; print \fIformat\fR on the standard output, interpreting `\e'
316 escapes and `%' directives.  Field widths and precisions can be
317 specified as with the `printf' C function.  Unlike \-print, \-printf
318 does not add a newline at the end of the string.  The escapes and
319 directives are:
321 .IP \ea
322 Alarm bell.
323 .IP \eb
324 Backspace.
325 .IP \ec
326 Stop printing from this format immediately and flush the output.
327 .IP \ef
328 Form feed.
329 .IP \en
330 Newline.
331 .IP \er
332 Carriage return.
333 .IP \et
334 Horizontal tab.
335 .IP \ev
336 Vertical tab.
337 .IP \e\0
338 ASCII NUL.
339 .IP \e\e
340 A literal backslash (`\e').
341 .IP \eNNN
342 The character whose ASCII code is NNN (octal).
344 A `\e' character followed by any other character is treated as an
345 ordinary character, so they both are printed.
346 .IP %%
347 A literal percent sign.
348 .IP %a
349 File's last access time in the format returned by the C `ctime' function.
350 .IP %A\fIk\fP
351 File's last access time in the format specified by \fIk\fR, which is
352 either `@' or a directive for the C `strftime' function.  The possible
353 values for \fIk\fR are listed below; some of them might not be
354 available on all systems, due to differences in `strftime' between
355 systems.
357 .IP @
358 seconds since Jan. 1, 1970, 00:00 GMT.
360 Time fields:
361 .IP H
362 hour (00..23)
363 .IP I
364 hour (01..12)
365 .IP k
366 hour ( 0..23)
367 .IP l
368 hour ( 1..12)
369 .IP M
370 minute (00..59)
371 .IP p
372 locale's AM or PM
373 .IP r
374 time, 12-hour (hh:mm:ss [AP]M)
375 .IP S
376 second (00..61)
377 .IP T
378 time, 24-hour (hh:mm:ss)
379 .IP X
380 locale's time representation (H:M:S)
381 .IP Z
382 time zone (e.g., EDT), or nothing if no time zone is determinable
384 Date fields:
385 .IP a
386 locale's abbreviated weekday name (Sun..Sat)
387 .IP A
388 locale's full weekday name, variable length (Sunday..Saturday)
389 .IP b
390 locale's abbreviated month name (Jan..Dec)
391 .IP B
392 locale's full month name, variable length (January..December)
393 .IP c
394 locale's date and time (Sat Nov 04 12:02:33 EST 1989)
395 .IP d
396 day of month (01..31)
397 .IP D
398 date (mm/dd/yy)
399 .IP h
400 same as b
401 .IP j
402 day of year (001..366)
403 .IP m
404 month (01..12)
405 .IP U
406 week number of year with Sunday as first day of week (00..53)
407 .IP w
408 day of week (0..6)
409 .IP W
410 week number of year with Monday as first day of week (00..53)
411 .IP x
412 locale's date representation (mm/dd/yy)
413 .IP y
414 last two digits of year (00..99)
415 .IP Y
416 year (1970...)
418 .IP %b
419 File's size in 512-byte blocks (rounded up).
420 .IP %c
421 File's last status change time in the format returned by the C `ctime'
422 function.
423 .IP %C\fIk\fP
424 File's last status change time in the format specified by \fIk\fR,
425 which is the same as for %A.
426 .IP %d
427 File's depth in the directory tree; 0 means the file is a command line
428 argument.
429 .IP %f
430 File's name with any leading directories removed (only the last element).
431 .IP %F
432 Type of the filesystem the file is on; this value can be used for
433 \-fstype.
434 .IP %g
435 File's group name, or numeric group ID if the group has no name.
436 .IP %G
437 File's numeric group ID.
438 .IP %h
439 Leading directories of file's name (all but the last element).
440 .IP %H
441 Command line argument under which file was found.
442 .IP %i
443 File's inode number (in decimal).
444 .IP %k
445 The amount of disk space used for this file in 1K blocks (rounded
446 up).  This is different from %s/1024 if the file is a sparse file.
447 .IP %l
448 Object of symbolic link (empty string if file is not a symbolic link).
449 .IP %m
450 File's permission bits (in octal).
451 .IP %n
452 Number of hard links to file.
453 .IP %p
454 File's name.
455 .IP %P
456 File's name with the name of the command line argument under which
457 it was found removed.
458 .IP %s
459 File's size in bytes.
460 .IP %t
461 File's last modification time in the format returned by the C `ctime'
462 function.
463 .IP %T\fIk\fP
464 File's last modification time in the format specified by \fIk\fR, 
465 which is the same as for %A.
466 .IP %u
467 File's user name, or numeric user ID if the user has no name.
468 .IP %U
469 File's numeric user ID.
471 A `%' character followed by any other character is discarded (but the
472 other character is printed).
474 .IP \-prune
475 If \-depth is not given, true; do not descend the current directory.
477 If \-depth is given, false; no effect.
478 .IP \-ls
479 True; list current file in `ls \-dils' format on standard output.
480 The block counts are of 1K blocks, unless the environment variable
481 POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
482 .IP \-ignore_readdir_race
483 Normally, \fBfind\fR will emit an error message when it fails to stat a file.
484 If you give this option and a file is deleted between the time \fBfind\fR 
485 reads the name of the file from the directory and the time it tries to stat 
486 the file, nno error message will be issued.    This also applies to files
487 or directories whose names are given on the command line.  This option takes
488 effect at the time the command line is read, which means that you cannot search
489 one part of the filesystem with this option on and part of it with this option
490 off (if you need to do that, you will need to issue two \fBfind\fR commands
491 instead, one with the option and one without it).
492 .IP \-noignore_readdir_race
493 Turns off the effect of \-ignore_readdir_race. 
494 .SS OPERATORS
496 Listed in order of decreasing precedence:
497 .IP "( \fIexpr\fR )"
498 Force precedence.
499 .IP "! \fIexpr\fR"
500 True if \fIexpr\fR is false.
501 .IP "\-not \fIexpr\fR"
502 Same as ! \fIexpr\fR.
503 .IP "\fIexpr1 expr2\fR"
504 And (implied); \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
505 .IP "\fIexpr1\fR \-a \fIexpr2\fR"
506 Same as \fIexpr1 expr2\fR.
507 .IP "\fIexpr1\fR \-and \fIexpr2\fR"
508 Same as \fIexpr1 expr2\fR.
509 .IP "\fIexpr1\fR \-o \fIexpr2\fR"
510 Or; \fIexpr2\fR is not evaluated if \fIexpr1\fR is true.
511 .IP "\fIexpr1\fR \-or \fIexpr2\fR"
512 Same as \fIexpr1\fR \-o \fIexpr2\fR.
513 .IP "\fIexpr1\fR , \fIexpr2\fR"
514 List; both \fIexpr1\fR and \fIexpr2\fR are always evaluated.
515 The value of \fIexpr1\fR is discarded; the value of the list is the
516 value of \fIexpr2\fR.
518 .SH "STANDARDS CONFORMANCE"
519 The following options are specified in the POSIX standard 
520 (IEEE Std 1003.1, 2003 Edition):
521 .IP "\-name"
522 This option is supported, but POSIX conformance depends on the 
523 POSIX conformance of the system's 
524 .BR fnmatch (3) 
525 library function.
527 .IP "\-type"
528 Supported.   POSIX specifies `b', `c', `d', `l', `p', `f' and `s'.
529 GNU find also supports `D', representing a Door, where the OS provides these.
531 .IP "\-ok"
532 Supported.   Interpretation of the response is not locale-dependent
533 (see ENVIRONMENT VARIABLES).
535 .IP "Other predicates"
536 The predicates
537 `-atime',
538 `-ctime',
539 `-depth',
540 `-exec',
541 `-group',
542 `-links',
543 `-mtime',
544 `-newer',
545 `-nogroup',
546 `-nouser',
547 `-perm',
548 `-print',
549 `-prune',
550 `-size',
551 `-user' and 
552 `-xdev',
553 are all supported.
556 The POSIX standard specifies parentheses `(', `)', negation `!' and the
557 `and' and `or' operators (`-a', `-o').   
559 All other options, predicates, expressions and so forth are extensions 
560 beyond the POSIX standard.  Many of these extensions are not unique to 
561 GNU find, however.
562 .SH "ENVIRONMENT VARIABLES"
563 .IP POSIXLY_CORRECT
564 Determines the block size used by `-ls'.
565 .IP LANG
566 Provides a default value for the internationalization variables that
567 are unset or null.
568 .IP LC_ALL
569 If set to a non-empty string value, override the values of all the
570 other internationalization variables.
571 .IP LC_COLLATE
572 The POSIX standard specifies that this variable affects the pattern
573 matching to be used for the `-name' option.   GNU find uses the 
574 .BR fnmatch (3) 
575 library function, and so support for `LC_COLLATE' depends on the
576 system library.    
578 POSIX also specifies that the `LC_COLLATE' environment 
579 variable affects the interpretation of the user's response to the 
580 query issued by `-ok', but this is not the case for GNU find.
581 .IP LC_CTYPE 
582 This variable affects the treatment of character classes used with 
583 the `-name' option, if the system's 
584 .BR fnmatch (3) 
585 library function supports this.   It has no effect on the behaviour 
586 of the `-ok' expression.
587 .IP LC_MESSAGES
588 Determines the locale to be used for internationalised messages.
589 .IP NLSPATH
590 Determines the location of the internationalisation message catalogues.
591 .IP PATH
592 Affects the directores which are searched to find the executables 
593 invoked by `-exec' and `-ok'.
594 .SH "EXAMPLES"
596 .B find /tmp -name core -type f -print | xargs /bin/rm -f
599 Find files named 
600 .B core
601 in or below the directory 
602 .B /tmp 
603 and delete them.  Note that this will work incorrectly if there are 
604 any filenames containing newlines or spaces.
606 .B find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
609 Find files named 
610 .B core
611 in or below the directory 
612 .B /tmp 
613 and delete them, processing filenames in such a way that file or 
614 directory names containing spaces or newlines are correctly handled.
617 .B cut -d: -f1 < /etc/passwd | sort | xargs echo
620 Generates a compact listing of all the users on the system.
624 .B find . -type f -exec file '{}' \e\;
627 Runs `file' on every file in or below the current directory.  Notice
628 that the braces are enclosed in single quote marks to protect them
629 from interpretation as shell script punctuation.   The semicolon is
630 similarly protected by the use of a backslash, though ';' could have
631 been used in that case also.
633 .SH EXIT STATUS
635 .B find
636 exits with status 0 if all files are processed successfully, greater
637 than 0 if errors occur.
638 .SH "SEE ALSO"
639 \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1), \fBxargs\fP(1)
640 \fBFinding Files\fP (on-line in Info, or printed)
641 .SH "BUGS"
642 .P 
643 The best way to report a bug is to use the form at
644 http://savannah.gnu.org/bugs/?group=findutils.  
645 The reason for this is that you will then be able to track progress in
646 fixing the problem.   Other comments about \fBfind\fP(1) and about
647 the findutils package in general can be sent to the 
648 .I bug-findutils
649 mailing list.  To join the list, send email to 
650 .IR bug-findutils-request@gnu.org .