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
35 .\" $FreeBSD: src/usr.bin/find/find.1,v 1.23.2.14 2001/12/14 15:53:30 ru Exp $
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
174 True if the difference between the file last access time and the time
176 was started, rounded up to the next full 24\-hour period, is
180 True if the difference between the time of last change of file status
181 information and the time
183 was started, rounded up to the next full minute, is
186 .It Ic -cnewer Ar file
190 True if the difference between the time of last change of file status
191 information and the time
193 was started, rounded up to the next full 24\-hour period, is
197 Delete found files and/or directories.
200 from the current working directory as
202 recurses down the tree.
203 It will not attempt to delete a filename with a
205 character in its pathname relative to
207 for security reasons.
208 Depth\-first traversal processing is implied by this option.
219 to process files that are contained in directories with unusual permissions.
220 It enures that you have write permission while you are placing files in a
221 directory, then sets the directory's permissions as the last thing.
223 True if the current file or directory is empty.
224 .It Ic -exec Ar utility Op Ar argument ... ;
225 True if the program named
227 returns a zero value as its exit status.
230 may be passed to the utility.
231 The expression must be terminated by a semicolon
235 appears anywhere in the utility name or the
236 arguments it is replaced by the pathname of the current file.
238 will be executed from the directory from which
244 are not subject to the further expansion of shell patterns
246 .It Ic -execdir Ar utility Op Ar argument ... ;
249 primary is identical to the
251 primary with the exception that
253 will be executed from the directory that holds
255 The filename substituted for
259 .It Ic -flags Oo Cm - Ns | Ns Cm + Oc Ns Ar flags , Ns Ar notflags
260 The flags are specified using symbolic names (see
270 are checked to be set, and flags in
272 are checked to be not set.
273 Note that this is different from
275 which only allows the user to specify mode bits that are set.
277 If flags are preceded by a dash
279 this primary evaluates to true
280 if at least all of the bits in
282 and none of the bits in
284 are set in the file's flags bits.
285 If flags are preceded by a plus
287 this primary evaluates to true
288 if any of the bits in
290 is set in the file's flags bits,
291 or any of the bits in
293 is not set in the file's flags bits.
295 this primary evaluates to true
298 exactly match the file's flags bits,
303 .It Ic -fstype Ar type
304 True if the file is contained in a file system of type
308 command can be used to find out the types of filesystems
309 that are available on the system:
313 In addition, there are two pseudo-types,
317 The former matches any file system physically mounted on the system where
320 is being executed and the latter matches any file system which is
322 .It Ic -group Ar gname
323 True if the file belongs to the group
327 is numeric and there is no such group name, then
329 is treated as a group ID.
330 .It Ic -iname Ar pattern
333 but the match is case insensitive.
335 True if the file has inode number
337 .It Ic -ipath Ar pattern
340 but the match is case insensitive.
341 .It Ic -iregex Ar pattern
344 but the match is case insensitive.
350 This primary always evaluates to true.
351 The following information for the current file is written to standard output:
352 its inode number, size in 512\-byte blocks, file permissions, number of hard
353 links, owner, group, size in bytes, last modification time, and pathname.
354 If the file is a block or character special file, the major and minor numbers
355 will be displayed instead of the size in bytes.
356 If the file is a symbolic link, the pathname of the linked\-to file will be
357 displayed preceded by
359 The format is identical to that produced by
363 .It Ic -maxdepth Ar n
364 True if the depth of the current file into the tree is less than or equal to
366 .It Ic -mindepth Ar n
367 True if the depth of the current file into the tree is greater than or equal to
370 True if the difference between the file last modification time and the time
372 was started, rounded up to the next full minute, is
375 .It Ic -mnewer Ar file
379 True if the difference between the file last modification time and the time
381 was started, rounded up to the next full 24\-hour period, is
384 .It Ic -name Ar pattern
385 True if the last component of the pathname being examined matches
387 Special shell pattern matching characters
393 may be used as part of
395 These characters may be matched explicitly by escaping them with a
398 .It Ic -newer Ar file
399 True if the current file has a more recent last modification time than
401 .It Ic -newer Ns Ar X Ns Ar Y Ar file
402 True if the current file has a more recent last access time
403 .Ar ( X Ns = Ns Cm a ) ,
405 .Ar ( X Ns = Ns Cm c ) ,
407 .Ar ( X Ns = Ns Cm m )
408 than the last access time
409 .Ar ( Y Ns = Ns Cm a ) ,
411 .Ar ( Y Ns = Ns Cm c ) ,
413 .Ar ( Y Ns = Ns Cm m )
420 is instead interpreted as a direct date specification of the form
428 True if the file belongs to an unknown group.
430 True if the file belongs to an unknown user.
431 .It Ic -ok Ar utility Op Ar argument ... ;
434 primary is identical to the
436 primary with the exception that
438 requests user affirmation for the execution of the
441 a message to the terminal and reading a response.
442 If the response is other than
444 the command is not executed and the
448 .It Ic -okdir Ar utility Op Ar argument ... ;
451 primary is identical to the
453 primary with the same exception as described for the
456 .It Ic -path Ar pattern
457 True if the pathname being examined matches
459 Special shell pattern matching characters
465 may be used as part of
467 These characters may be matched explicitly by escaping them with a
472 are treated as normal characters and do not have to be
474 .It Ic -perm Oo Cm - Ns | Ns Cm + Oc Ns Ar mode
477 may be either symbolic (see
482 is symbolic, a starting value of zero is assumed and the
484 sets or clears permissions without regard to the process' file mode
488 is octal, only bits 07777
489 .Pq Dv S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO
490 of the file's mode bits participate
494 is preceded by a dash
496 this primary evaluates to true
497 if at least all of the bits in the
499 are set in the file's mode bits.
502 is preceded by a plus
504 this primary evaluates to true
505 if any of the bits in the
507 are set in the file's mode bits.
508 Otherwise, this primary evaluates to true if
511 exactly match the file's mode bits.
512 Note, the first character of a symbolic mode may not be a dash
515 This primary always evaluates to true.
516 It prints the pathname of the current file to standard output.
518 .Ic -exec , -ls , -print0 ,
521 is specified, the given expression shall be effectively replaced by
522 .Cm \&( Ar "given expression" Cm \&) Ic -print .
524 This primary always evaluates to true.
525 It prints the pathname of the current file to standard output, followed by an
527 character (character code 0).
529 This primary always evaluates to true.
532 to not descend into the current file.
535 primary has no effect if the
537 option was specified.
538 .It Ic -regex Ar pattern
539 True if the whole path of the file matches
541 using regular expression.
542 To match a file named
544 you can use the regular expression
552 .It Ic -size Ar n Ns Op Cm c
553 True if the file's size, rounded up, in 512\-byte blocks is
559 then the primary is true if the
564 True if the file is of the specified type.
565 Possible file types are as follows:
567 .Bl -tag -width indent -compact
583 .It Ic -user Ar uname
584 True if the file belongs to the user
588 is numeric and there is no such user name, then
590 is treated as a user ID.
593 All primaries which take a numeric argument allow the number to be
594 preceded by a plus sign
598 A preceding plus sign means
600 a preceding minus sign means
605 The primaries may be combined using the following operators.
606 The operators are listed in order of decreasing precedence.
608 .Bl -tag -width "( expression )" -compact
609 .It Cm \&( Ar expression Cm \&)
610 This evaluates to true if the parenthesized expression evaluates to
613 .It Cm \&! Ar expression
614 .It Cm -false Ar expression
615 .It Cm -not Ar expression
619 It evaluates to true if the expression is false.
621 .It Ar expression Cm -and Ar expression
622 .It Ar expression expression
625 operator is the logical
628 As it is implied by the juxtaposition of two expressions it does not
629 have to be specified.
630 The expression evaluates to true if both expressions are true.
631 The second expression is not evaluated if the first expression is false.
633 .It Ar expression Cm -or Ar expression
636 operator is the logical
639 The expression evaluates to true if either the first or the second expression
641 The second expression is not evaluated if the first expression is true.
644 All operands and primaries must be separate arguments to
646 Primaries which themselves take arguments expect each argument
647 to be a separate argument to
650 The following examples are shown as given to the shell:
651 .Bl -tag -width indent
652 .It Li "find / \e! -name \*q*.c\*q -print"
653 Print out a list of all the files whose names do not end in
655 .It Li "find / -newer ttt -user wnj -print"
656 Print out a list of all the files owned by user
661 .It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
662 Print out a list of all the files which are not both newer than
666 .It Li "find / \e( -newer ttt -or -user wnj \e) -print"
667 Print out a list of all the files that are either owned by
669 or that are newer than
671 .It Li "find . -newerct '1 minute ago' -print"
672 Print out a list of all the files whose inode change time is more
673 recent than the current time minus one minute.
692 utility syntax is a superset of the syntax specified by the
696 All the single character options as well as the
697 .Ic -iname , -inum , -iregex , -print0 , -delete , -ls ,
700 primaries are extensions to
707 options were implemented using the primaries
708 .Ic -depth , -follow ,
711 These primaries always evaluated to true.
712 As they were really global variables that took effect before the traversal
713 began, some legal expressions could have unexpected results.
714 An example is the expression
715 .Ic -print Cm -o Ic -depth .
718 always evaluates to true, the standard order of evaluation
721 would never be evaluated.
722 This is not the case.
733 Historic implementations of the
737 primaries did not replace the string
739 in the utility name or the
740 utility arguments if it had preceding or following non-whitespace characters.
741 This version replaces it no matter where in the utility name or arguments
746 option was implemented on the analogy of
751 The special characters used by
753 are also special characters to many shell programs.
754 In particular, the characters
765 may have to be escaped from the shell.
767 As there is no delimiter separating options and file names or file
770 it is difficult to specify files named
774 These problems are handled by the
783 primary does not interact well with other options that cause the filesystem
784 tree traversal options to be changed.