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
56 (composed of the ``primaries'' and ``operands'' listed below) in terms
57 of each file in the tree.
59 The options are as follows:
65 option causes the file information and file type (see
67 returned for each symbolic link specified on the command line to be
68 those of the file referenced by the link, not the link itself.
69 If the referenced file does not exist, the file information and type will
70 be for the link itself.
71 File information of all symbolic links not on
72 the command line is that of the link itself.
76 option causes the file information and file type (see
78 returned for each symbolic link to be those of the file referenced by the
79 link, not the link itself.
80 If the referenced file does not exist, the file information and type will
81 be for the link itself.
85 option causes the file information and file type (see
87 returned for each symbolic link to be those of the link itself.
92 option is a modification to permit
94 to be safely used in conjunction with
96 If a file name contains any of the delimiting characters used by
98 a diagnostic message is displayed on standard error, and the file
100 The delimiting characters include single (`` ' '') and double (`` " '')
101 quotes, backslash (``\e''), space, tab and newline characters.
107 to perform a depth\-first traversal, i.e. directories
108 are visited in post\-order and all entries in a directory will be acted
109 on before the directory itself.
112 visits directories in pre\-order, i.e. before their contents.
115 a breadth\-first traversal.
119 option specifies a file hierarchy for
122 File hierarchies may also be specified as the operands immediately
123 following the options.
129 to traverse the file hierarchies in lexicographical order,
130 i.e., alphabetical order within each directory.
137 may give different results.
143 from descending into directories that have a device number different
144 than that of the file from which the descent began.
149 True if the difference between the file last access time and the time
151 was started, rounded up to the next full minutes period, is
155 True if the difference between the file last access time and the time
157 was started, rounded up to the next full 24\-hour period, is
161 True if the difference between the time of last change of file status
162 information and the time
164 was started, rounded up to the next full minutes period, is
168 True if the difference between the time of last change of file status
169 information and the time
171 was started, rounded up to the next full 24\-hour period, is
175 Delete found files and/or directories.
178 from the current working directory as
180 recurses down the tree.
181 It will not attempt to delete a filename with a ``/''
182 character in its pathname relative to "." for security reasons.
183 Depth\-first traversal processing is implied by this option.
184 .It Ic -exec Ar utility Op argument ... ;
185 True if the program named
187 returns a zero value as its exit status.
188 Optional arguments may be passed to the utility.
189 The expression must be terminated by a semicolon (``;'').
190 If the string ``{}'' appears anywhere in the utility name or the
191 arguments it is replaced by the pathname of the current file.
193 will be executed from the directory from which
196 .It Ic -execdir Ar utility Op argument ... ;
199 primary is identical to the
201 primary with the exception that
203 will be executed from the directory that holds
205 The filename substituted for
206 the string ``{}'' is not qualified.
207 .It Ic -fstype Ar type
208 True if the file is contained in a file system of type
212 command can be used to find out the types of filesystems
213 that are available on the system:
214 .Bd -literal -offset indent
217 In addition, there are two pseudo-types, ``local'' and ``rdonly''.
218 The former matches any file system physically mounted on the system where
221 is being executed and the latter matches any file system which is
223 .It Ic -group Ar gname
224 True if the file belongs to the group
228 is numeric and there is no such group name, then
230 is treated as a group id.
232 True if the file has inode number
239 This primary always evaluates to true.
240 The following information for the current file is written to standard output:
241 its inode number, size in 512\-byte blocks, file permissions, number of hard
242 links, owner, group, size in bytes, last modification time, and pathname.
243 If the file is a block or character special file, the major and minor numbers
244 will be displayed instead of the size in bytes.
245 If the file is a symbolic link, the pathname of the linked\-to file will be
246 displayed preceded by ``\->''.
247 The format is identical to that produced by ``ls \-dgils''.
249 True if the difference between the file last modification time and the time
251 was started, rounded up to the next full minutes period, is
255 True if the difference between the file last modification time and the time
257 was started, rounded up to the next full 24\-hour period, is
260 .It Ic \&-ok Ar utility Op argument ... ;
263 primary is identical to the
265 primary with the exception that
267 requests user affirmation for the execution of the utility by printing
268 a message to the terminal and reading a response.
269 If the response is other than ``y'' the command is not executed and the
273 .It Ic -name Ar pattern
274 True if the last component of the pathname being examined matches
276 Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'')
277 may be used as part of
279 These characters may be matched explicitly by escaping them with a
281 .It Ic -newer Ar file
282 True if the current file has a more recent last modification time than
285 True if the file belongs to an unknown user.
287 True if the file belongs to an unknown group.
288 .It Ic -path Ar pattern
289 True if the pathname being examined matches
291 Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'')
292 may be used as part of
294 These characters may be matched explicitly by escaping them with a
296 Slashes (``/'') are treated as normal characters and do not have to be
305 may be either symbolic (see
308 If the mode is symbolic, a starting value of zero is assumed and the
309 mode sets or clears permissions without regard to the process' file mode
311 If the mode is octal, only bits 07777
323 of the file's mode bits participate
325 If the mode is preceded by a dash (``\-''), this primary evaluates to true
326 if at least all of the bits in the mode are set in the file's mode bits.
327 If the mode is not preceded by a dash, this primary evaluates to true if
328 the bits in the mode exactly match the file's mode bits.
329 Note, the first character of a symbolic mode may not be a dash (``\-'').
330 .It Ic -flags Op Fl Ns Ar flags
331 This primary evaluates to true if exactly those flags of the file are
332 set which are also set using the specified
334 (if these are not preceded by a dash (``\-''),
335 or if they match the specified flags (if these are preceded by a dash).
338 are specified using symbolic names (see
340 Note that this is different from
342 which only allows you to specify flags which are set.
344 This primary always evaluates to true.
345 It prints the pathname of the current file to standard output.
352 is specified, the given expression shall be effectively replaced by
353 .Cm \&( Ns Ar given\& expression Ns Cm \&)
356 This primary always evaluates to true.
357 It prints the pathname of the current file to standard output, followed by an
360 character (character code 0).
362 This primary always evaluates to true.
365 to not descend into the current file.
368 primary has no effect if the
370 option was specified.
371 .It Ic -size Ar n Ns Op Cm c
372 True if the file's size, rounded up, in 512\-byte blocks is
376 is followed by a ``c'', then the primary is true if the
381 True if the file is of the specified type.
382 Possible file types are as follows:
384 .Bl -tag -width flag -offset indent -compact
401 .It Ic -user Ar uname
402 True if the file belongs to the user
406 is numeric and there is no such user name, then
408 is treated as a user id.
411 All primaries which take a numeric argument allow the number to be
412 preceded by a plus sign (``+'') or a minus sign (``\-'').
413 A preceding plus sign means ``more than n'', a preceding minus sign means
414 ``less than n'' and neither means ``exactly n'' .
416 The primaries may be combined using the following operators.
417 The operators are listed in order of decreasing precedence.
418 .Bl -tag -width (expression)
419 .It Cm \&( Ar expression Cm \&)
420 This evaluates to true if the parenthesized expression evaluates to
423 .It Cm \&! Ar expression
427 It evaluates to true if the expression is false.
429 .It Ar expression Cm -and Ar expression
430 .It Ar expression expression
433 operator is the logical
436 As it is implied by the juxtaposition of two expressions it does not
437 have to be specified.
438 The expression evaluates to true if both expressions are true.
439 The second expression is not evaluated if the first expression is false.
441 .It Ar expression Cm -or Ar expression
444 operator is the logical
447 The expression evaluates to true if either the first or the second expression
449 The second expression is not evaluated if the first expression is true.
452 All operands and primaries must be separate arguments to
454 Primaries which themselves take arguments expect each argument
455 to be a separate argument to
459 The following examples are shown as given to the shell:
460 .Bl -tag -width findx
461 .It Li "find / \e! -name \*q*.c\*q -print"
462 Print out a list of all the files whose names do not end in ``.c''.
463 .It Li "find / -newer ttt -user wnj -print"
464 Print out a list of all the files owned by user ``wnj'' that are newer
465 than the file ``ttt''.
466 .It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
467 Print out a list of all the files which are not both newer than ``ttt''
468 and owned by ``wnj''.
469 .It Li "find / \e( -newer ttt -or -user wnj \e) -print"
470 Print out a list of all the files that are either owned by ``wnj'' or
471 that are newer than ``ttt''.
488 utility syntax is a superset of the syntax specified by the
492 All the single character options as well as the
498 primaries are extensions to
506 options were implemented using the primaries ``\-depth'', ``\-follow'',
508 These primaries always evaluated to true.
509 As they were really global variables that took effect before the traversal
510 began, some legal expressions could have unexpected results.
511 An example is the expression ``\-print \-o \-depth''.
512 As \-print always evaluates to true, the standard order of evaluation
513 implies that \-depth would never be evaluated.
514 This is not the case.
516 The operator ``-or'' was implemented as ``\-o'', and the operator ``-and''
517 was implemented as ``\-a''.
519 Historic implementations of the
523 primaries did not replace the string ``{}'' in the utility name or the
524 utility arguments if it had preceding or following non-whitespace characters.
525 This version replaces it no matter where in the utility name or arguments
528 The special characters used by
530 are also special characters to many shell programs.
531 In particular, the characters ``*'', ``['', ``]'', ``?'', ``('', ``)'',
532 ``!'', ``\e'' and ``;'' may have to be escaped from the shell.
534 As there is no delimiter separating options and file names or file
537 it is difficult to specify files named ``-xdev'' or ``!''.
538 These problems are handled by the
546 primary does not interact well with other options that cause the filesystem
547 tree traversal options to be changed.