1 .\" Copyright (c) 1990, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the Institute of Electrical and Electronics Engineers, Inc.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed by the University of
18 .\" California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\" may be used to endorse or promote products derived from this software
21 .\" without specific prior written permission.
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .\" @(#)find.1 8.7 (Berkeley) 5/9/95
43 .Nd walk a file hierarchy
46 .Op Fl H | Fl L | Fl P
52 .Op Fl H | Fl L | Fl P
60 utility recursively descends the directory tree for each
68 listed below) in terms
69 of each file in the tree.
71 The options are as follows:
72 .Bl -tag -width indent
74 Interpret regular expressions followed by
78 primaries as extended (modern) regular expressions rather than basic
79 regular expressions (BRE's).
82 manual page fully describes both formats.
84 Cause the file information and file type (see
86 returned for each symbolic link specified on the command line to be
87 those of the file referenced by the 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.
90 File information of all symbolic links not on
91 the command line is that of the link itself.
93 Cause the file information and file type (see
95 returned for each symbolic link to be those of the file referenced by the
96 link, not the link itself.
97 If the referenced file does not exist, the file information and type will
98 be for the link itself.
100 This option is equivalent to the deprecated
104 Cause the file information and file type (see
106 returned for each symbolic link to be those of the link itself.
111 to be safely used in conjunction with
113 If a file name contains any of the delimiting characters used by
115 a diagnostic message is displayed on standard error, and the file
117 The delimiting characters include single
123 space, tab and newline characters.
125 However, you may wish to consider the
127 primary in conjunction with
129 as an effective alternative.
133 to perform a depth-first traversal, i.e., directories
134 are visited in post-order and all entries in a directory will be acted
135 on before the directory itself.
138 visits directories in pre-order, i.e., before their contents.
141 a breadth-first traversal.
143 This option is equivalent to the
154 to process files that are contained in directories with unusual permissions.
155 It ensures that you have write permission while you are placing files in a
156 directory, then sets the directory's permissions as the last thing.
158 Specify a file hierarchy for
161 File hierarchies may also be specified as the operands immediately
162 following the options.
166 to traverse the file hierarchies in lexicographical order,
167 i.e., alphabetical order within each directory.
172 may give different results.
176 from descending into directories that have a device number different
177 than that of the file from which the descent began.
179 This option is equivalent to the deprecated
184 .Bl -tag -width indent
186 True if the difference between the time of a file's inode creation
189 was started, rounded up to the next full minute, is
192 .It Ic -Bnewer Ar file
195 .It Ic -Btime Ar n Ns Op Cm smhdw
196 If no units are specified, this primary evaluates to
197 true if the difference between the time of a file's inode creation
200 was started, rounded up to the next full 24-hour period, is
204 If units are specified, this primary evaluates to
205 true if the difference between the time of a file's inode creation
208 was started is exactly
213 primary description for information on supported time units.
215 May be used in conjunction with other primaries to locate
216 files with extended ACLs.
219 for more information.
221 True if the difference between the file last access time and the time
223 was started, rounded up to the next full minute, is
226 .It Ic -anewer Ar file
229 .It Ic -atime Ar n Ns Op Cm smhdw
230 If no units are specified, this primary evaluates to
231 true if the difference between the file last access time and the time
233 was started, rounded up to the next full 24-hour period, is
237 If units are specified, this primary evaluates to
238 true if the difference between the file last access time and the time
240 was started is exactly
243 Possible time units are as follows:
245 .Bl -tag -width indent -compact
258 Any number of units may be combined in one
260 argument, for example,
261 .Dq Li "-atime -1h30m" .
262 Units are probably only useful when used in conjunction with the
268 True if the difference between the time of last change of file status
269 information and the time
271 was started, rounded up to the next full minute, is
274 .It Ic -cnewer Ar file
277 .It Ic -ctime Ar n Ns Op Cm smhdw
278 If no units are specified, this primary evaluates to
279 true if the difference between the time of last change of file status
280 information and the time
282 was started, rounded up to the next full 24-hour period, is
286 If units are specified, this primary evaluates to
287 true if the difference between the time of last change of file status
288 information and the time
290 was started is exactly
295 primary description for information on supported time units.
297 Delete found files and/or directories.
300 from the current working directory as
302 recurses down the tree.
303 It will not attempt to delete a filename with a
305 character in its pathname relative to
307 for security reasons.
308 Depth-first traversal processing is implied by this option.
315 True if the depth of the file relative to the starting point of the traversal
319 True if the current file or directory is empty.
320 .It Ic -exec Ar utility Oo Ar argument ... Oc Li \&;
321 True if the program named
323 returns a zero value as its exit status.
326 may be passed to the utility.
327 The expression must be terminated by a semicolon
331 from a shell you may need to quote the semicolon if the shell would
332 otherwise treat it as a control operator.
335 appears anywhere in the utility name or the
336 arguments it is replaced by the pathname of the current file.
338 will be executed from the directory from which
344 are not subject to the further expansion of shell patterns
346 .It Ic -exec Ar utility Oo Ar argument ... Oc Li {} +
351 is replaced with as many pathnames as possible for each invocation of
353 This behaviour is similar to that of
355 .It Ic -execdir Ar utility Oo Ar argument ... Oc Li \&;
358 primary is identical to the
360 primary with the exception that
362 will be executed from the directory that holds
364 The filename substituted for
368 .It Ic -flags Oo Cm - Ns | Ns Cm + Oc Ns Ar flags , Ns Ar notflags
369 The flags are specified using symbolic names (see
379 are checked to be set, and flags in
381 are checked to be not set.
382 Note that this is different from
384 which only allows the user to specify mode bits that are set.
386 If flags are preceded by a dash
388 this primary evaluates to true
389 if at least all of the bits in
391 and none of the bits in
393 are set in the file's flags bits.
394 If flags are preceded by a plus
396 this primary evaluates to true
397 if any of the bits in
399 is set in the file's flags bits,
400 or any of the bits in
402 is not set in the file's flags bits.
404 this primary evaluates to true
407 exactly match the file's flags bits,
412 .It Ic -fstype Ar type
413 True if the file is contained in a file system of type
417 command can be used to find out the types of file systems
418 that are available on the system:
422 In addition, there are two pseudo-types,
426 The former matches any file system physically mounted on the system where
429 is being executed and the latter matches any file system which is
431 .It Ic -group Ar gname
432 True if the file belongs to the group
436 is numeric and there is no such group name, then
438 is treated as a group ID.
439 .It Ic -iname Ar pattern
442 but the match is case insensitive.
444 True if the file has inode number
446 .It Ic -ipath Ar pattern
449 but the match is case insensitive.
450 .It Ic -iregex Ar pattern
453 but the match is case insensitive.
459 This primary always evaluates to true.
460 The following information for the current file is written to standard output:
461 its inode number, size in 512-byte blocks, file permissions, number of hard
462 links, owner, group, size in bytes, last modification time, and pathname.
463 If the file is a block or character special file, the major and minor numbers
464 will be displayed instead of the size in bytes.
465 If the file is a symbolic link, the pathname of the linked-to file will be
466 displayed preceded by
468 The format is identical to that produced by
472 .It Ic -maxdepth Ar n
473 Always true; descend at most
475 directory levels below the command line arguments.
478 primary is specified, it applies to the entire expression even if it would
479 not normally be evaluated.
480 .Dq Ic -maxdepth Li 0
481 limits the whole search to the command line arguments.
482 .It Ic -mindepth Ar n
483 Always true; do not apply any tests or actions at levels less than
487 primary is specified, it applies to the entire expression even if it would
488 not normally be evaluated.
489 .Dq Ic -mindepth Li 1
490 processes all but the command line arguments.
492 True if the difference between the file last modification time and the time
494 was started, rounded up to the next full minute, is
497 .It Ic -mnewer Ar file
500 .It Ic -mtime Ar n Ns Op Cm smhdw
501 If no units are specified, this primary evaluates to
502 true if the difference between the file last modification time and the time
504 was started, rounded up to the next full 24-hour period, is
508 If units are specified, this primary evaluates to
509 true if the difference between the file last modification time and the time
511 was started is exactly
516 primary description for information on supported time units.
517 .It Ic -name Ar pattern
518 True if the last component of the pathname being examined matches
520 Special shell pattern matching characters
526 may be used as part of
528 These characters may be matched explicitly by escaping them with a
531 .It Ic -newer Ar file
532 True if the current file has a more recent last modification time than
534 .It Ic -newer Ns Ar X Ns Ar Y Ar file
535 True if the current file has a more recent last access time
536 .Pq Ar X Ns = Ns Cm a ,
538 .Pq Ar X Ns = Ns Cm B ,
540 .Pq Ar X Ns = Ns Cm c ,
542 .Pq Ar X Ns = Ns Cm m
543 than the last access time
544 .Pq Ar Y Ns = Ns Cm a ,
546 .Pq Ar Y Ns = Ns Cm B ,
548 .Pq Ar Y Ns = Ns Cm c ,
550 .Pq Ar Y Ns = Ns Cm m
557 is instead interpreted as a direct date specification of the form
565 True if the file belongs to an unknown group.
567 True if the file belongs to an unknown user.
568 .It Ic -ok Ar utility Oo Ar argument ... Oc Li \&;
571 primary is identical to the
573 primary with the exception that
575 requests user affirmation for the execution of the
578 a message to the terminal and reading a response.
579 If the response is not affirmative
584 the command is not executed and the
588 .It Ic -okdir Ar utility Oo Ar argument ... Oc Li \&;
591 primary is identical to the
593 primary with the same exception as described for the
596 .It Ic -path Ar pattern
597 True if the pathname being examined matches
599 Special shell pattern matching characters
605 may be used as part of
607 These characters may be matched explicitly by escaping them with a
612 are treated as normal characters and do not have to be
614 .It Ic -perm Oo Cm - Ns | Ns Cm + Oc Ns Ar mode
617 may be either symbolic (see
622 is symbolic, a starting value of zero is assumed and the
624 sets or clears permissions without regard to the process' file mode
628 is octal, only bits 07777
629 .Pq Dv S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO
630 of the file's mode bits participate
634 is preceded by a dash
636 this primary evaluates to true
637 if at least all of the bits in the
639 are set in the file's mode bits.
642 is preceded by a plus
644 this primary evaluates to true
645 if any of the bits in the
647 are set in the file's mode bits.
648 Otherwise, this primary evaluates to true if
651 exactly match the file's mode bits.
652 Note, the first character of a symbolic mode may not be a dash
655 This primary always evaluates to true.
656 It prints the pathname of the current file to standard output.
658 .Ic -exec , -ls , -print0 ,
661 is specified, the given expression shall be effectively replaced by
662 .Cm \&( Ar "given expression" Cm \&) Ic -print .
664 This primary always evaluates to true.
665 It prints the pathname of the current file to standard output, followed by an
668 character (character code 0).
670 This primary always evaluates to true.
673 to not descend into the current file.
676 primary has no effect if the
678 option was specified.
679 .It Ic -regex Ar pattern
680 True if the whole path of the file matches
682 using regular expression.
683 To match a file named
685 you can use the regular expression
693 .It Ic -size Ar n Ns Op Cm ckMGTP
694 True if the file's size, rounded up, in 512-byte blocks is
700 then the primary is true if the
706 is followed by a scale indicator then the file's size is compared to
710 .Bl -tag -width indent -compact
712 kilobytes (1024 bytes)
714 megabytes (1024 kilobytes)
716 gigabytes (1024 megabytes)
718 terabytes (1024 gigabytes)
720 petabytes (1024 terabytes)
723 True if the file is of the specified type.
724 Possible file types are as follows:
726 .Bl -tag -width indent -compact
742 .It Ic -user Ar uname
743 True if the file belongs to the user
747 is numeric and there is no such user name, then
749 is treated as a user ID.
752 All primaries which take a numeric argument allow the number to be
753 preceded by a plus sign
757 A preceding plus sign means
759 a preceding minus sign means
764 The primaries may be combined using the following operators.
765 The operators are listed in order of decreasing precedence.
767 .Bl -tag -width indent -compact
768 .It Cm \&( Ar expression Cm \&)
769 This evaluates to true if the parenthesized expression evaluates to
772 .It Cm \&! Ar expression
773 .It Cm -false Ar expression
774 .It Cm -not Ar expression
778 It evaluates to true if the expression is false.
780 .It Ar expression Cm -and Ar expression
781 .It Ar expression expression
784 operator is the logical
787 As it is implied by the juxtaposition of two expressions it does not
788 have to be specified.
789 The expression evaluates to true if both expressions are true.
790 The second expression is not evaluated if the first expression is false.
792 .It Ar expression Cm -or Ar expression
795 operator is the logical
798 The expression evaluates to true if either the first or the second expression
800 The second expression is not evaluated if the first expression is true.
803 All operands and primaries must be separate arguments to
805 Primaries which themselves take arguments expect each argument
806 to be a separate argument to
810 .Ev LANG , LC_ALL , LC_COLLATE , LC_CTYPE , LC_MESSAGES
813 environment variables affect the execution of the
815 utility as described in
818 The following examples are shown as given to the shell:
819 .Bl -tag -width indent
820 .It Li "find / \e! -name \*q*.c\*q -print"
821 Print out a list of all the files whose names do not end in
823 .It Li "find / -newer ttt -user wnj -print"
824 Print out a list of all the files owned by user
829 .It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
830 Print out a list of all the files which are not both newer than
834 .It Li "find / \e( -newer ttt -or -user wnj \e) -print"
835 Print out a list of all the files that are either owned by
837 or that are newer than
839 .It Li "find / -newerct '1 minute ago' -print"
840 Print out a list of all the files whose inode change time is more
841 recent than the current time minus one minute.
842 .It Li "find / -type f -exec echo {} \e;"
845 command to print out a list of all the files.
846 .It Li "find -L /usr/ports/packages -type l -delete"
847 Delete all broken symbolic links in
848 .Pa /usr/ports/packages .
849 .It Li "find /usr/src -name CVS -prune -o -depth +6 -print"
850 Find files and directories that are at least seven levels deep
851 in the working directory
853 .It Li "find /usr/src -name CVS -prune -o -mindepth 7 -print"
854 Is not equivalent to the previous example, since
856 is not evaluated below level seven.
861 primary is deprecated; the
863 option should be used instead.
866 section below for details.
886 utility syntax is a superset of the syntax specified by the
890 All the single character options except
895 .Ic -amin , -anewer , -cmin , -cnewer , -delete , -empty , -fstype ,
896 .Ic -iname , -inum , -iregex , -ls , -maxdepth , -mindepth , -mmin ,
897 .Ic -path , -print0 , -regex
900 birthtime related primaries are extensions to
907 options were implemented using the primaries
908 .Ic -depth , -follow ,
911 These primaries always evaluated to true.
912 As they were really global variables that took effect before the traversal
913 began, some legal expressions could have unexpected results.
914 An example is the expression
915 .Ic -print Cm -o Ic -depth .
918 always evaluates to true, the standard order of evaluation
921 would never be evaluated.
922 This is not the case.
933 Historic implementations of the
937 primaries did not replace the string
939 in the utility name or the
940 utility arguments if it had preceding or following non-whitespace characters.
941 This version replaces it no matter where in the utility name or arguments
946 option was inspired by the equivalent
957 The special characters used by
959 are also special characters to many shell programs.
960 In particular, the characters
971 may have to be escaped from the shell.
973 As there is no delimiter separating options and file names or file
976 it is difficult to specify files named
980 These problems are handled by the
989 primary does not interact well with other options that cause the file system
990 tree traversal options to be changed.
996 primaries are actually global options (as documented above).
998 probably be replaced by options which look like options.