1 .\" The Regents of the University of California. All rights reserved.
3 .\" This code is derived from software contributed to Berkeley by
4 .\" the Institute of Electrical and Electronics Engineers, Inc.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)find.1 8.7 (Berkeley) 5/9/95
42 .Nd walk a file hierarchy
45 .Op Fl H | Fl L | Fl P
52 recursively descends the directory tree for each
60 listed below) in terms
61 of each file in the tree.
63 The options are as follows:
64 .Bl -tag -width indent
66 Interpret regular expressions followed by
70 options as extended (modern) regular expressions rather than basic
71 regular expressions (BRE's).
74 manual page fully describes both formats.
78 option causes the file information and file type (see
80 returned for each symbolic link specified on the command line to be
81 those of the file referenced by the link, not the link itself.
82 If the referenced file does not exist, the file information and type will
83 be for the link itself.
84 File information of all symbolic links not on
85 the command line is that of the link itself.
89 option causes 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.
98 option causes the file information and file type (see
100 returned for each symbolic link to be those of the link itself.
105 option is a modification to permit
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.
125 to perform a depth\-first traversal, i.e., directories
126 are visited in post\-order and all entries in a directory will be acted
127 on before the directory itself.
130 visits directories in pre\-order, i.e., before their contents.
133 a breadth\-first traversal.
137 option specifies a file hierarchy for
140 File hierarchies may also be specified as the operands immediately
141 following the options.
147 to traverse the file hierarchies in lexicographical order,
148 i.e., alphabetical order within each directory.
153 may give different results.
159 from descending into directories that have a device number different
160 than that of the file from which the descent began.
163 .Bl -tag -width indent
165 True if the difference between the file last access time and the time
167 was started, rounded up to the next full minute, is
170 .It Ic -anewer Ar file
173 .It Ic -atime Ar n Ns Op Cm smhdw
174 If no units are specified, this primary evaluates to
175 true if the difference between the file last access time and the time
177 was started, rounded up to the next full 24\-hour period, is
181 If units are specified, this primary evaluates to
182 true if the difference between the file last access time and the time
184 was started is exactly
187 Possible time units are as follows:
189 .Bl -tag -width indent -compact
202 Any number of units may be combined in one
204 argument, for example,
205 .Dq Li "-atime -1h30m" .
206 Units are probably only useful when used in conjunction with the
212 True if the difference between the time of last change of file status
213 information and the time
215 was started, rounded up to the next full minute, is
218 .It Ic -cnewer Ar file
221 .It Ic -ctime Ar n Ns Op Cm smhdw
222 If no units are specified, this primary evaluates to
223 true if the difference between the time of last change of file status
224 information 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 time of last change of file status
232 information and the time
234 was started is exactly
239 primary description for information on supported time units.
241 Delete found files and/or directories.
244 from the current working directory as
246 recurses down the tree.
247 It will not attempt to delete a filename with a
249 character in its pathname relative to
251 for security reasons.
252 Depth\-first traversal processing is implied by this option.
263 to process files that are contained in directories with unusual permissions.
264 It enures that you have write permission while you are placing files in a
265 directory, then sets the directory's permissions as the last thing.
267 True if the current file or directory is empty.
268 .It Ic -exec Ar utility Op Ar argument ... ;
269 True if the program named
271 returns a zero value as its exit status.
274 may be passed to the utility.
275 The expression must be terminated by a semicolon
279 appears anywhere in the utility name or the
280 arguments it is replaced by the pathname of the current file.
282 will be executed from the directory from which
288 are not subject to the further expansion of shell patterns
290 .It Ic -execdir Ar utility Op Ar argument ... ;
293 primary is identical to the
295 primary with the exception that
297 will be executed from the directory that holds
299 The filename substituted for
303 .It Ic -flags Oo Cm - Ns | Ns Cm + Oc Ns Ar flags , Ns Ar notflags
304 The flags are specified using symbolic names (see
314 are checked to be set, and flags in
316 are checked to be not set.
317 Note that this is different from
319 which only allows the user to specify mode bits that are set.
321 If flags are preceded by a dash
323 this primary evaluates to true
324 if at least all of the bits in
326 and none of the bits in
328 are set in the file's flags bits.
329 If flags are preceded by a plus
331 this primary evaluates to true
332 if any of the bits in
334 is set in the file's flags bits,
335 or any of the bits in
337 is not set in the file's flags bits.
339 this primary evaluates to true
342 exactly match the file's flags bits,
347 .It Ic -fstype Ar type
348 True if the file is contained in a file system of type
352 command can be used to find out the types of filesystems
353 that are available on the system:
357 In addition, there are two pseudo-types,
361 The former matches any file system physically mounted on the system where
364 is being executed and the latter matches any file system which is
366 .It Ic -group Ar gname
367 True if the file belongs to the group
371 is numeric and there is no such group name, then
373 is treated as a group ID.
374 .It Ic -iname Ar pattern
377 but the match is case insensitive.
379 True if the file has inode number
381 .It Ic -ipath Ar pattern
384 but the match is case insensitive.
385 .It Ic -iregex Ar pattern
388 but the match is case insensitive.
394 This primary always evaluates to true.
395 The following information for the current file is written to standard output:
396 its inode number, size in 512\-byte blocks, file permissions, number of hard
397 links, owner, group, size in bytes, last modification time, and pathname.
398 If the file is a block or character special file, the major and minor numbers
399 will be displayed instead of the size in bytes.
400 If the file is a symbolic link, the pathname of the linked\-to file will be
401 displayed preceded by
403 The format is identical to that produced by
407 .It Ic -maxdepth Ar n
408 True if the depth of the current file into the tree is less than or equal to
410 .It Ic -mindepth Ar n
411 True if the depth of the current file into the tree is greater than or equal to
414 True if the difference between the file last modification time and the time
416 was started, rounded up to the next full minute, is
419 .It Ic -mnewer Ar file
422 .It Ic -mtime Ar n Ns Op Cm smhdw
423 If no units are specified, this primary evaluates to
424 true if the difference between the file last modification time and the time
426 was started, rounded up to the next full 24\-hour period, is
430 If units are specified, this primary evaluates to
431 true if the difference between the file last modification time and the time
433 was started is exactly
438 primary description for information on supported time units.
439 .It Ic -name Ar pattern
440 True if the last component of the pathname being examined matches
442 Special shell pattern matching characters
448 may be used as part of
450 These characters may be matched explicitly by escaping them with a
453 .It Ic -newer Ar file
454 True if the current file has a more recent last modification time than
456 .It Ic -newer Ns Ar X Ns Ar Y Ar file
457 True if the current file has a more recent last access time
458 .Ar ( X Ns = Ns Cm a ) ,
460 .Ar ( X Ns = Ns Cm c ) ,
462 .Ar ( X Ns = Ns Cm m )
463 than the last access time
464 .Ar ( Y Ns = Ns Cm a ) ,
466 .Ar ( Y Ns = Ns Cm c ) ,
468 .Ar ( Y Ns = Ns Cm m )
475 is instead interpreted as a direct date specification of the form
483 True if the file belongs to an unknown group.
485 True if the file belongs to an unknown user.
486 .It Ic -ok Ar utility Op Ar argument ... ;
489 primary is identical to the
491 primary with the exception that
493 requests user affirmation for the execution of the
496 a message to the terminal and reading a response.
497 If the response is other than
499 the command is not executed and the
503 .It Ic -okdir Ar utility Op Ar argument ... ;
506 primary is identical to the
508 primary with the same exception as described for the
511 .It Ic -path Ar pattern
512 True if the pathname being examined matches
514 Special shell pattern matching characters
520 may be used as part of
522 These characters may be matched explicitly by escaping them with a
527 are treated as normal characters and do not have to be
529 .It Ic -perm Oo Cm - Ns | Ns Cm + Oc Ns Ar mode
532 may be either symbolic (see
537 is symbolic, a starting value of zero is assumed and the
539 sets or clears permissions without regard to the process' file mode
543 is octal, only bits 07777
544 .Pq Dv S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO
545 of the file's mode bits participate
549 is preceded by a dash
551 this primary evaluates to true
552 if at least all of the bits in the
554 are set in the file's mode bits.
557 is preceded by a plus
559 this primary evaluates to true
560 if any of the bits in the
562 are set in the file's mode bits.
563 Otherwise, this primary evaluates to true if
566 exactly match the file's mode bits.
567 Note, the first character of a symbolic mode may not be a dash
570 This primary always evaluates to true.
571 It prints the pathname of the current file to standard output.
573 .Ic -exec , -ls , -print0 ,
576 is specified, the given expression shall be effectively replaced by
577 .Cm \&( Ar "given expression" Cm \&) Ic -print .
579 This primary always evaluates to true.
580 It prints the pathname of the current file to standard output, followed by an
582 character (character code 0).
584 This primary always evaluates to true.
587 to not descend into the current file.
590 primary has no effect if the
592 option was specified.
593 .It Ic -regex Ar pattern
594 True if the whole path of the file matches
596 using regular expression.
597 To match a file named
599 you can use the regular expression
607 .It Ic -size Ar n Ns Op Cm c
608 True if the file's size, rounded up, in 512\-byte blocks is
614 then the primary is true if the
619 True if the file is of the specified type.
620 Possible file types are as follows:
622 .Bl -tag -width indent -compact
638 .It Ic -user Ar uname
639 True if the file belongs to the user
643 is numeric and there is no such user name, then
645 is treated as a user ID.
648 All primaries which take a numeric argument allow the number to be
649 preceded by a plus sign
653 A preceding plus sign means
655 a preceding minus sign means
660 The primaries may be combined using the following operators.
661 The operators are listed in order of decreasing precedence.
663 .Bl -tag -width "( expression )" -compact
664 .It Cm \&( Ar expression Cm \&)
665 This evaluates to true if the parenthesized expression evaluates to
668 .It Cm \&! Ar expression
672 It evaluates to true if the expression is false.
674 .It Ar expression Cm -and Ar expression
675 .It Ar expression expression
678 operator is the logical
681 As it is implied by the juxtaposition of two expressions it does not
682 have to be specified.
683 The expression evaluates to true if both expressions are true.
684 The second expression is not evaluated if the first expression is false.
686 .It Ar expression Cm -or Ar expression
689 operator is the logical
692 The expression evaluates to true if either the first or the second expression
694 The second expression is not evaluated if the first expression is true.
697 All operands and primaries must be separate arguments to
699 Primaries which themselves take arguments expect each argument
700 to be a separate argument to
703 The following examples are shown as given to the shell:
704 .Bl -tag -width indent
705 .It Li "find / \e! -name \*q*.c\*q -print"
706 Print out a list of all the files whose names do not end in
708 .It Li "find / -newer ttt -user wnj -print"
709 Print out a list of all the files owned by user
714 .It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
715 Print out a list of all the files which are not both newer than
719 .It Li "find / \e( -newer ttt -or -user wnj \e) -print"
720 Print out a list of all the files that are either owned by
722 or that are newer than
724 .It Li "find . -newerct '1 minute ago' -print"
725 Print out a list of all the files whose inode change time is more
726 recent than the current time minus one minute.
745 utility syntax is a superset of the syntax specified by the
749 All the single character options as well as the
750 .Ic -iname , -inum , -iregex , -print0 , -delete , -ls ,
753 primaries are extensions to
760 options were implemented using the primaries
761 .Ic -depth , -follow ,
764 These primaries always evaluated to true.
765 As they were really global variables that took effect before the traversal
766 began, some legal expressions could have unexpected results.
767 An example is the expression
768 .Ic -print Cm -o Ic -depth .
771 always evaluates to true, the standard order of evaluation
774 would never be evaluated.
775 This is not the case.
786 Historic implementations of the
790 primaries did not replace the string
792 in the utility name or the
793 utility arguments if it had preceding or following non-whitespace characters.
794 This version replaces it no matter where in the utility name or arguments
799 option was implemented on the analogy of
804 The special characters used by
806 are also special characters to many shell programs.
807 In particular, the characters
818 may have to be escaped from the shell.
820 As there is no delimiter separating options and file names or file
823 it is difficult to specify files named
827 These problems are handled by the
836 primary does not interact well with other options that cause the filesystem
837 tree traversal options to be changed.