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
36 .Nd walk a file hierarchy
39 .Op Fl H | Fl L | Fl P
45 .Op Fl H | Fl L | Fl P
53 utility recursively descends the directory tree for each
61 listed below) in terms
62 of each file in the tree.
64 The options are as follows:
65 .Bl -tag -width indent
67 Interpret regular expressions following the
71 primaries as extended (modern) regular expressions rather than basic
72 regular expressions (BRE's).
75 manual page fully describes both formats.
77 Cause the file information and file type (see
79 returned for each symbolic link specified on the command line to be
80 those of the file referenced by the link, not the link itself.
81 If the referenced file does not exist, the file information and type will
82 be for the link itself.
83 File information of all symbolic links not on
84 the command line is that of the link itself.
86 Cause the file information and file type (see
88 returned for each symbolic link to be those of the file referenced by the
89 link, not the link itself.
90 If the referenced file does not exist, the file information and type will
91 be for the link itself.
93 This option is equivalent to the deprecated
97 Cause the file information and file type (see
99 returned for each symbolic link to be those of the link itself.
104 to be safely used in conjunction with
106 If a file name contains any of the delimiting characters used by
108 a diagnostic message is displayed on standard error, and the file
110 The delimiting characters include single
116 space, tab and newline characters.
118 However, you may wish to consider the
120 primary in conjunction with
122 as an effective alternative.
126 to perform a depth-first traversal.
128 This option is a BSD-specific equivalent of the
132 Refer to its description under
134 for more information.
138 to the list of paths that will be recursed into.
141 begins with a character that would otherwise be interpreted as an
151 to traverse the file hierarchies in lexicographical order,
152 i.e., alphabetical order within each directory.
157 may give different results.
163 with all its contents before a directory
167 puts the directory name
169 before any string like
176 In locales other than
178 results may vary more due to collation differences.
182 from descending into directories that have a device number different
183 than that of the file from which the descent began.
185 This option is equivalent to the deprecated
190 All primaries which take a numeric argument allow the number to be
191 preceded by a plus sign
195 A preceding plus sign means
197 a preceding minus sign means
201 .Bl -tag -width indent
203 True if the difference between the time of a file's inode creation
206 was started, rounded up to the next full minute, is
209 .It Ic -Bnewer Ar file
212 .It Ic -Btime Ar n Ns Op Cm smhdw
213 If no units are specified, this primary evaluates to
214 true if the difference between the time of a file's inode creation
217 was started, rounded up to the next full 24-hour period, is
221 If units are specified, this primary evaluates to
222 true if the difference between the time of a file's inode creation
225 was started is exactly
230 primary description for information on supported time units.
232 May be used in conjunction with other primaries to locate
233 files with extended ACLs.
236 for more information.
237 .It Ic -amin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
238 True if the difference between the file last access time and the time
240 was started, rounded up to the next full minute, is
250 .It Ic -anewer Ar file
253 .It Ic -atime Ar n Ns Op Cm smhdw
254 If no units are specified, this primary evaluates to
255 true if the difference between the file last access time and the time
257 was started, rounded up to the next full 24-hour period, is
261 If units are specified, this primary evaluates to
262 true if the difference between the file last access time and the time
264 was started is exactly
267 Possible time units are as follows:
269 .Bl -tag -width indent -compact
282 Any number of units may be combined in one
284 argument, for example,
285 .Dq Li "-atime -1h30m" .
286 Units are probably only useful when used in conjunction with the
291 .It Ic -cmin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
292 True if the difference between the time of last change of file status
293 information and the time
295 was started, rounded up to the next full minute, is
305 .It Ic -cnewer Ar file
308 .It Ic -ctime Ar n Ns Op Cm smhdw
309 If no units are specified, this primary evaluates to
310 true if the difference between the time of last change of file status
311 information and the time
313 was started, rounded up to the next full 24-hour period, is
317 If units are specified, this primary evaluates to
318 true if the difference between the time of last change of file status
319 information and the time
321 was started is exactly
326 primary description for information on supported time units.
328 Non-portable, BSD-specific version of
330 GNU find implements this as a primary in mistaken emulation of
334 Delete found files and/or directories.
337 from the current working directory as
339 recurses down the tree.
340 It will not attempt to delete a filename with a
342 character in its pathname relative to
344 for security reasons.
345 Depth-first traversal processing is implied by this option.
348 primary will fail to delete a directory if it is not empty.
349 Following symlinks is incompatible with this option.
352 same as the non-portable
357 to perform a depth-first traversal, i.e., directories
358 are visited in post-order and all entries in a directory will be acted
359 on before the directory itself.
362 visits directories in pre-order, i.e., before their contents.
365 a breadth-first traversal.
374 to process files that are contained in directories with unusual permissions.
375 It ensures that you have write permission while you are placing files in a
376 directory, then sets the directory's permissions as the last thing.
378 True if the depth of the file relative to the starting point of the traversal
382 True if the current file or directory is empty.
383 .It Ic -exec Ar utility Oo Ar argument ... Oc Li \&;
384 True if the program named
386 returns a zero value as its exit status.
389 may be passed to the utility.
390 The expression must be terminated by a semicolon
394 from a shell you may need to quote the semicolon if the shell would
395 otherwise treat it as a control operator.
398 appears anywhere in the utility name or the
399 arguments it is replaced by the pathname of the current file.
401 will be executed from the directory from which
407 are not subject to the further expansion of shell patterns
409 .It Ic -exec Ar utility Oo Ar argument ... Oc Li {} +
414 is replaced with as many pathnames as possible for each invocation of
416 This behaviour is similar to that of
418 The primary always returns true;
419 if at least one invocation of
421 returns a non-zero exit status,
423 will return a non-zero exit status.
424 .It Ic -execdir Ar utility Oo Ar argument ... Oc Li \&;
427 primary is identical to the
429 primary with the exception that
431 will be executed from the directory that holds
433 The filename substituted for
437 .It Ic -execdir Ar utility Oo Ar argument ... Oc Li {} +
442 is replaced with as many pathnames as possible for each invocation of
444 This behaviour is similar to that of
446 The primary always returns true;
447 if at least one invocation of
449 returns a non-zero exit status,
451 will return a non-zero exit status.
452 .It Ic -flags Oo Cm - Ns | Ns Cm + Oc Ns Ar flags , Ns Ar notflags
453 The flags are specified using symbolic names (see
463 are checked to be set, and flags in
465 are checked to be not set.
466 Note that this is different from
468 which only allows the user to specify mode bits that are set.
470 If flags are preceded by a dash
472 this primary evaluates to true
473 if at least all of the bits in
475 and none of the bits in
477 are set in the file's flags bits.
478 If flags are preceded by a plus
480 this primary evaluates to true
481 if any of the bits in
483 is set in the file's flags bits,
484 or any of the bits in
486 is not set in the file's flags bits.
488 this primary evaluates to true
491 exactly match the file's flags bits,
496 .It Ic -fstype Ar type
497 True if the file is contained in a file system of type
501 command can be used to find out the types of file systems
502 that are available on the system.
503 In addition, there are two pseudo-types,
507 The former matches any file system physically mounted on the system where
510 is being executed and the latter matches any file system which is
515 for compatibility with GNU find.
516 GNU find imposes a restriction that
521 .It Ic -group Ar gname
522 True if the file belongs to the group
526 is numeric and there is no such group name, then
528 is treated as a group ID.
529 .It Ic -ignore_readdir_race
530 Ignore errors because a file or a directory is deleted
531 after reading the name from a directory.
532 This option does not affect errors occurring on starting points.
533 .It Ic -ilname Ar pattern
536 but the match is case insensitive.
537 This is a GNU find extension.
538 .It Ic -iname Ar pattern
541 but the match is case insensitive.
543 True if the file has inode number
545 .It Ic -ipath Ar pattern
548 but the match is case insensitive.
549 .It Ic -iregex Ar pattern
552 but the match is case insensitive.
553 .It Ic -iwholename Ar pattern
556 for GNU find compatibility.
561 .It Ic -lname Ar pattern
564 but the contents of the symbolic link are matched instead of the file
566 Note that this only matches broken symbolic links
567 if symbolic links are being followed.
568 This is a GNU find extension.
570 This primary always evaluates to true.
571 The following information for the current file is written to standard output:
572 its inode number, size in 512-byte blocks, file permissions, number of hard
573 links, owner, group, size in bytes, last modification time, and pathname.
574 If the file is a block or character special file, the device number
575 will be displayed instead of the size in bytes.
576 If the file is a symbolic link, the pathname of the linked-to file will be
577 displayed preceded by
579 The format is identical to that produced by
583 .It Ic -maxdepth Ar n
584 Always true; descend at most
586 directory levels below the command line arguments.
589 primary is specified, it applies to the entire expression even if it would
590 not normally be evaluated.
591 .Dq Ic -maxdepth Li 0
592 limits the whole search to the command line arguments.
593 .It Ic -mindepth Ar n
594 Always true; do not apply any tests or actions at levels less than
598 primary is specified, it applies to the entire expression even if it would
599 not normally be evaluated.
600 .Dq Ic -mindepth Li 1
601 processes all but the command line arguments.
602 .It Ic -mmin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
603 True if the difference between the file last modification time and the time
605 was started, rounded up to the next full minute, is
615 .It Ic -mnewer Ar file
621 for GNU find compatibility.
622 .It Ic -mtime Ar n Ns Op Cm smhdw
623 If no units are specified, this primary evaluates to
624 true if the difference between the file last modification time and the time
626 was started, rounded up to the next full 24-hour period, is
630 If units are specified, this primary evaluates to
631 true if the difference between the file last modification time and the time
633 was started is exactly
638 primary description for information on supported time units.
639 .It Ic -name Ar pattern
640 True if the last component of the pathname being examined matches
642 Special shell pattern matching characters
648 may be used as part of
650 These characters may be matched explicitly by escaping them with a
653 .It Ic -newer Ar file
654 True if the current file has a more recent last modification time than
656 .It Ic -newer Ns Ar X Ns Ar Y Ar file
657 True if the current file has a more recent last access time
658 .Pq Ar X Ns = Ns Cm a ,
660 .Pq Ar X Ns = Ns Cm B ,
662 .Pq Ar X Ns = Ns Cm c ,
664 .Pq Ar X Ns = Ns Cm m
665 than the last access time
666 .Pq Ar Y Ns = Ns Cm a ,
668 .Pq Ar Y Ns = Ns Cm B ,
670 .Pq Ar Y Ns = Ns Cm c ,
672 .Pq Ar Y Ns = Ns Cm m
679 is instead interpreted as a direct date specification of the form
680 understood by ISO8601 or RFC822.
686 True if the file belongs to an unknown group.
687 .It Ic -noignore_readdir_race
688 Turn off the effect of
689 .Ic -ignore_readdir_race .
690 This is default behaviour.
692 This option is for GNU find compatibility.
693 In GNU find it disables an optimization not relevant to
697 True if the file belongs to an unknown user.
698 .It Ic -ok Ar utility Oo Ar argument ... Oc Li \&;
701 primary is identical to the
703 primary with the exception that
705 requests user affirmation for the execution of the
708 a message to the terminal and reading a response.
709 If the response is not affirmative
714 the command is not executed and the
718 .It Ic -okdir Ar utility Oo Ar argument ... Oc Li \&;
721 primary is identical to the
723 primary with the same exception as described for the
726 .It Ic -path Ar pattern
727 True if the pathname being examined matches
729 Special shell pattern matching characters
735 may be used as part of
737 These characters may be matched explicitly by escaping them with a
742 are treated as normal characters and do not have to be
744 .It Ic -perm Oo Cm - Ns | Ns Cm + Oc Ns Ar mode
747 may be either symbolic (see
752 is symbolic, a starting value of zero is assumed and the
754 sets or clears permissions without regard to the process' file mode
758 is octal, only bits 07777
759 .Pq Dv S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO
760 of the file's mode bits participate
764 is preceded by a dash
766 this primary evaluates to true
767 if at least all of the bits in the
769 are set in the file's mode bits.
772 is preceded by a plus
774 this primary evaluates to true
775 if any of the bits in the
777 are set in the file's mode bits.
778 Otherwise, this primary evaluates to true if
781 exactly match the file's mode bits.
782 Note, the first character of a symbolic mode may not be a dash
785 This primary always evaluates to true.
786 It prints the pathname of the current file to standard output.
788 .Ic -exec , -ls , -print0 ,
791 is specified, the given expression shall be effectively replaced by
792 .Cm \&( Ar "given expression" Cm \&) Ic -print .
794 This primary always evaluates to true.
795 It prints the pathname of the current file to standard output, followed by an
798 character (character code 0).
800 This primary always evaluates to true.
803 to not descend into the current file.
806 primary has no effect if the
808 option was specified.
812 to terminate immediately.
813 .It Ic -regex Ar pattern
814 True if the whole path of the file matches
816 using regular expression.
817 To match a file named
819 you can use the regular expression
827 .It Ic -samefile Ar name
828 True if the file is a hard link to
830 If the command option
832 is specified, it is also true if the file is a symbolic link and
835 .It Ic -size Ar n Ns Op Cm ckMGTP
836 True if the file's size, rounded up, in 512-byte blocks is
842 then the primary is true if the
848 is followed by a scale indicator then the file's size is compared to
852 .Bl -tag -width indent -compact
854 kilobytes (1024 bytes)
856 megabytes (1024 kilobytes)
858 gigabytes (1024 megabytes)
860 terabytes (1024 gigabytes)
862 petabytes (1024 terabytes)
865 True if the current file is sparse,
866 i.e. has fewer blocks allocated than expected based on its size in bytes.
867 This might also match files that have been compressed by the filesystem.
869 True if the file is of the specified type.
870 Possible file types are as follows:
872 .Bl -tag -width indent -compact
891 for compatibility with GNU find.
892 GNU find imposes a restriction that
897 .It Ic -user Ar uname
898 True if the file belongs to the user
902 is numeric and there is no such user name, then
904 is treated as a user ID.
905 .It Ic -wholename Ar pattern
908 for GNU find compatibility.
911 The primaries may be combined using the following operators.
912 The operators are listed in order of decreasing precedence.
914 .Bl -tag -width indent -compact
915 .It Cm \&( Ar expression Cm \&)
916 This evaluates to true if the parenthesized expression evaluates to
919 .It Cm \&! Ar expression
920 .It Cm -not Ar expression
924 It evaluates to true if the expression is false.
931 .It Ar expression Cm -and Ar expression
932 .It Ar expression expression
935 operator is the logical
938 As it is implied by the juxtaposition of two expressions it does not
939 have to be specified.
940 The expression evaluates to true if both expressions are true.
941 The second expression is not evaluated if the first expression is false.
943 .It Ar expression Cm -or Ar expression
946 operator is the logical
949 The expression evaluates to true if either the first or the second expression
951 The second expression is not evaluated if the first expression is true.
954 All operands and primaries must be separate arguments to
956 Primaries which themselves take arguments expect each argument
957 to be a separate argument to
961 .Ev LANG , LC_ALL , LC_COLLATE , LC_CTYPE , LC_MESSAGES
964 environment variables affect the execution of the
966 utility as described in
969 The following examples are shown as given to the shell:
970 .Bl -tag -width indent
971 .It Li "find / \e! -name \*q*.c\*q -print"
972 Print out a list of all the files whose names do not end in
974 .It Li "find / -newer ttt -user wnj -print"
975 Print out a list of all the files owned by user
980 .It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
981 Print out a list of all the files which are not both newer than
985 .It Li "find / \e( -newer ttt -or -user wnj \e) -print"
986 Print out a list of all the files that are either owned by
988 or that are newer than
990 .It Li "find / -newerct '1 minute ago' -print"
991 Print out a list of all the files whose inode change time is more
992 recent than the current time minus one minute.
993 .It Li "find / -type f -exec echo {} \e;"
996 command to print out a list of all the files.
997 .It Li "find -L /usr/ports/packages -type l -exec rm -- {} +"
998 Delete all broken symbolic links in
999 .Pa /usr/ports/packages .
1000 .It Li "find /usr/src -name CVS -prune -o -depth +6 -print"
1001 Find files and directories that are at least seven levels deep
1002 in the working directory
1004 .It Li "find /usr/src -name CVS -prune -o -mindepth 7 -print"
1005 Is not equivalent to the previous example, since
1007 is not evaluated below level seven.
1012 primary is deprecated; the
1014 option should be used instead.
1017 section below for details.
1038 utility syntax is a superset of the syntax specified by the
1042 All the single character options except
1047 .Ic -amin , -anewer , -cmin , -cnewer , -delete , -empty , -fstype ,
1048 .Ic -iname , -inum , -iregex , -ls , -maxdepth , -mindepth , -mmin ,
1049 .Ic -not , -path , -print0 , -regex , -sparse
1052 birthtime related primaries are extensions to
1059 options were implemented using the primaries
1060 .Ic -depth , -follow ,
1063 These primaries always evaluated to true.
1064 As they were really global variables that took effect before the traversal
1065 began, some legal expressions could have unexpected results.
1066 An example is the expression
1067 .Ic -print Cm -o Ic -depth .
1070 always evaluates to true, the standard order of evaluation
1073 would never be evaluated.
1074 This is not the case.
1085 Historic implementations of the
1089 primaries did not replace the string
1091 in the utility name or the
1092 utility arguments if it had preceding or following non-whitespace characters.
1093 This version replaces it no matter where in the utility name or arguments
1098 option was inspired by the equivalent
1110 It was rewritten for
1112 and later be enhanced for the Programmer's Workbench (PWB).
1113 These changes were later incorporated in
1116 The special characters used by
1118 are also special characters to many shell programs.
1119 In particular, the characters
1130 may have to be escaped from the shell.
1132 As there is no delimiter separating options and file names or file
1135 it is difficult to specify files named
1139 These problems are handled by the
1148 primary does not interact well with other options that cause the file system
1149 tree traversal options to be changed.
1155 primaries are actually global options (as documented above).
1157 probably be replaced by options which look like options.