1 .\" $NetBSD: find.1,v 1.81 2014/05/17 11:31:40 apb 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:
70 Causes the file information and file type (see
72 returned for each symbolic link encountered on the command line to be
73 those of the file referenced by the link, not the link itself.
74 If the referenced file does not exist, the file information and type will
75 be for the link itself.
76 File information of all symbolic links not on the command line is that
79 Causes the file information and file type (see
81 returned for each symbolic link to be those of the file referenced by the
82 link, not the link itself.
83 If the referenced file does not exist, the file information and type will
84 be for the link itself.
86 Causes the file information and file type (see
88 returned for each symbolic link to be those of the link itself.
92 to perform a depth-first traversal, i.e., directories
93 are visited in post-order, and all entries in a directory will be acted
94 on before the directory itself.
97 visits directories in pre-order, i.e., before their contents.
100 a breadth-first traversal.
104 arguments to primaries to be interpreted as extended regular
108 Specifies a file hierarchy for
111 File hierarchies may also be specified as the operands immediately
112 following the options.
114 Causes the file information and file type (see
116 returned for each symbolic link to be those of the file referenced by the
117 link, not the link itself.
118 If the referenced file does not exist, the file information and type will
119 be for the link itself.
121 Causes the entries of each directory to be sorted in
122 lexicographical order.
123 Note that the sorting is done only inside of each directory;
124 files in different directories are not sorted.
129 which is different from
130 .Dq Li "find ... \&| sort"
133 Modifies the output to permit
135 to be safely used in conjunction with
137 If a file name contains any of the delimiting characters used by
139 a diagnostic message is displayed on standard error, and the file
141 The delimiting characters include single
147 space, tab, and newline characters.
152 primaries can be used to format the output in a way that
156 Restricts the search to the file system containing the
158 Does not list mount points to other file systems.
161 All primaries which take a numeric argument of
163 allow the number to be preceded by a plus sign
167 A preceding plus sign means
169 a preceding minus sign means
174 .Bl -tag -width Ds -compact
176 True if the difference between the file last access time and the time
178 was started, rounded up to the next full minute, is
182 .It Ic -anewer Ar file
183 True if the current file has a more recent last access time than
187 True if the difference between the file last access time and the time
189 was started, rounded up to the next full 24-hour period, is
194 True if the difference between the time of last change of file status
195 information and the time
197 was started, rounded up to the next full minute, is
201 .It Ic -cnewer Ar file
202 True if the current file has a more recent last change time than
206 True if the difference between the time of last change of file status
207 information and the time
209 was started, rounded up to the next full 24-hour period, is
214 Delete found files, symbolic links, and directories.
216 This executes from the current working directory as
218 recurses down the tree.
219 To avoid deleting unexpected files, it will ignore any filenames that
221 returns that contain a
224 should not return such pathnames).
225 Depth-first traversal processing is implied by this option.
226 This primary can also be invoked as
230 True if the current file or directory is empty.
232 .It Ic -exec Ar utility Oo argument ... Oc Ic \&;
233 .It Ic -exec Ar utility Oo argument ... Oc Ic {} Ic \&+
234 Execute the specified
236 with the specified arguments.
238 The list of arguments for
240 is terminated by a lone semicolon
244 character as a separate parameter.
245 The command specified by
247 will be executed with its current working directory being the directory
252 If the list of arguments is terminated by a semicolon
256 is invoked once per pathname.
260 appears one or more times in the utility name or arguments,
261 then it is replaced by the pathname of the current file
262 (but it need not appear, in which case the pathname
263 will not be passed to
265 The semicolon-terminated form of the
267 primary returns true if and only if
269 exits with a zero exit status.
270 Note that the semicolon will have to be escaped on the shell command line
271 in order to be passed as a parameter.
273 If the list of arguments is terminated by a plus sign
275 then the pathnames for which the primary is evaluated are aggregated
278 will be invoked once per set, similar to
280 In this case the string
282 must appear, and must appear as the last item in the argument list,
285 parameter, and is replaced by the pathnames of the current set of files.
286 Each set is limited to no more than 5,000 pathnames,
287 and is also limited such that the total number of bytes in the argument
290 The plus-terminated form of the
292 primary always returns true.
293 If the plus-terminated form of the
295 primary results in any invocation of
297 exiting with non-zero exit status, then
299 will eventually exit with non-zero status as well,
300 but this does not cause
304 .It Ic -execdir Ar utility Oo argument ... Oc Ic \&;
307 primary is similar to the semicolon-terminated
311 primary, with the exception that
313 will be executed from the directory that holds
315 Only the base filename is substituted for the string
318 .Pq Do Ic \&+ Dc termination
321 .It Ic -exit Op Ar status
324 to stop traversing the file system and exit immediately,
325 with the specified numeric exit status.
328 value is not specified, then
330 will exit with status zero.
331 Note that any preceding primaries will be evaluated and acted upon
335 This primary always evaluates to false.
336 This can be used following a primary that caused the
337 expression to be true to make the expression to be false.
338 This can be useful after using a
340 primary so it can continue to the next expression (using an
342 operator, for example).
344 .It Ic -flags Oo Fl Oc Ns Ar flags
347 are preceded by a dash
349 this primary evaluates to true
350 if at least all of the bits in
352 are set in the file's flags bits.
355 are not preceded by a dash, this primary evaluates to true if
358 exactly match the file's flags bits.
363 files with no flags bits set are matched.
366 for more information about file flags.)
369 Follow symbolic links.
371 .It Ic -fprint Ar filename
372 This primary always evaluates to true.
375 or overwrites the file if it already exists.
376 The file is created at startup.
377 It writes the pathname of the current file to this file, followed
378 by a newline character.
379 The file will be empty if no files are matched.
381 .It Ic -fstype Ar type
382 True if the file is contained in a file system of type
386 command can be used to find out the types of file systems
387 that are available on the system:
388 .Bd -literal -offset indent
389 sysctl vfs.generic.fstypes
392 In addition, there are two pseudo-types,
396 The former matches any file system physically mounted on the system where
399 is being executed, and the latter matches any file system which is
402 .It Ic -group Ar gname
403 True if the file belongs to the group
407 is numeric and there is no such group name, then
409 is treated as a group id.
411 .It Ic -iname Ar pattern
412 True if the last component of the pathname being examined matches
414 in a case-insensitive manner.
415 Special shell pattern matching characters
423 may be used as part of
425 These characters may be matched explicitly by escaping them with a
430 True if the file has inode number
433 .It Ic -iregex Ar regexp
434 True if the path name of the current file matches the case-insensitive
435 basic regular expression
436 .Pq see Xr re_format 7
438 This is a match on the whole path, not a search for the regular expression
447 This primary is an alias for
451 This primary always evaluates to true.
452 The following information for the current file is written to standard output:
453 its inode number, size in 512-byte blocks, file permissions, number of hard
454 links, owner, group, size in bytes, last modification time, and pathname.
455 If the file is a block or character special file, the major and minor numbers
456 will be displayed instead of the size in bytes.
457 If the file is a symbolic link, the pathname of the linked-to file will be
458 displayed preceded by
460 The format is identical to that produced by
463 .It Ic -maxdepth Ar n
464 True if the current search depth is less than or equal to what is specified in
467 .It Ic -mindepth Ar n
468 True if the current search depth is at least what is specified in
472 True if the difference between the file last modification time and the time
474 was started, rounded up to the next full minute, is
479 True if the difference between the file last modification time and the time
481 was started, rounded up to the next full 24-hour period, is
485 .It Ic -ok Ar utility Oo argument ... Oc Ic \&;
488 primary is similar to the semicolon-terminated
492 primary, with the exception that
494 requests user affirmation for the execution of
497 a message to the terminal and reading a response.
498 If the response is other than
500 the command is not executed and the
502 primary evaluates to false.
504 .Pq Do \&+ Dc termination
507 .It Ic -name Ar pattern
508 True if the last component of the pathname being examined matches
510 Special shell pattern matching characters
518 may be used as part of
520 These characters may be matched explicitly by escaping them with a
524 .It Ic -newer Ar file
525 True if the current file has a more recent last modification time than
529 True if the file belongs to an unknown user.
532 True if the file belongs to an unknown group.
534 .It Ic -path Ar pattern
535 True if the pathname being examined matches
537 Special shell pattern matching characters
545 may be used as part of
547 These characters may be matched explicitly by escaping them with a
552 are treated as normal characters and do not have to be
555 .It Ic -perm Oo Fl Oc Ns Ar mode
558 may be either symbolic (see
561 If the mode is symbolic, a starting value of zero is assumed and the
562 mode sets or clears permissions without regard to the process' file mode
564 If the mode is octal, only bits 07777
576 of the file's mode bits participate
578 If the mode is preceded by a dash
580 this primary evaluates to true
581 if at least all of the bits in the mode are set in the file's mode bits.
582 If the mode is not preceded by a dash, this primary evaluates to true if
583 the bits in the mode exactly match the file's mode bits.
584 Note, the first character of a symbolic mode may not be a dash
588 This primary always evaluates to true.
589 It prints the pathname of the current file to standard output, followed
590 by a newline character.
603 is specified, the given expression shall be effectively replaced by
604 .Cm \&( Ns Ar given\& expression Ns Cm \&)
608 This primary always evaluates to true.
609 It prints the pathname of the current file to standard output, followed
613 This primary always evaluates to true.
614 It prints the pathname of the current file to standard output,
615 with each space, tab, newline, backslash, dollar sign, and single,
616 double, or back quotation mark prefixed by a backslash, so the output of
618 can safely be used as input to
622 This primary always evaluates to true.
625 to not descend into the current file.
628 primary has no effect if the
630 option was specified.
632 .It Ic -regex Ar regexp
633 True if the path name of the current file matches the case-sensitive
634 basic regular expression
635 .Pq see Xr re_format 7
637 This is a match on the whole path, not a search for the regular expression
640 .It Ic -size Ar n Ns Op Cm c
641 True if the file's size, rounded up, in 512-byte blocks is
647 then the primary is true if the file's size is
652 True if the file is of the specified type.
653 Possible file types are as follows:
655 .Bl -tag -width flag -offset indent -compact
676 .It Ic -user Ar uname
677 True if the file belongs to the user
681 is numeric and there is no such user name, then
683 is treated as a user id (and considered a numeric argument).
686 This primary always evaluates to true.
687 It causes find not to descend past directories that have a different
695 The primaries may be combined using the following operators.
696 The operators are listed in order of decreasing precedence.
697 .Bl -tag -width (expression)
698 .It Cm \&( Ar expression Cm \&)
699 This evaluates to true if the parenthesized expression evaluates to
701 .It Cm \&! Ar expression
705 It evaluates to true if the expression is false.
706 .It Ar expression Cm -and Ar expression
707 .It Ar expression expression
710 operator is the logical
713 As it is implied by the juxtaposition of two expressions it does not
714 have to be specified.
715 The expression evaluates to true if both expressions are true.
716 The second expression is not evaluated if the first expression is false.
717 .It Ar expression Cm -or Ar expression
720 operator is the logical
723 The expression evaluates to true if either the first or the second expression
725 The second expression is not evaluated if the first expression is true.
728 All operands and primaries must be separate arguments to
730 Primaries which themselves take arguments expect each argument
731 to be a separate argument to
736 utility normally exits 0 on success, and exits with 1 under certain
737 internal error conditions.
738 If any invocations of
739 .Dq Ic -exec Ar ... Ic \&+
740 primaries return non-zero exit-status, then
744 The following examples are shown as given to the shell:
745 .Bl -tag -width findx
746 .It Li "find / \e! -name \*q*.c\*q \-print"
747 Print out a list of all the files whose names do not end in
749 .It Li "find / \-newer ttt \-user wnj \-print"
750 Print out a list of all the files owned by user
752 that are newer than the file
754 .It Li "find . \-type f \-mmin \-30 \-print \-or \-mindepth 1 \-prune"
755 Print out a list of all the files in the current directory that are
756 newer than 30 minutes.
757 .It Li "find . \-type f \-atime +10 \-mindepth 2 \-print"
758 Print out a list of all the files in any sub-directories that have not
759 been accessed in the past ten days.
760 .It Li "find . \-mtime +90 \-exec rm \-i {} + \-or \-mindepth 1 \-prune"
761 Interactively remove all of the files in the current directory that have
762 not been modified in 90 days.
763 .It Li "find . \-type f \-mtime +90 \-ok mv {} {}.old \e;"
764 Interactively rename all of the files in the current directory and all
765 sub-directories that have not been modified in 90 days.
766 .It Li "find / \e! \e( \-newer ttt \-user wnj \e) \-print"
767 Print out a list of all the files which are not both newer than
771 .It Li "find / \e( \-newer ttt \-or \-user wnj \e) \-print"
772 Print out a list of all the files that are either owned by
774 or that are newer than
776 .It Li "find / \e( \-newer ttt \-or \-user wnj \e) \-exit 1"
777 Return immediately with a value of 1 if any files are found that are either
780 or that are newer than
782 but do not print them.
783 .It Li "find / \e( \-newer ttt \-or \-user wnj \e) \-ls \-exit 1"
784 Same as above, but list the first file matching the criteria before exiting
786 .It Li "find . \-type f \-exec sh \-c 'file=\*[q]$1\*[q]; ...;' - {} \;"
787 Perform an arbitrarily complex shell command for every file.
805 utility syntax is a superset of the syntax specified by the
833 primaries are extensions to
841 options were implemented using the primaries
846 These primaries always evaluated to true, and always
849 was parsed, before the file system traversal began.
850 As a result, some legal expressions could be confusing.
851 For example, in the expression
852 .Dq Ic -print Ic -or Ic -depth ,
854 always evaluates to true, so the standard meaning of
858 would never be evaluated, but that is not what happens;
861 takes effect immediately, without testing whether
863 returns true or false.
865 Historically, the operator
874 Historic implementations of the
878 primaries did not replace the string
880 in the utility name or the
881 utility arguments if it did not appear as a separate argument.
882 This version replaces it no matter where in the utility name or arguments
886 .Dq Ic -exec Ar ... Ic \&+
888 .Em IEEE PASC Interpretation 1003.2 #210 ,
889 though the feature originated in
894 primary does not interact well with other options that cause the file system
895 tree traversal options to be changed.
899 command appeared in First Edition AT\*[Am]T Unix.
900 The syntax had become similar to the present version by
901 the time of the Fifth Edition.
903 The special characters used by
905 are also special characters to many shell programs.
906 In particular, the characters
917 may have to be escaped from the shell.
919 As there is no delimiter separating options and file names or file
922 it is difficult to specify files named
926 These problems are handled by the