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. Neither the name of the University nor the names of its contributors
16 .\" may be used to endorse or promote products derived from this software
17 .\" without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" @(#)find.1 8.7 (Berkeley) 5/9/95
38 .Nd walk a file hierarchy
41 .Op Fl H | Fl L | Fl P
47 .Op Fl H | Fl L | Fl P
55 utility recursively descends the directory tree for each
63 listed below) in terms
64 of each file in the tree.
66 The options are as follows:
67 .Bl -tag -width indent
69 Interpret regular expressions following the
73 primaries as extended (modern) regular expressions rather than basic
74 regular expressions (BRE's).
77 manual page fully describes both formats.
79 Cause the file information and file type (see
81 returned for each symbolic link specified on the command line to be
82 those of the file referenced by the 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.
85 File information of all symbolic links not on
86 the command line is that of the link itself.
88 Cause the file information and file type (see
90 returned for each symbolic link to be those of the file referenced by the
91 link, not the link itself.
92 If the referenced file does not exist, the file information and type will
93 be for the link itself.
95 This option is equivalent to the deprecated
99 Cause the file information and file type (see
101 returned for each symbolic link to be those of the link itself.
106 to be safely used in conjunction with
108 If a file name contains any of the delimiting characters used by
110 a diagnostic message is displayed on standard error, and the file
112 The delimiting characters include single
118 space, tab and newline characters.
120 However, you may wish to consider the
122 primary in conjunction with
124 as an effective alternative.
128 to perform a depth-first traversal.
130 This option is a BSD-specific equivalent of the
134 Refer to its description under
136 for more information.
140 to the list of paths that will be recursed into.
143 begins with a character that would otherwise be interpreted as an
153 to traverse the file hierarchies in lexicographical order,
154 i.e., alphabetical order within each directory.
159 may give different results.
165 with all its contents before a directory
169 puts the directory name
171 before any string like
178 In locales other than
180 results may vary more due to collation differences.
184 from descending into directories that have a device number different
185 than that of the file from which the descent began.
187 This option is equivalent to the deprecated
192 All primaries which take a numeric argument allow the number to be
193 preceded by a plus sign
197 A preceding plus sign means
199 a preceding minus sign means
203 .Bl -tag -width indent
205 True if the difference between the time of a file's inode creation
208 was started, rounded up to the next full minute, is
211 .It Ic -Bnewer Ar file
214 .It Ic -Btime Ar n Ns Op Cm smhdw
215 If no units are specified, this primary evaluates to
216 true if the difference between the time of a file's inode creation
219 was started, rounded up to the next full 24-hour period, is
223 If units are specified, this primary evaluates to
224 true if the difference between the time of a file's inode creation
227 was started is exactly
232 primary description for information on supported time units.
234 May be used in conjunction with other primaries to locate
235 files with extended ACLs.
238 for more information.
239 .It Ic -amin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
240 True if the difference between the file last access time and the time
242 was started, rounded up to the next full minute, is
252 .It Ic -anewer Ar file
255 .It Ic -atime Ar n Ns Op Cm smhdw
256 If no units are specified, this primary evaluates to
257 true if the difference between the file last access time and the time
259 was started, rounded up to the next full 24-hour period, is
263 If units are specified, this primary evaluates to
264 true if the difference between the file last access time and the time
266 was started is exactly
269 Possible time units are as follows:
271 .Bl -tag -width indent -compact
284 Any number of units may be combined in one
286 argument, for example,
287 .Dq Li "-atime -1h30m" .
288 Units are probably only useful when used in conjunction with the
293 .It Ic -cmin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
294 True if the difference between the time of last change of file status
295 information and the time
297 was started, rounded up to the next full minute, is
307 .It Ic -cnewer Ar file
310 .It Ic -ctime Ar n Ns Op Cm smhdw
311 If no units are specified, this primary evaluates to
312 true if the difference between the time of last change of file status
313 information and the time
315 was started, rounded up to the next full 24-hour period, is
319 If units are specified, this primary evaluates to
320 true if the difference between the time of last change of file status
321 information and the time
323 was started is exactly
328 primary description for information on supported time units.
330 Non-portable, BSD-specific version of
332 GNU find implements this as a primary in mistaken emulation of
336 Delete found files and/or directories.
339 from the current working directory as
341 recurses down the tree.
342 It will not attempt to delete a filename with a
344 character in its pathname relative to
346 for security reasons.
347 Depth-first traversal processing is implied by this option.
350 primary will fail to delete a directory if it is not empty.
351 Following symlinks is incompatible with this option.
354 same as the non-portable
359 to perform a depth-first traversal, i.e., directories
360 are visited in post-order and all entries in a directory will be acted
361 on before the directory itself.
364 visits directories in pre-order, i.e., before their contents.
367 a breadth-first traversal.
376 to process files that are contained in directories with unusual permissions.
377 It ensures that you have write permission while you are placing files in a
378 directory, then sets the directory's permissions as the last thing.
380 True if the depth of the file relative to the starting point of the traversal
384 True if the current file or directory is empty.
385 .It Ic -exec Ar utility Oo Ar argument ... Oc Li \&;
386 True if the program named
388 returns a zero value as its exit status.
391 may be passed to the utility.
392 The expression must be terminated by a semicolon
396 from a shell you may need to quote the semicolon if the shell would
397 otherwise treat it as a control operator.
400 appears anywhere in the utility name or the
401 arguments it is replaced by the pathname of the current file.
403 will be executed from the directory from which
409 are not subject to the further expansion of shell patterns
411 .It Ic -exec Ar utility Oo Ar argument ... Oc Li {} +
416 is replaced with as many pathnames as possible for each invocation of
418 This behaviour is similar to that of
420 The primary always returns true;
421 if at least one invocation of
423 returns a non-zero exit status,
425 will return a non-zero exit status.
426 .It Ic -execdir Ar utility Oo Ar argument ... Oc Li \&;
429 primary is identical to the
431 primary with the exception that
433 will be executed from the directory that holds
435 The filename substituted for
439 .It Ic -execdir Ar utility Oo Ar argument ... Oc Li {} +
444 is replaced with as many pathnames as possible for each invocation of
446 This behaviour is similar to that of
448 The primary always returns true;
449 if at least one invocation of
451 returns a non-zero exit status,
453 will return a non-zero exit status.
454 .It Ic -flags Oo Cm - Ns | Ns Cm + Oc Ns Ar flags , Ns Ar notflags
455 The flags are specified using symbolic names (see
465 are checked to be set, and flags in
467 are checked to be not set.
468 Note that this is different from
470 which only allows the user to specify mode bits that are set.
472 If flags are preceded by a dash
474 this primary evaluates to true
475 if at least all of the bits in
477 and none of the bits in
479 are set in the file's flags bits.
480 If flags are preceded by a plus
482 this primary evaluates to true
483 if any of the bits in
485 is set in the file's flags bits,
486 or any of the bits in
488 is not set in the file's flags bits.
490 this primary evaluates to true
493 exactly match the file's flags bits,
498 .It Ic -fstype Ar type
499 True if the file is contained in a file system of type
503 command can be used to find out the types of file systems
504 that are available on the system.
505 In addition, there are two pseudo-types,
509 The former matches any file system physically mounted on the system where
512 is being executed and the latter matches any file system which is
517 for compatibility with GNU find.
518 GNU find imposes a restriction that
523 .It Ic -group Ar gname
524 True if the file belongs to the group
528 is numeric and there is no such group name, then
530 is treated as a group ID.
531 .It Ic -ignore_readdir_race
532 Ignore errors because a file or a directory is deleted
533 after reading the name from a directory.
534 This option does not affect errors occurring on starting points.
535 .It Ic -ilname Ar pattern
538 but the match is case insensitive.
539 This is a GNU find extension.
540 .It Ic -iname Ar pattern
543 but the match is case insensitive.
545 True if the file has inode number
547 .It Ic -ipath Ar pattern
550 but the match is case insensitive.
551 .It Ic -iregex Ar pattern
554 but the match is case insensitive.
555 .It Ic -iwholename Ar pattern
558 for GNU find compatibility.
563 .It Ic -lname Ar pattern
566 but the contents of the symbolic link are matched instead of the file
568 Note that this only matches broken symbolic links
569 if symbolic links are being followed.
570 This is a GNU find extension.
572 This primary always evaluates to true.
573 The following information for the current file is written to standard output:
574 its inode number, size in 512-byte blocks, file permissions, number of hard
575 links, owner, group, size in bytes, last modification time, and pathname.
576 If the file is a block or character special file, the device number
577 will be displayed instead of the size in bytes.
578 If the file is a symbolic link, the pathname of the linked-to file will be
579 displayed preceded by
581 The format is identical to that produced by
585 .It Ic -maxdepth Ar n
586 Always true; descend at most
588 directory levels below the command line arguments.
591 primary is specified, it applies to the entire expression even if it would
592 not normally be evaluated.
593 .Dq Ic -maxdepth Li 0
594 limits the whole search to the command line arguments.
595 .It Ic -mindepth Ar n
596 Always true; do not apply any tests or actions at levels less than
600 primary is specified, it applies to the entire expression even if it would
601 not normally be evaluated.
602 .Dq Ic -mindepth Li 1
603 processes all but the command line arguments.
604 .It Ic -mmin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
605 True if the difference between the file last modification time and the time
607 was started, rounded up to the next full minute, is
617 .It Ic -mnewer Ar file
623 for GNU find compatibility.
624 .It Ic -mtime Ar n Ns Op Cm smhdw
625 If no units are specified, this primary evaluates to
626 true if the difference between the file last modification time and the time
628 was started, rounded up to the next full 24-hour period, is
632 If units are specified, this primary evaluates to
633 true if the difference between the file last modification time and the time
635 was started is exactly
640 primary description for information on supported time units.
641 .It Ic -name Ar pattern
642 True if the last component of the pathname being examined matches
644 Special shell pattern matching characters
650 may be used as part of
652 These characters may be matched explicitly by escaping them with a
655 .It Ic -newer Ar file
656 True if the current file has a more recent last modification time than
658 .It Ic -newer Ns Ar X Ns Ar Y Ar file
659 True if the current file has a more recent last access time
660 .Pq Ar X Ns = Ns Cm a ,
662 .Pq Ar X Ns = Ns Cm B ,
664 .Pq Ar X Ns = Ns Cm c ,
666 .Pq Ar X Ns = Ns Cm m
667 than the last access time
668 .Pq Ar Y Ns = Ns Cm a ,
670 .Pq Ar Y Ns = Ns Cm B ,
672 .Pq Ar Y Ns = Ns Cm c ,
674 .Pq Ar Y Ns = Ns Cm m
681 is instead interpreted as a direct date specification of the form
682 understood by ISO8601 or RFC822.
688 True if the file belongs to an unknown group.
689 .It Ic -noignore_readdir_race
690 Turn off the effect of
691 .Ic -ignore_readdir_race .
692 This is default behaviour.
694 This option is for GNU find compatibility.
695 In GNU find it disables an optimization not relevant to
699 True if the file belongs to an unknown user.
700 .It Ic -ok Ar utility Oo Ar argument ... Oc Li \&;
703 primary is identical to the
705 primary with the exception that
707 requests user affirmation for the execution of the
710 a message to the terminal and reading a response.
711 If the response is not affirmative
716 the command is not executed and the
720 .It Ic -okdir Ar utility Oo Ar argument ... Oc Li \&;
723 primary is identical to the
725 primary with the same exception as described for the
728 .It Ic -path Ar pattern
729 True if the pathname being examined matches
731 Special shell pattern matching characters
737 may be used as part of
739 These characters may be matched explicitly by escaping them with a
744 are treated as normal characters and do not have to be
746 .It Ic -perm Oo Cm - Ns | Ns Cm + Oc Ns Ar mode
749 may be either symbolic (see
754 is symbolic, a starting value of zero is assumed and the
756 sets or clears permissions without regard to the process' file mode
760 is octal, only bits 07777
761 .Pq Dv S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO
762 of the file's mode bits participate
766 is preceded by a dash
768 this primary evaluates to true
769 if at least all of the bits in the
771 are set in the file's mode bits.
774 is preceded by a plus
776 this primary evaluates to true
777 if any of the bits in the
779 are set in the file's mode bits.
780 Otherwise, this primary evaluates to true if
783 exactly match the file's mode bits.
784 Note, the first character of a symbolic mode may not be a dash
787 This primary always evaluates to true.
788 It prints the pathname of the current file to standard output.
790 .Ic -exec , -ls , -print0 ,
793 is specified, the given expression shall be effectively replaced by
794 .Cm \&( Ar "given expression" Cm \&) Ic -print .
796 This primary always evaluates to true.
797 It prints the pathname of the current file to standard output, followed by an
800 character (character code 0).
802 This primary always evaluates to true.
805 to not descend into the current file.
808 primary has no effect if the
810 option was specified.
814 to terminate immediately.
815 .It Ic -regex Ar pattern
816 True if the whole path of the file matches
818 using regular expression.
819 To match a file named
821 you can use the regular expression
829 .It Ic -samefile Ar name
830 True if the file is a hard link to
832 If the command option
834 is specified, it is also true if the file is a symbolic link and
837 .It Ic -size Ar n Ns Op Cm ckMGTP
838 True if the file's size, rounded up, in 512-byte blocks is
844 then the primary is true if the
850 is followed by a scale indicator then the file's size is compared to
854 .Bl -tag -width indent -compact
856 kilobytes (1024 bytes)
858 megabytes (1024 kilobytes)
860 gigabytes (1024 megabytes)
862 terabytes (1024 gigabytes)
864 petabytes (1024 terabytes)
867 True if the current file is sparse,
868 i.e. has fewer blocks allocated than expected based on its size in bytes.
869 This might also match files that have been compressed by the filesystem.
871 True if the file is of the specified type.
872 Possible file types are as follows:
874 .Bl -tag -width indent -compact
893 for compatibility with GNU find.
894 GNU find imposes a restriction that
899 .It Ic -user Ar uname
900 True if the file belongs to the user
904 is numeric and there is no such user name, then
906 is treated as a user ID.
907 .It Ic -wholename Ar pattern
910 for GNU find compatibility.
913 The primaries may be combined using the following operators.
914 The operators are listed in order of decreasing precedence.
916 .Bl -tag -width indent -compact
917 .It Cm \&( Ar expression Cm \&)
918 This evaluates to true if the parenthesized expression evaluates to
921 .It Cm \&! Ar expression
922 .It Cm -not Ar expression
926 It evaluates to true if the expression is false.
933 .It Ar expression Cm -and Ar expression
934 .It Ar expression expression
937 operator is the logical
940 As it is implied by the juxtaposition of two expressions it does not
941 have to be specified.
942 The expression evaluates to true if both expressions are true.
943 The second expression is not evaluated if the first expression is false.
945 .It Ar expression Cm -or Ar expression
948 operator is the logical
951 The expression evaluates to true if either the first or the second expression
953 The second expression is not evaluated if the first expression is true.
956 All operands and primaries must be separate arguments to
958 Primaries which themselves take arguments expect each argument
959 to be a separate argument to
963 .Ev LANG , LC_ALL , LC_COLLATE , LC_CTYPE , LC_MESSAGES
966 environment variables affect the execution of the
968 utility as described in
971 The following examples are shown as given to the shell:
972 .Bl -tag -width indent
973 .It Li "find / \e! -name \*q*.c\*q -print"
974 Print out a list of all the files whose names do not end in
976 .It Li "find / -newer ttt -user wnj -print"
977 Print out a list of all the files owned by user
982 .It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
983 Print out a list of all the files which are not both newer than
987 .It Li "find / \e( -newer ttt -or -user wnj \e) -print"
988 Print out a list of all the files that are either owned by
990 or that are newer than
992 .It Li "find / -newerct '1 minute ago' -print"
993 Print out a list of all the files whose inode change time is more
994 recent than the current time minus one minute.
995 .It Li "find / -type f -exec echo {} \e;"
998 command to print out a list of all the files.
999 .It Li "find -L /usr/ports/packages -type l -exec rm -- {} +"
1000 Delete all broken symbolic links in
1001 .Pa /usr/ports/packages .
1002 .It Li "find /usr/src -name CVS -prune -o -depth +6 -print"
1003 Find files and directories that are at least seven levels deep
1004 in the working directory
1006 .It Li "find /usr/src -name CVS -prune -o -mindepth 7 -print"
1007 Is not equivalent to the previous example, since
1009 is not evaluated below level seven.
1014 primary is deprecated; the
1016 option should be used instead.
1019 section below for details.
1040 utility syntax is a superset of the syntax specified by the
1044 All the single character options except
1049 .Ic -amin , -anewer , -cmin , -cnewer , -delete , -empty , -fstype ,
1050 .Ic -iname , -inum , -iregex , -ls , -maxdepth , -mindepth , -mmin ,
1051 .Ic -not , -path , -print0 , -regex , -sparse
1054 birthtime related primaries are extensions to
1061 options were implemented using the primaries
1062 .Ic -depth , -follow ,
1065 These primaries always evaluated to true.
1066 As they were really global variables that took effect before the traversal
1067 began, some legal expressions could have unexpected results.
1068 An example is the expression
1069 .Ic -print Cm -o Ic -depth .
1072 always evaluates to true, the standard order of evaluation
1075 would never be evaluated.
1076 This is not the case.
1087 Historic implementations of the
1091 primaries did not replace the string
1093 in the utility name or the
1094 utility arguments if it had preceding or following non-whitespace characters.
1095 This version replaces it no matter where in the utility name or arguments
1100 option was inspired by the equivalent
1112 It was rewritten for
1114 and later be enhanced for the Programmer's Workbench (PWB).
1115 These changes were later incorporated in
1118 The special characters used by
1120 are also special characters to many shell programs.
1121 In particular, the characters
1132 may have to be escaped from the shell.
1134 As there is no delimiter separating options and file names or file
1137 it is difficult to specify files named
1141 These problems are handled by the
1150 primary does not interact well with other options that cause the file system
1151 tree traversal options to be changed.
1157 primaries are actually global options (as documented above).
1159 probably be replaced by options which look like options.