1 .\" $NetBSD: find.1,v 1.66 2007/07/19 07:49:30 daniel Exp $
3 .\" Copyright (c) 1990, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" This code is derived from software contributed to Berkeley by
7 .\" the Institute of Electrical and Electronics Engineers, Inc.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
17 .\" 3. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" from: @(#)find.1 8.7 (Berkeley) 5/9/95
40 .Nd walk a file hierarchy
43 .Op Fl H | Fl L | Fl P
49 .Op Fl H | Fl L | Fl P
56 recursively descends the directory tree for each
64 listed below) in terms
65 of each file in the tree.
67 The options are as follows:
73 option causes the file information and file type (see
75 returned for each symbolic link encountered on the command line to be
76 those of the file referenced by the link, not the link itself.
77 If the referenced file does not exist, the file information and type will
78 be for the link itself.
79 File information of all symbolic links not on the command line is that
84 option causes the file information and file type (see
86 returned for each symbolic link to be those of the file referenced by the
87 link, not the link itself.
88 If the referenced file does not exist, the file information and type will
89 be for the link itself.
93 option causes the file information and file type (see
95 returned for each symbolic link to be those of the link itself.
101 to perform a depth-first traversal, i.e., directories
102 are visited in post-order and all entries in a directory will be acted
103 on before the directory itself.
106 visits directories in pre-order, i.e., before their contents.
109 a breadth-first traversal.
115 arguments to primaries to be interpreted as extended regular
121 option specifies a file hierarchy for
124 File hierarchies may also be specified as the operands immediately
125 following the options.
129 option causes the file information and file type (see
131 returned for each symbolic link to be those of the file referenced by the
132 link, not the link itself.
133 If the referenced file does not exist, the file information and type will
134 be for the link itself.
138 option causes the entries of each directory to be sorted in
139 lexicographical order.
140 Note that the sorting is done only inside of each directory;
141 files in different directories are not sorted.
146 which is different from
147 .Dq Li "find ... \&| sort"
152 option is a modification to permit
154 to be safely used in conjunction with
156 If a file name contains any of the delimiting characters used by
158 a diagnostic message is displayed on standard error, and the file
160 The delimiting characters include single
166 space, tab and newline characters.
171 primaries can be used to format the output in a way that
177 option restricts the search to the file system containing the
179 Does not list mount points to other file systems.
184 True if the difference between the file last access time and the time
186 was started, rounded up to the next full minute, is
189 .It Ic -anewer Ar file
190 True if the current file has a more recent last access time than
193 True if the difference between the file last access time and the time
195 was started, rounded up to the next full 24-hour period, is
199 True if the difference between the time of last change of file status
200 information and the time
202 was started, rounded up to the next full minute, is
205 .It Ic -cnewer Ar file
206 True if the current file has a more recent last change time than
209 True if the difference between the time of last change of file status
210 information and the time
212 was started, rounded up to the next full 24-hour period, is
216 Delete found files and/or directories.
218 This executes from the current working directory as
220 recurses down the tree.
221 It will not attempt to delete a filename with a
223 character in its pathname relative to
225 for security reasons.
226 Depth-first traversal processing is implied by this option.
227 This can also be invoked as
230 True if the current file or directory is empty.
231 .\" The ".sp" below is probably not the right way to get the desired effect.
232 .It Ic -exec Ar utility Oo argument ... Oc No ;
234 .It Ic -exec Ar utility Oo argument ... Oc No {} +
235 Execute the specified
237 with the specified arguments.
238 The list of arguments is terminated by
243 will be executed from the directory from which
247 If terminated by a semicolon
251 is invoked once per path.
254 appears anywhere in the utility name or the arguments,
255 it is replaced by the pathname of the current file.
257 If terminated by a plus sign
259 the pathnames for which the
260 primary is evaluated are aggregated into sets, and
262 will be invoked once per set, similar to
264 If any invocation exits with non-zero exit status, then
266 will eventually do so as well, but this does not cause
271 must appear, and must appear last.
272 Each set is limitted to no more than 5,000 pathnames,
273 and is also limitted such that the invokation of
277 .It Ic -execdir Ar utility Oo argument ... Oc No ;
280 primary is similar to the semicolon-terminated
284 primary, with the exception that
286 will be executed from the directory that holds
288 The filename substituted for the string
292 .Pq Do \&+ Dc termination
297 to stop traversing the filesystem and exit immediately if a
298 previous condition was met.
299 If no value is specified, the exit value will be 0, else
301 Note that other primaries will be evaluated and acted upon before exiting.
303 This primary always evaluates to false.
304 This can be used following a primary that caused the
305 expression to be true to make the expression to be false.
306 This can be useful after using a
308 primary so it can continue to the next expression (using an
310 operator, for example).
311 .It Ic -flags Oo Fl Oc Ns Ar flags
314 are preceded by a dash
316 this primary evaluates to true
317 if at least all of the bits in
319 are set in the file's flags bits.
322 are not preceded by a dash, this primary evaluates to true if
325 exactly match the file's flags bits.
330 files with no flags bits set are matched.
333 for more information about file flags.)
335 Follow symbolic links.
336 .It Ic -fprint Ar filename
337 This primary always evaluates to true.
340 or overwrites the file if it already exists.
341 The file is created at startup.
342 It writes the pathname of the current file to this file, followed
343 by a newline character.
344 The file will be empty if no files are matched.
345 .It Ic -fstype Ar type
346 True if the file is contained in a file system of type
350 command can be used to find out the types of filesystems
351 that are available on the system:
352 .Bd -literal -offset indent
353 sysctl vfs.generic.fstypes
356 In addition, there are two pseudo-types,
360 The former matches any file system physically mounted on the system where
363 is being executed, and the latter matches any file system which is
365 .It Ic -group Ar gname
366 True if the file belongs to the group
370 is numeric and there is no such group name, then
372 is treated as a group id.
373 .It Ic -iname Ar pattern
374 True if the last component of the pathname being examined
379 True if the file has inode number
381 .It Ic -iregex Ar regexp
382 True if the path name of the current file matches the case-insensitive
383 basic regular expression
384 .Pq see Xr re_format 7
386 This is a match on the whole path, not a search for the regular expression
396 This primary always evaluates to true.
397 The following information for the current file is written to standard output:
398 its inode number, size in 512-byte blocks, file permissions, number of hard
399 links, owner, group, size in bytes, last modification time, and pathname.
400 If the file is a block or character special file, the major and minor numbers
401 will be displayed instead of the size in bytes.
402 If the file is a symbolic link, the pathname of the linked-to file will be
403 displayed preceded by
405 The format is identical to that produced by
407 .It Ic -maxdepth Ar n
408 True if the current search depth is less than or equal to what is specified in
410 .It Ic -mindepth Ar n
411 True if the current search depth is at least what is specified in
414 True if the difference between the file last modification time and the time
416 was started, rounded up to the next full minute, is
420 True if the difference between the file last modification time and the time
422 was started, rounded up to the next full 24-hour period, is
425 .It Ic -ok Ar utility Oo argument ... Oc No ;
428 primary is similar to the semicolon-terminated
432 primary, with the exception that
434 requests user affirmation for the execution of the utility by printing
435 a message to the terminal and reading a response.
436 If the response is other than
438 the command is not executed and the
440 primary evaluates to false.
442 .Pq Do \&+ Dc termination
444 .It Ic -name Ar pattern
445 True if the last component of the pathname being examined matches
447 Special shell pattern matching characters
454 may be used as part of
456 These characters may be matched explicitly by escaping them with a
459 .It Ic -newer Ar file
460 True if the current file has a more recent last modification time than
463 True if the file belongs to an unknown user.
465 True if the file belongs to an unknown group.
466 .It Ic -path Ar pattern
467 True if the pathname being examined matches
469 Special shell pattern matching characters
477 may be used as part of
479 These characters may be matched explicitly by escaping them with a
484 are treated as normal characters and do not have to be
486 .It Ic -perm Oo Fl Oc Ns Ar mode
489 may be either symbolic (see
492 If the mode is symbolic, a starting value of zero is assumed and the
493 mode sets or clears permissions without regard to the process' file mode
495 If the mode is octal, only bits 07777
507 of the file's mode bits participate
509 If the mode is preceded by a dash
511 this primary evaluates to true
512 if at least all of the bits in the mode are set in the file's mode bits.
513 If the mode is not preceded by a dash, this primary evaluates to true if
514 the bits in the mode exactly match the file's mode bits.
515 Note, the first character of a symbolic mode may not be a dash
518 This primary always evaluates to true.
519 It prints the pathname of the current file to standard output, followed
520 by a newline character.
530 is specified, the given expression shall be effectively replaced by
531 .Cm \&( Ns Ar given\& expression Ns Cm \&)
534 This primary always evaluates to true.
535 It prints the pathname of the current file to standard output, followed
538 This primary always evaluates to true.
539 It prints the pathname of the current file to standard output,
540 with each space, tab, newline, backslash, dollar sign, and single,
541 double, or back quotation mark prefixed by a backslash, so the output of
543 can safely be used as input to
546 This primary always evaluates to true.
549 to not descend into the current file.
552 primary has no effect if the
554 option was specified.
555 .It Ic -regex Ar regexp
556 True if the path name of the current file matches the case-sensitive
557 basic regular expression
558 .Pq see Xr re_format 7
560 This is a match on the whole path, not a search for the regular expression
562 .It Ic -size Ar n Ns Op Cm c
563 True if the file's size, rounded up, in 512-byte blocks is
569 then the primary is true if the file's size is
573 True if the file is of the specified type.
574 Possible file types are as follows:
576 .Bl -tag -width flag -offset indent -compact
597 .It Ic -user Ar uname
598 True if the file belongs to the user
602 is numeric and there is no such user name, then
604 is treated as a user id (and considered a numeric argument).
606 This primary always evaluates to true.
607 It causes find not to descend past directories that have a different
608 device ID (st_dev, see
613 All primaries which take a numeric argument allow the number to be
614 preceded by a plus sign
618 A preceding plus sign means
620 a preceding minus sign means
625 The primaries may be combined using the following operators.
626 The operators are listed in order of decreasing precedence.
627 .Bl -tag -width (expression)
628 .It Cm \&( Ar expression Cm \&)
629 This evaluates to true if the parenthesized expression evaluates to
632 .It Cm \&! Ar expression
636 It evaluates to true if the expression is false.
638 .It Ar expression Cm -and Ar expression
639 .It Ar expression expression
642 operator is the logical
645 As it is implied by the juxtaposition of two expressions it does not
646 have to be specified.
647 The expression evaluates to true if both expressions are true.
648 The second expression is not evaluated if the first expression is false.
650 .It Ar expression Cm -or Ar expression
653 operator is the logical
656 The expression evaluates to true if either the first or the second expression
658 The second expression is not evaluated if the first expression is true.
661 All operands and primaries must be separate arguments to
663 Primaries which themselves take arguments expect each argument
664 to be a separate argument to
669 utility normally exits 0 on success, and exits with 1 under certain
670 internal error conditions.
671 If any invokations of
672 .Dq Ic -exec Ar ... No +
673 primaries return non-zero exit-status, then
677 The following examples are shown as given to the shell:
678 .Bl -tag -width findx
679 .It Li "find / \e! -name \*q*.c\*q -print"
680 Print out a list of all the files whose names do not end in
682 .It Li "find / -newer ttt -user wnj -print"
683 Print out a list of all the files owned by user
685 that are newer than the file
687 .It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
688 Print out a list of all the files which are not both newer than
692 .It Li "find / \e( -newer ttt -or -user wnj \e) -print"
693 Print out a list of all the files that are either owned by
695 or that are newer than
697 .It Li "find / \e( -newer ttt -or -user wnj \e) -exit 1"
698 Return immediately with a value of 1 if any files are found that are either
701 or that are newer than
703 but do not print them.
704 .It Li "find / \e( -newer ttt -or -user wnj \e) -ls -exit 1"
705 Same as above, but list the first file matching the criteria before exiting
723 utility syntax is a superset of the syntax specified by the
751 primaries are extensions to
759 options were implemented using the primaries
764 These primaries always evaluated to true.
765 As they were really global variables that took effect before the traversal
766 began, some legal expressions could have unexpected results.
767 An example is the expression
768 .Dq -print -o -depth .
769 As -print always evaluates to true, the standard order of evaluation
770 implies that -depth would never be evaluated.
771 This is not the case.
782 Historic implementations of the
786 primaries did not replace the string
788 in the utility name or the
789 utility arguments if it had preceding or following non-whitespace characters.
790 This version replaces it no matter where in the utility name or arguments
794 .Dq Ic -exec Ar ... No +
796 .Em IEEE PASC Interpretation 1003.2 #210 ,
797 though the feature originated in
802 primary does not interact well with other options that cause the filesystem
803 tree traversal options to be changed.
807 command appeared in First Edition AT\*[Am]T Unix.
808 The syntax had become similar to the present version by
809 the time of the Fifth Edition.
811 The special characters used by
813 are also special characters to many shell programs.
814 In particular, the characters
825 may have to be escaped from the shell.
827 As there is no delimiter separating options and file names or file
830 it is difficult to specify files named
834 These problems are handled by the