1 .\" $NetBSD: find.1,v 1.68 2009/10/15 02:26:38 joerg 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.
182 .Bl -tag -width Ds -compact
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
190 .It Ic -anewer Ar file
191 True if the current file has a more recent last access time than
195 True if the difference between the file last access time and the time
197 was started, rounded up to the next full 24-hour period, is
202 True if the difference between the time of last change of file status
203 information and the time
205 was started, rounded up to the next full minute, is
209 .It Ic -cnewer Ar file
210 True if the current file has a more recent last change time than
214 True if the difference between the time of last change of file status
215 information and the time
217 was started, rounded up to the next full 24-hour period, is
222 Delete found files, symbolic links and directories.
224 This executes from the current working directory as
226 recurses down the tree.
227 To avoid deleting unexpected files, it will ignore any filenames that
229 returns that contain a
232 should not return such pathnames).
233 Depth-first traversal processing is implied by this option.
234 This can also be invoked as
238 True if the current file or directory is empty.
240 .It Ic -exec Ar utility Oo argument ... Oc No ;
241 .It Ic -exec Ar utility Oo argument ... Oc No {} +
242 Execute the specified
244 with the specified arguments.
245 The list of arguments is terminated by
250 will be executed from the directory from which
254 If terminated by a semicolon
258 is invoked once per path.
261 appears anywhere in the utility name or the arguments,
262 it is replaced by the pathname of the current file.
264 If terminated by a plus sign
266 the pathnames for which the
267 primary is evaluated are aggregated into sets, and
269 will be invoked once per set, similar to
271 If any invocation exits with non-zero exit status, then
273 will eventually do so as well, but this does not cause
278 must appear, and must appear last.
279 Each set is limitted to no more than 5,000 pathnames,
280 and is also limitted such that the invokation of
285 .It Ic -execdir Ar utility Oo argument ... Oc No ;
288 primary is similar to the semicolon-terminated
292 primary, with the exception that
294 will be executed from the directory that holds
296 The filename substituted for the string
300 .Pq Do \&+ Dc termination
306 to stop traversing the filesystem and exit immediately if a
307 previous condition was met.
308 If no value is specified, the exit value will be 0, else
310 Note that other primaries will be evaluated and acted upon before exiting.
313 This primary always evaluates to false.
314 This can be used following a primary that caused the
315 expression to be true to make the expression to be false.
316 This can be useful after using a
318 primary so it can continue to the next expression (using an
320 operator, for example).
322 .It Ic -flags Oo Fl Oc Ns Ar flags
325 are preceded by a dash
327 this primary evaluates to true
328 if at least all of the bits in
330 are set in the file's flags bits.
333 are not preceded by a dash, this primary evaluates to true if
336 exactly match the file's flags bits.
341 files with no flags bits set are matched.
344 for more information about file flags.)
347 Follow symbolic links.
349 .It Ic -fprint Ar filename
350 This primary always evaluates to true.
353 or overwrites the file if it already exists.
354 The file is created at startup.
355 It writes the pathname of the current file to this file, followed
356 by a newline character.
357 The file will be empty if no files are matched.
359 .It Ic -fstype Ar type
360 True if the file is contained in a file system of type
364 command can be used to find out the types of filesystems
365 that are available on the system:
366 .Bd -literal -offset indent
367 sysctl vfs.generic.fstypes
370 In addition, there are two pseudo-types,
374 The former matches any file system physically mounted on the system where
377 is being executed, and the latter matches any file system which is
380 .It Ic -group Ar gname
381 True if the file belongs to the group
385 is numeric and there is no such group name, then
387 is treated as a group id.
389 .It Ic -iname Ar pattern
390 True if the last component of the pathname being examined
396 True if the file has inode number
399 .It Ic -iregex Ar regexp
400 True if the path name of the current file matches the case-insensitive
401 basic regular expression
402 .Pq see Xr re_format 7
404 This is a match on the whole path, not a search for the regular expression
417 This primary always evaluates to true.
418 The following information for the current file is written to standard output:
419 its inode number, size in 512-byte blocks, file permissions, number of hard
420 links, owner, group, size in bytes, last modification time, and pathname.
421 If the file is a block or character special file, the major and minor numbers
422 will be displayed instead of the size in bytes.
423 If the file is a symbolic link, the pathname of the linked-to file will be
424 displayed preceded by
426 The format is identical to that produced by
429 .It Ic -maxdepth Ar n
430 True if the current search depth is less than or equal to what is specified in
433 .It Ic -mindepth Ar n
434 True if the current search depth is at least what is specified in
438 True if the difference between the file last modification time and the time
440 was started, rounded up to the next full minute, is
445 True if the difference between the file last modification time and the time
447 was started, rounded up to the next full 24-hour period, is
451 .It Ic -ok Ar utility Oo argument ... Oc No ;
454 primary is similar to the semicolon-terminated
458 primary, with the exception that
460 requests user affirmation for the execution of the utility by printing
461 a message to the terminal and reading a response.
462 If the response is other than
464 the command is not executed and the
466 primary evaluates to false.
468 .Pq Do \&+ Dc termination
471 .It Ic -name Ar pattern
472 True if the last component of the pathname being examined matches
474 Special shell pattern matching characters
481 may be used as part of
483 These characters may be matched explicitly by escaping them with a
487 .It Ic -newer Ar file
488 True if the current file has a more recent last modification time than
492 True if the file belongs to an unknown user.
495 True if the file belongs to an unknown group.
497 .It Ic -path Ar pattern
498 True if the pathname being examined matches
500 Special shell pattern matching characters
508 may be used as part of
510 These characters may be matched explicitly by escaping them with a
515 are treated as normal characters and do not have to be
518 .It Ic -perm Oo Fl Oc Ns Ar mode
521 may be either symbolic (see
524 If the mode is symbolic, a starting value of zero is assumed and the
525 mode sets or clears permissions without regard to the process' file mode
527 If the mode is octal, only bits 07777
539 of the file's mode bits participate
541 If the mode is preceded by a dash
543 this primary evaluates to true
544 if at least all of the bits in the mode are set in the file's mode bits.
545 If the mode is not preceded by a dash, this primary evaluates to true if
546 the bits in the mode exactly match the file's mode bits.
547 Note, the first character of a symbolic mode may not be a dash
551 This primary always evaluates to true.
552 It prints the pathname of the current file to standard output, followed
553 by a newline character.
563 is specified, the given expression shall be effectively replaced by
564 .Cm \&( Ns Ar given\& expression Ns Cm \&)
568 This primary always evaluates to true.
569 It prints the pathname of the current file to standard output, followed
573 This primary always evaluates to true.
574 It prints the pathname of the current file to standard output,
575 with each space, tab, newline, backslash, dollar sign, and single,
576 double, or back quotation mark prefixed by a backslash, so the output of
578 can safely be used as input to
582 This primary always evaluates to true.
585 to not descend into the current file.
588 primary has no effect if the
590 option was specified.
592 .It Ic -regex Ar regexp
593 True if the path name of the current file matches the case-sensitive
594 basic regular expression
595 .Pq see Xr re_format 7
597 This is a match on the whole path, not a search for the regular expression
600 .It Ic -size Ar n Ns Op Cm c
601 True if the file's size, rounded up, in 512-byte blocks is
607 then the primary is true if the file's size is
612 True if the file is of the specified type.
613 Possible file types are as follows:
615 .Bl -tag -width flag -offset indent -compact
636 .It Ic -user Ar uname
637 True if the file belongs to the user
641 is numeric and there is no such user name, then
643 is treated as a user id (and considered a numeric argument).
646 This primary always evaluates to true.
647 It causes find not to descend past directories that have a different
648 device ID (st_dev, see
653 All primaries which take a numeric argument allow the number to be
654 preceded by a plus sign
658 A preceding plus sign means
660 a preceding minus sign means
665 The primaries may be combined using the following operators.
666 The operators are listed in order of decreasing precedence.
667 .Bl -tag -width (expression)
668 .It Cm \&( Ar expression Cm \&)
669 This evaluates to true if the parenthesized expression evaluates to
672 .It Cm \&! Ar expression
676 It evaluates to true if the expression is false.
678 .It Ar expression Cm -and Ar expression
679 .It Ar expression expression
682 operator is the logical
685 As it is implied by the juxtaposition of two expressions it does not
686 have to be specified.
687 The expression evaluates to true if both expressions are true.
688 The second expression is not evaluated if the first expression is false.
690 .It Ar expression Cm -or Ar expression
693 operator is the logical
696 The expression evaluates to true if either the first or the second expression
698 The second expression is not evaluated if the first expression is true.
701 All operands and primaries must be separate arguments to
703 Primaries which themselves take arguments expect each argument
704 to be a separate argument to
709 utility normally exits 0 on success, and exits with 1 under certain
710 internal error conditions.
711 If any invokations of
712 .Dq Ic -exec Ar ... No +
713 primaries return non-zero exit-status, then
717 The following examples are shown as given to the shell:
718 .Bl -tag -width findx
719 .It Li "find / \e! -name \*q*.c\*q -print"
720 Print out a list of all the files whose names do not end in
722 .It Li "find / -newer ttt -user wnj -print"
723 Print out a list of all the files owned by user
725 that are newer than the file
727 .It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
728 Print out a list of all the files which are not both newer than
732 .It Li "find / \e( -newer ttt -or -user wnj \e) -print"
733 Print out a list of all the files that are either owned by
735 or that are newer than
737 .It Li "find / \e( -newer ttt -or -user wnj \e) -exit 1"
738 Return immediately with a value of 1 if any files are found that are either
741 or that are newer than
743 but do not print them.
744 .It Li "find / \e( -newer ttt -or -user wnj \e) -ls -exit 1"
745 Same as above, but list the first file matching the criteria before exiting
763 utility syntax is a superset of the syntax specified by the
791 primaries are extensions to
799 options were implemented using the primaries
804 These primaries always evaluated to true.
805 As they were really global variables that took effect before the traversal
806 began, some legal expressions could have unexpected results.
807 An example is the expression
808 .Dq -print -o -depth .
809 As -print always evaluates to true, the standard order of evaluation
810 implies that -depth would never be evaluated.
811 This is not the case.
822 Historic implementations of the
826 primaries did not replace the string
828 in the utility name or the
829 utility arguments if it had preceding or following non-whitespace characters.
830 This version replaces it no matter where in the utility name or arguments
834 .Dq Ic -exec Ar ... No +
836 .Em IEEE PASC Interpretation 1003.2 #210 ,
837 though the feature originated in
842 primary does not interact well with other options that cause the filesystem
843 tree traversal options to be changed.
847 command appeared in First Edition AT\*[Am]T Unix.
848 The syntax had become similar to the present version by
849 the time of the Fifth Edition.
851 The special characters used by
853 are also special characters to many shell programs.
854 In particular, the characters
865 may have to be escaped from the shell.
867 As there is no delimiter separating options and file names or file
870 it is difficult to specify files named
874 These problems are handled by the