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 .\" 4. 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
39 .Nd walk a file hierarchy
42 .Op Fl H | Fl L | Fl P
48 .Op Fl H | Fl L | Fl P
56 utility 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:
68 .Bl -tag -width indent
70 Interpret regular expressions followed by
74 primaries as extended (modern) regular expressions rather than basic
75 regular expressions (BRE's).
78 manual page fully describes both formats.
80 Cause the file information and file type (see
82 returned for each symbolic link specified on the command line to be
83 those of the file referenced by the link, not the link itself.
84 If the referenced file does not exist, the file information and type will
85 be for the link itself.
86 File information of all symbolic links not on
87 the command line is that of the link itself.
89 Cause the file information and file type (see
91 returned for each symbolic link to be those of the file referenced by the
92 link, not the link itself.
93 If the referenced file does not exist, the file information and type will
94 be for the link itself.
96 This option is equivalent to the deprecated
100 Cause the file information and file type (see
102 returned for each symbolic link to be those of the link itself.
107 to be safely used in conjunction with
109 If a file name contains any of the delimiting characters used by
111 a diagnostic message is displayed on standard error, and the file
113 The delimiting characters include single
119 space, tab and newline characters.
121 However, you may wish to consider the
123 primary in conjunction with
125 as an effective alternative.
129 to perform a depth-first traversal.
131 This option is a BSD-specific equivalent of the
135 Refer to its description under
137 for more information.
141 to traverse the file hierarchies in lexicographical order,
142 i.e., alphabetical order within each directory.
147 may give different results.
151 from descending into directories that have a device number different
152 than that of the file from which the descent began.
154 This option is equivalent to the deprecated
159 All primaries which take a numeric argument allow the number to be
160 preceded by a plus sign
164 A preceding plus sign means
166 a preceding minus sign means
170 .Bl -tag -width indent
172 True if the difference between the time of a file's inode creation
175 was started, rounded up to the next full minute, is
178 .It Ic -Bnewer Ar file
181 .It Ic -Btime Ar n Ns Op Cm smhdw
182 If no units are specified, this primary evaluates to
183 true if the difference between the time of a file's inode creation
186 was started, rounded up to the next full 24-hour period, is
190 If units are specified, this primary evaluates to
191 true if the difference between the time of a file's inode creation
194 was started is exactly
199 primary description for information on supported time units.
201 May be used in conjunction with other primaries to locate
202 files with extended ACLs.
205 for more information.
206 .It Ic -amin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
207 True if the difference between the file last access time and the time
209 was started, rounded up to the next full minute, is
219 .It Ic -anewer Ar file
222 .It Ic -atime Ar n Ns Op Cm smhdw
223 If no units are specified, this primary evaluates to
224 true if the difference between the file last access time and the time
226 was started, rounded up to the next full 24-hour period, is
230 If units are specified, this primary evaluates to
231 true if the difference between the file last access time and the time
233 was started is exactly
236 Possible time units are as follows:
238 .Bl -tag -width indent -compact
251 Any number of units may be combined in one
253 argument, for example,
254 .Dq Li "-atime -1h30m" .
255 Units are probably only useful when used in conjunction with the
260 .It Ic -cmin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
261 True if the difference between the time of last change of file status
262 information and the time
264 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 Non-portable, BSD-specific version of
299 GNU find implements this as a primary in mistaken emulation of
303 Delete found files and/or directories.
306 from the current working directory as
308 recurses down the tree.
309 It will not attempt to delete a filename with a
311 character in its pathname relative to
313 for security reasons.
314 Depth-first traversal processing is implied by this option.
317 primary will fail to delete a directory if it is not empty.
318 Following symlinks is incompatible with this option.
321 same as the non-portable
326 to perform a depth-first traversal, i.e., directories
327 are visited in post-order and all entries in a directory will be acted
328 on before the directory itself.
331 visits directories in pre-order, i.e., before their contents.
334 a breadth-first traversal.
343 to process files that are contained in directories with unusual permissions.
344 It ensures that you have write permission while you are placing files in a
345 directory, then sets the directory's permissions as the last thing.
347 True if the depth of the file relative to the starting point of the traversal
351 True if the current file or directory is empty.
352 .It Ic -exec Ar utility Oo Ar argument ... Oc Li \&;
353 True if the program named
355 returns a zero value as its exit status.
358 may be passed to the utility.
359 The expression must be terminated by a semicolon
363 from a shell you may need to quote the semicolon if the shell would
364 otherwise treat it as a control operator.
367 appears anywhere in the utility name or the
368 arguments it is replaced by the pathname of the current file.
370 will be executed from the directory from which
376 are not subject to the further expansion of shell patterns
378 .It Ic -exec Ar utility Oo Ar argument ... Oc Li {} +
383 is replaced with as many pathnames as possible for each invocation of
385 This behaviour is similar to that of
387 .It Ic -execdir Ar utility Oo Ar argument ... Oc Li \&;
390 primary is identical to the
392 primary with the exception that
394 will be executed from the directory that holds
396 The filename substituted for
400 .It Ic -execdir Ar utility Oo Ar argument ... Oc Li {} +
405 is replaced with as many pathnames as possible for each invocation of
407 This behaviour is similar to that of
409 .It Ic -flags Oo Cm - Ns | Ns Cm + Oc Ns Ar flags , Ns Ar notflags
410 The flags are specified using symbolic names (see
420 are checked to be set, and flags in
422 are checked to be not set.
423 Note that this is different from
425 which only allows the user to specify mode bits that are set.
427 If flags are preceded by a dash
429 this primary evaluates to true
430 if at least all of the bits in
432 and none of the bits in
434 are set in the file's flags bits.
435 If flags are preceded by a plus
437 this primary evaluates to true
438 if any of the bits in
440 is set in the file's flags bits,
441 or any of the bits in
443 is not set in the file's flags bits.
445 this primary evaluates to true
448 exactly match the file's flags bits,
453 .It Ic -fstype Ar type
454 True if the file is contained in a file system of type
458 command can be used to find out the types of file systems
459 that are available on the system.
460 In addition, there are two pseudo-types,
464 The former matches any file system physically mounted on the system where
467 is being executed and the latter matches any file system which is
472 for compatibility with GNU find.
473 GNU find imposes a restriction that
478 .It Ic -group Ar gname
479 True if the file belongs to the group
483 is numeric and there is no such group name, then
485 is treated as a group ID.
486 .It Ic -ignore_readdir_race
487 Ignore errors because a file or a directory is deleted
488 after reading the name from a directory.
489 This option does not affect errors occurring on starting points.
490 .It Ic -ilname Ar pattern
493 but the match is case insensitive.
494 This is a GNU find extension.
495 .It Ic -iname Ar pattern
498 but the match is case insensitive.
500 True if the file has inode number
502 .It Ic -ipath Ar pattern
505 but the match is case insensitive.
506 .It Ic -iregex Ar pattern
509 but the match is case insensitive.
510 .It Ic -iwholename Ar pattern
513 for GNU find compatibility.
518 .It Ic -lname Ar pattern
521 but the contents of the symbolic link are matched instead of the file
523 Note that this only matches broken symbolic links
524 if symbolic links are being followed.
525 This is a GNU find extension.
527 This primary always evaluates to true.
528 The following information for the current file is written to standard output:
529 its inode number, size in 512-byte blocks, file permissions, number of hard
530 links, owner, group, size in bytes, last modification time, and pathname.
531 If the file is a block or character special file, the device number
532 will be displayed instead of the size in bytes.
533 If the file is a symbolic link, the pathname of the linked-to file will be
534 displayed preceded by
536 The format is identical to that produced by
540 .It Ic -maxdepth Ar n
541 Always true; descend at most
543 directory levels below the command line arguments.
546 primary is specified, it applies to the entire expression even if it would
547 not normally be evaluated.
548 .Dq Ic -maxdepth Li 0
549 limits the whole search to the command line arguments.
550 .It Ic -mindepth Ar n
551 Always true; do not apply any tests or actions at levels less than
555 primary is specified, it applies to the entire expression even if it would
556 not normally be evaluated.
557 .Dq Ic -mindepth Li 1
558 processes all but the command line arguments.
559 .It Ic -mmin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
560 True if the difference between the file last modification time and the time
562 was started, rounded up to the next full minute, is
572 .It Ic -mnewer Ar file
578 for GNU find compatibility.
579 .It Ic -mtime Ar n Ns Op Cm smhdw
580 If no units are specified, this primary evaluates to
581 true if the difference between the file last modification time and the time
583 was started, rounded up to the next full 24-hour period, is
587 If units are specified, this primary evaluates to
588 true if the difference between the file last modification time and the time
590 was started is exactly
595 primary description for information on supported time units.
596 .It Ic -name Ar pattern
597 True if the last component of 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
610 .It Ic -newer Ar file
611 True if the current file has a more recent last modification time than
613 .It Ic -newer Ns Ar X Ns Ar Y Ar file
614 True if the current file has a more recent last access time
615 .Pq Ar X Ns = Ns Cm a ,
617 .Pq Ar X Ns = Ns Cm B ,
619 .Pq Ar X Ns = Ns Cm c ,
621 .Pq Ar X Ns = Ns Cm m
622 than the last access time
623 .Pq Ar Y Ns = Ns Cm a ,
625 .Pq Ar Y Ns = Ns Cm B ,
627 .Pq Ar Y Ns = Ns Cm c ,
629 .Pq Ar Y Ns = Ns Cm m
636 is instead interpreted as a direct date specification of the form
644 True if the file belongs to an unknown group.
645 .It Ic -noignore_readdir_race
646 Turn off the effect of
647 .Ic -ignore_readdir_race .
648 This is default behaviour.
650 This option is for GNU find compatibility.
651 In GNU find it disables an optimization not relevant to
655 True if the file belongs to an unknown user.
656 .It Ic -ok Ar utility Oo Ar argument ... Oc Li \&;
659 primary is identical to the
661 primary with the exception that
663 requests user affirmation for the execution of the
666 a message to the terminal and reading a response.
667 If the response is not affirmative
672 the command is not executed and the
676 .It Ic -okdir Ar utility Oo Ar argument ... Oc Li \&;
679 primary is identical to the
681 primary with the same exception as described for the
684 .It Ic -path Ar pattern
685 True if the pathname being examined matches
687 Special shell pattern matching characters
693 may be used as part of
695 These characters may be matched explicitly by escaping them with a
700 are treated as normal characters and do not have to be
702 .It Ic -perm Oo Cm - Ns | Ns Cm + Oc Ns Ar mode
705 may be either symbolic (see
710 is symbolic, a starting value of zero is assumed and the
712 sets or clears permissions without regard to the process' file mode
716 is octal, only bits 07777
717 .Pq Dv S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO
718 of the file's mode bits participate
722 is preceded by a dash
724 this primary evaluates to true
725 if at least all of the bits in the
727 are set in the file's mode bits.
730 is preceded by a plus
732 this primary evaluates to true
733 if any of the bits in the
735 are set in the file's mode bits.
736 Otherwise, this primary evaluates to true if
739 exactly match the file's mode bits.
740 Note, the first character of a symbolic mode may not be a dash
743 This primary always evaluates to true.
744 It prints the pathname of the current file to standard output.
746 .Ic -exec , -ls , -print0 ,
749 is specified, the given expression shall be effectively replaced by
750 .Cm \&( Ar "given expression" Cm \&) Ic -print .
752 This primary always evaluates to true.
753 It prints the pathname of the current file to standard output, followed by an
756 character (character code 0).
758 This primary always evaluates to true.
761 to not descend into the current file.
764 primary has no effect if the
766 option was specified.
770 to immediately terminate successfully.
771 .It Ic -regex Ar pattern
772 True if the whole path of the file matches
774 using regular expression.
775 To match a file named
777 you can use the regular expression
785 .It Ic -samefile Ar name
786 True if the file is a hard link to
788 If the command option
790 is specified, it is also true if the file is a symbolic link and
793 .It Ic -size Ar n Ns Op Cm ckMGTP
794 True if the file's size, rounded up, in 512-byte blocks is
800 then the primary is true if the
806 is followed by a scale indicator then the file's size is compared to
810 .Bl -tag -width indent -compact
812 kilobytes (1024 bytes)
814 megabytes (1024 kilobytes)
816 gigabytes (1024 megabytes)
818 terabytes (1024 gigabytes)
820 petabytes (1024 terabytes)
823 True if the current file is sparse,
824 i.e. has fewer blocks allocated than expected based on its size in bytes.
825 This might also match files that have been compressed by the filesystem.
827 True if the file is of the specified type.
828 Possible file types are as follows:
830 .Bl -tag -width indent -compact
849 for compatibility with GNU find.
850 GNU find imposes a restriction that
855 .It Ic -user Ar uname
856 True if the file belongs to the user
860 is numeric and there is no such user name, then
862 is treated as a user ID.
863 .It Ic -wholename Ar pattern
866 for GNU find compatibility.
869 The primaries may be combined using the following operators.
870 The operators are listed in order of decreasing precedence.
872 .Bl -tag -width indent -compact
873 .It Cm \&( Ar expression Cm \&)
874 This evaluates to true if the parenthesized expression evaluates to
877 .It Cm \&! Ar expression
878 .It Cm -not Ar expression
882 It evaluates to true if the expression is false.
889 .It Ar expression Cm -and Ar expression
890 .It Ar expression expression
893 operator is the logical
896 As it is implied by the juxtaposition of two expressions it does not
897 have to be specified.
898 The expression evaluates to true if both expressions are true.
899 The second expression is not evaluated if the first expression is false.
901 .It Ar expression Cm -or Ar expression
904 operator is the logical
907 The expression evaluates to true if either the first or the second expression
909 The second expression is not evaluated if the first expression is true.
912 All operands and primaries must be separate arguments to
914 Primaries which themselves take arguments expect each argument
915 to be a separate argument to
919 .Ev LANG , LC_ALL , LC_COLLATE , LC_CTYPE , LC_MESSAGES
922 environment variables affect the execution of the
924 utility as described in
927 The following examples are shown as given to the shell:
928 .Bl -tag -width indent
929 .It Li "find / \e! -name \*q*.c\*q -print"
930 Print out a list of all the files whose names do not end in
932 .It Li "find / -newer ttt -user wnj -print"
933 Print out a list of all the files owned by user
938 .It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
939 Print out a list of all the files which are not both newer than
943 .It Li "find / \e( -newer ttt -or -user wnj \e) -print"
944 Print out a list of all the files that are either owned by
946 or that are newer than
948 .It Li "find / -newerct '1 minute ago' -print"
949 Print out a list of all the files whose inode change time is more
950 recent than the current time minus one minute.
951 .It Li "find / -type f -exec echo {} \e;"
954 command to print out a list of all the files.
955 .It Li "find -L /usr/ports/packages -type l -exec rm -- {} +"
956 Delete all broken symbolic links in
957 .Pa /usr/ports/packages .
958 .It Li "find /usr/src -name CVS -prune -o -depth +6 -print"
959 Find files and directories that are at least seven levels deep
960 in the working directory
962 .It Li "find /usr/src -name CVS -prune -o -mindepth 7 -print"
963 Is not equivalent to the previous example, since
965 is not evaluated below level seven.
970 primary is deprecated; the
972 option should be used instead.
975 section below for details.
996 utility syntax is a superset of the syntax specified by the
1000 All the single character options except
1005 .Ic -amin , -anewer , -cmin , -cnewer , -delete , -empty , -fstype ,
1006 .Ic -iname , -inum , -iregex , -ls , -maxdepth , -mindepth , -mmin ,
1007 .Ic -path , -print0 , -regex , -sparse
1010 birthtime related primaries are extensions to
1017 options were implemented using the primaries
1018 .Ic -depth , -follow ,
1021 These primaries always evaluated to true.
1022 As they were really global variables that took effect before the traversal
1023 began, some legal expressions could have unexpected results.
1024 An example is the expression
1025 .Ic -print Cm -o Ic -depth .
1028 always evaluates to true, the standard order of evaluation
1031 would never be evaluated.
1032 This is not the case.
1043 Historic implementations of the
1047 primaries did not replace the string
1049 in the utility name or the
1050 utility arguments if it had preceding or following non-whitespace characters.
1051 This version replaces it no matter where in the utility name or arguments
1056 option was inspired by the equivalent
1067 The special characters used by
1069 are also special characters to many shell programs.
1070 In particular, the characters
1081 may have to be escaped from the shell.
1083 As there is no delimiter separating options and file names or file
1086 it is difficult to specify files named
1090 These problems are handled by the
1099 primary does not interact well with other options that cause the file system
1100 tree traversal options to be changed.
1106 primaries are actually global options (as documented above).
1108 probably be replaced by options which look like options.