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
32 .\" $FreeBSD: src/usr.bin/find/find.1,v 1.97 2012/06/13 21:53:40 jilles Exp $
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 file last access time and the time
174 was started, rounded up to the next full minute, is
177 .It Ic -anewer Ar file
180 .It Ic -atime Ar n Ns Op Cm smhdw
181 If no units are specified, this primary evaluates to
182 true if the difference between the file last access time and the time
184 was started, rounded up to the next full 24-hour period, is
188 If units are specified, this primary evaluates to
189 true if the difference between the file last access time and the time
191 was started is exactly
194 Possible time units are as follows:
196 .Bl -tag -width indent -compact
209 Any number of units may be combined in one
211 argument, for example,
212 .Dq Li "-atime -1h30m" .
213 Units are probably only useful when used in conjunction with the
219 True if the difference between the time of last change of file status
220 information and the time
222 was started, rounded up to the next full minute, is
225 .It Ic -cnewer Ar file
228 .It Ic -ctime Ar n Ns Op Cm smhdw
229 If no units are specified, this primary evaluates to
230 true if the difference between the time of last change of file status
231 information 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 time of last change of file status
239 information and the time
241 was started is exactly
246 primary description for information on supported time units.
248 Non-portable, BSD-specific version of
250 GNU find implements this as a primary in mistaken emulation of
254 Delete found files and/or directories.
257 from the current working directory as
259 recurses down the tree.
260 It will not attempt to delete a filename with a
262 character in its pathname relative to
264 for security reasons.
265 Depth-first traversal processing is implied by this option.
268 primary will fail to delete a directory if it is not empty.
269 Following symlinks is incompatible with this option.
272 same as the non-portable
277 to perform a depth-first traversal, i.e., directories
278 are visited in post-order and all entries in a directory will be acted
279 on before the directory itself.
282 visits directories in pre-order, i.e., before their contents.
285 a breadth-first traversal.
294 to process files that are contained in directories with unusual permissions.
295 It ensures that you have write permission while you are placing files in a
296 directory, then sets the directory's permissions as the last thing.
298 True if the depth of the file relative to the starting point of the traversal
302 True if the current file or directory is empty.
303 .It Ic -exec Ar utility Oo Ar argument ... Oc Li \&;
304 True if the program named
306 returns a zero value as its exit status.
309 may be passed to the utility.
310 The expression must be terminated by a semicolon
314 from a shell you may need to quote the semicolon if the shell would
315 otherwise treat it as a control operator.
318 appears anywhere in the utility name or the
319 arguments it is replaced by the pathname of the current file.
321 will be executed from the directory from which
327 are not subject to the further expansion of shell patterns
329 .It Ic -exec Ar utility Oo Ar argument ... Oc Li {} +
334 is replaced with as many pathnames as possible for each invocation of
336 This behaviour is similar to that of
338 .It Ic -execdir Ar utility Oo Ar argument ... Oc Li \&;
341 primary is identical to the
343 primary with the exception that
345 will be executed from the directory that holds
347 The filename substituted for
351 .It Ic -execdir Ar utility Oo Ar argument ... Oc Li {} +
356 is replaced with as many pathnames as possible for each invocation of
358 This behaviour is similar to that of
360 .It Ic -flags Oo Cm - Ns | Ns Cm + Oc Ns Ar flags , Ns Ar notflags
361 The flags are specified using symbolic names (see
371 are checked to be set, and flags in
373 are checked to be not set.
374 Note that this is different from
376 which only allows the user to specify mode bits that are set.
378 If flags are preceded by a dash
380 this primary evaluates to true
381 if at least all of the bits in
383 and none of the bits in
385 are set in the file's flags bits.
386 If flags are preceded by a plus
388 this primary evaluates to true
389 if any of the bits in
391 is set in the file's flags bits,
392 or any of the bits in
394 is not set in the file's flags bits.
396 this primary evaluates to true
399 exactly match the file's flags bits,
404 .It Ic -fstype Ar type
405 True if the file is contained in a file system of type
409 command can be used to find out the types of file systems
410 that are available on the system.
411 In addition, there are two pseudo-types,
415 The former matches any file system physically mounted on the system where
418 is being executed and the latter matches any file system which is
423 for compatibility with GNU find.
424 GNU find imposes a restriction that
429 .It Ic -group Ar gname
430 True if the file belongs to the group
434 is numeric and there is no such group name, then
436 is treated as a group ID.
437 .It Ic -ignore_readdir_race
438 This option is for GNU find compatibility and is ignored.
439 .It Ic -ilname Ar pattern
442 but the match is case insensitive.
443 This is a GNU find extension.
444 .It Ic -iname Ar pattern
447 but the match is case insensitive.
449 True if the file has inode number
451 .It Ic -ipath Ar pattern
454 but the match is case insensitive.
455 .It Ic -iregex Ar pattern
458 but the match is case insensitive.
459 .It Ic -iwholename Ar pattern
462 for GNU find compatibility.
467 .It Ic -lname Ar pattern
470 but the contents of the symbolic link are matched instead of the file
472 This is a GNU find extension.
474 This primary always evaluates to true.
475 The following information for the current file is written to standard output:
476 its inode number, size in 512-byte blocks, file permissions, number of hard
477 links, owner, group, size in bytes, last modification time, and pathname.
478 If the file is a block or character special file, the device number
479 will be displayed instead of the size in bytes.
480 If the file is a symbolic link, the pathname of the linked-to file will be
481 displayed preceded by
483 The format is identical to that produced by
487 .It Ic -maxdepth Ar n
488 Always true; descend at most
490 directory levels below the command line arguments.
493 primary is specified, it applies to the entire expression even if it would
494 not normally be evaluated.
495 .Dq Ic -maxdepth Li 0
496 limits the whole search to the command line arguments.
497 .It Ic -mindepth Ar n
498 Always true; do not apply any tests or actions at levels less than
502 primary is specified, it applies to the entire expression even if it would
503 not normally be evaluated.
504 .Dq Ic -mindepth Li 1
505 processes all but the command line arguments.
507 True if the difference between the file last modification time and the time
509 was started, rounded up to the next full minute, is
512 .It Ic -mnewer Ar file
518 for GNU find compatibility.
519 .It Ic -mtime Ar n Ns Op Cm smhdw
520 If no units are specified, this primary evaluates to
521 true if the difference between the file last modification time and the time
523 was started, rounded up to the next full 24-hour period, is
527 If units are specified, this primary evaluates to
528 true if the difference between the file last modification time and the time
530 was started is exactly
535 primary description for information on supported time units.
536 .It Ic -name Ar pattern
537 True if the last component of the pathname being examined matches
539 Special shell pattern matching characters
545 may be used as part of
547 These characters may be matched explicitly by escaping them with a
550 .It Ic -newer Ar file
551 True if the current file has a more recent last modification time than
553 .It Ic -newer Ns Ar X Ns Ar Y Ar file
554 True if the current file has a more recent last access time
555 .Pq Ar X Ns = Ns Cm a ,
557 .Pq Ar X Ns = Ns Cm c ,
559 .Pq Ar X Ns = Ns Cm m
560 than the last access time
561 .Pq Ar Y Ns = Ns Cm a ,
563 .Pq Ar Y Ns = Ns Cm c ,
565 .Pq Ar Y Ns = Ns Cm m
572 is instead interpreted as a direct date specification of the form
580 True if the file belongs to an unknown group.
581 .It Ic -noignore_readdir_race
582 This option is for GNU find compatibility and is ignored.
584 This option is for GNU find compatibility.
585 In GNU find it disables an optimization not relevant to
589 True if the file belongs to an unknown user.
590 .It Ic -ok Ar utility Oo Ar argument ... Oc Li \&;
593 primary is identical to the
595 primary with the exception that
597 requests user affirmation for the execution of the
600 a message to the terminal and reading a response.
601 If the response is other than
603 the command is not executed and the
607 .It Ic -okdir Ar utility Oo Ar argument ... Oc Li \&;
610 primary is identical to the
612 primary with the same exception as described for the
615 .It Ic -path Ar pattern
616 True if the pathname being examined matches
618 Special shell pattern matching characters
624 may be used as part of
626 These characters may be matched explicitly by escaping them with a
631 are treated as normal characters and do not have to be
633 .It Ic -perm Oo Cm - Ns | Ns Cm + Oc Ns Ar mode
636 may be either symbolic (see
641 is symbolic, a starting value of zero is assumed and the
643 sets or clears permissions without regard to the process' file mode
647 is octal, only bits 07777
648 .Pq Dv S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO
649 of the file's mode bits participate
653 is preceded by a dash
655 this primary evaluates to true
656 if at least all of the bits in the
658 are set in the file's mode bits.
661 is preceded by a plus
663 this primary evaluates to true
664 if any of the bits in the
666 are set in the file's mode bits.
667 Otherwise, this primary evaluates to true if
670 exactly match the file's mode bits.
671 Note, the first character of a symbolic mode may not be a dash
674 This primary always evaluates to true.
675 It prints the pathname of the current file to standard output.
677 .Ic -exec , -ls , -print0 ,
680 is specified, the given expression shall be effectively replaced by
681 .Cm \&( Ar "given expression" Cm \&) Ic -print .
683 This primary always evaluates to true.
684 It prints the pathname of the current file to standard output, followed by an
687 character (character code 0).
689 This primary always evaluates to true.
692 to not descend into the current file.
695 primary has no effect if the
697 option was specified.
698 .It Ic -regex Ar pattern
699 True if the whole path of the file matches
701 using regular expression.
702 To match a file named
704 you can use the regular expression
712 .It Ic -samefile Ar name
713 True if the file is a hard link to
715 If the command option
717 is specified, it is also true if the file is a symbolic link and
720 .It Ic -size Ar n Ns Op Cm ckMGTP
721 True if the file's size, rounded up, in 512-byte blocks is
727 then the primary is true if the
733 is followed by a scale indicator then the file's size is compared to
737 .Bl -tag -width indent -compact
739 kilobytes (1024 bytes)
741 megabytes (1024 kilobytes)
743 gigabytes (1024 megabytes)
745 terabytes (1024 gigabytes)
747 petabytes (1024 terabytes)
750 True if the file is of the specified type.
751 Possible file types are as follows:
753 .Bl -tag -width indent -compact
772 for compatibility with GNU find.
773 GNU find imposes a restriction that
778 .It Ic -user Ar uname
779 True if the file belongs to the user
783 is numeric and there is no such user name, then
785 is treated as a user ID.
786 .It Ic -wholename Ar pattern
789 for GNU find compatibility.
792 The primaries may be combined using the following operators.
793 The operators are listed in order of decreasing precedence.
795 .Bl -tag -width indent -compact
796 .It Cm \&( Ar expression Cm \&)
797 This evaluates to true if the parenthesized expression evaluates to
800 .It Cm \&! Ar expression
801 .It Cm -not Ar expression
805 It evaluates to true if the expression is false.
812 .It Ar expression Cm -and Ar expression
813 .It Ar expression expression
816 operator is the logical
819 As it is implied by the juxtaposition of two expressions it does not
820 have to be specified.
821 The expression evaluates to true if both expressions are true.
822 The second expression is not evaluated if the first expression is false.
824 .It Ar expression Cm -or Ar expression
827 operator is the logical
830 The expression evaluates to true if either the first or the second expression
832 The second expression is not evaluated if the first expression is true.
835 All operands and primaries must be separate arguments to
837 Primaries which themselves take arguments expect each argument
838 to be a separate argument to
842 .Ev LANG , LC_ALL , LC_COLLATE , LC_CTYPE , LC_MESSAGES
845 environment variables affect the execution of the
847 utility as described in
850 The following examples are shown as given to the shell:
851 .Bl -tag -width indent
852 .It Li "find / \e! -name \*q*.c\*q -print"
853 Print out a list of all the files whose names do not end in
855 .It Li "find / -newer ttt -user wnj -print"
856 Print out a list of all the files owned by user
861 .It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
862 Print out a list of all the files which are not both newer than
866 .It Li "find / \e( -newer ttt -or -user wnj \e) -print"
867 Print out a list of all the files that are either owned by
869 or that are newer than
871 .It Li "find / -newerct '1 minute ago' -print"
872 Print out a list of all the files whose inode change time is more
873 recent than the current time minus one minute.
874 .It Li "find / -type f -exec echo {} \e;"
877 command to print out a list of all the files.
878 .It Li "find -L /usr/ports/packages -type l -exec rm -- {} +"
879 Delete all broken symbolic links in
880 .Pa /usr/ports/packages .
881 .It Li "find /usr/src -name CVS -prune -o -depth +6 -print"
882 Find files and directories that are at least seven levels deep
883 in the working directory
885 .It Li "find /usr/src -name CVS -prune -o -mindepth 7 -print"
886 Is not equivalent to the previous example, since
888 is not evaluated below level seven.
893 primary is deprecated; the
895 option should be used instead.
898 section below for details.
918 utility syntax is a superset of the syntax specified by the
922 All the single character options except
927 .Ic -amin , -anewer , -cmin , -cnewer , -delete , -empty , -fstype ,
928 .Ic -iname , -inum , -iregex , -ls , -maxdepth , -mindepth , -mmin ,
929 .Ic -path , -print0 , -regex
937 options were implemented using the primaries
938 .Ic -depth , -follow ,
941 These primaries always evaluated to true.
942 As they were really global variables that took effect before the traversal
943 began, some legal expressions could have unexpected results.
944 An example is the expression
945 .Ic -print Cm -o Ic -depth .
948 always evaluates to true, the standard order of evaluation
951 would never be evaluated.
952 This is not the case.
963 Historic implementations of the
967 primaries did not replace the string
969 in the utility name or the
970 utility arguments if it had preceding or following non-whitespace characters.
971 This version replaces it no matter where in the utility name or arguments
976 option was inspired by the equivalent
987 The special characters used by
989 are also special characters to many shell programs.
990 In particular, the characters
1001 may have to be escaped from the shell.
1003 As there is no delimiter separating options and file names or file
1006 it is difficult to specify files named
1010 These problems are handled by the
1019 primary does not interact well with other options that cause the file system
1020 tree traversal options to be changed.
1026 primaries are actually global options (as documented above).
1028 probably be replaced by options which look like options.