Commit | Line | Data |
---|---|---|
45fc66f9 KB |
1 | .\" Copyright (c) 1990 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3559318a | 3 | .\" |
45fc66f9 KB |
4 | .\" %sccs.include.redist.man% |
5 | .\" | |
5325ced3 | 6 | .\" @(#)find.1 6.15 (Berkeley) %G% |
910ee6b3 | 7 | .\" |
b5dc1377 CL |
8 | .Dd |
9 | .Dt FIND 1 | |
dd9e2e8d | 10 | .Os BSD 4.4 |
b5dc1377 CL |
11 | .Sh NAME |
12 | .Nm find | |
13 | .Nd walk a file hierarchy | |
14 | .Sh SYNOPSIS | |
15 | .Nm find | |
16 | .Op Fl dsx | |
17 | .Op Ar path | |
18 | .Ar expression | |
19 | .Nm find | |
20 | .Op Fl dsx | |
21 | .Op Fl f Ar path | |
22 | .Ar expression | |
23 | .Sh DESCRIPTION | |
24 | .Nm Find | |
45fc66f9 | 25 | recursively descends the directory tree for each |
b5dc1377 | 26 | .Ar path |
ae3aaa1b | 27 | listed, evaluating an |
b5dc1377 | 28 | .Ar expression |
ae3aaa1b KB |
29 | (composed of the ``primaries'' and ``operands'' listed below) in terms |
30 | of each file in the tree. | |
b5dc1377 | 31 | .Pp |
202dd4ce | 32 | The options are as follows: |
b5dc1377 CL |
33 | .Pp |
34 | .Tw Ds | |
35 | .Tp Fl d | |
202dd4ce | 36 | The |
b5dc1377 | 37 | .Fl d |
202dd4ce KB |
38 | option causes find to perform a depth\-first traversal, i.e. directories |
39 | are visited in post\-order and all entries in a directory will be acted | |
40 | on before the directory itself. | |
41 | By default, | |
b5dc1377 | 42 | .Nm find |
202dd4ce KB |
43 | visits directories in pre\-order, i.e. before their contents. |
44 | Note, the default is | |
b5dc1377 | 45 | .Ar not |
202dd4ce | 46 | a breadth\-first traversal. |
b5dc1377 | 47 | .Tp Fl f |
202dd4ce | 48 | The |
b5dc1377 | 49 | .Fl f |
202dd4ce | 50 | option specifies a file hierarchy for |
b5dc1377 | 51 | .Nm find |
202dd4ce KB |
52 | to traverse. |
53 | If no | |
b5dc1377 | 54 | .Fl f |
202dd4ce | 55 | option is specified, the first operand after the options is |
ae3aaa1b | 56 | expected to be the file hierarchy to be traversed. |
b5dc1377 | 57 | .Tp Fl s |
202dd4ce | 58 | The |
b5dc1377 | 59 | .Fl s |
202dd4ce | 60 | option causes the file information and file type (see |
b5dc1377 | 61 | .Xr stat 2 ) , |
202dd4ce KB |
62 | returned for each symbolic link to be those of the file referenced by the |
63 | link, not the link itself. | |
64 | If the referenced file does not exist, the file information and type will | |
65 | be for the link itself. | |
b5dc1377 | 66 | .Tp Fl x |
202dd4ce | 67 | The |
b5dc1377 | 68 | .Fl x |
ae3aaa1b | 69 | option prevents |
b5dc1377 | 70 | .Nm find |
ae3aaa1b KB |
71 | from descending into directories that have a device number different |
72 | than that of the file from which the descent began. | |
b5dc1377 CL |
73 | .Tp |
74 | .Sh PRIMARIES | |
75 | .Tw Ds | |
76 | .Tp Cx Ic atime | |
77 | .Cx \&\ \& | |
78 | .Ar n | |
79 | .Cx | |
45fc66f9 | 80 | True if the difference between the file last access time and the time |
b5dc1377 | 81 | .Nm find |
45fc66f9 | 82 | was started, rounded up to the next full 24\-hour period, is |
b5dc1377 | 83 | .Ar n |
45fc66f9 | 84 | 24\-hour periods. |
b5dc1377 CL |
85 | .Tp Cx Ic ctime |
86 | .Cx \&\ \& | |
87 | .Ar n | |
88 | .Cx | |
45fc66f9 KB |
89 | True if the difference between the time of last change of file status |
90 | information and the time | |
b5dc1377 | 91 | .Nm find |
45fc66f9 | 92 | was started, rounded up to the next full 24\-hour period, is |
b5dc1377 | 93 | .Ar n |
45fc66f9 | 94 | 24\-hour periods. |
b5dc1377 CL |
95 | .Tp Cx Ic exec |
96 | .Cx \&\ \& | |
97 | .Ar utility | |
98 | .Cx \&\ \& | |
99 | .Op argument ... ; | |
100 | .Cx | |
45fc66f9 | 101 | True if the program named |
b5dc1377 | 102 | .Ar utility |
45fc66f9 KB |
103 | returns a zero value as its exit status. |
104 | Optional arguments may be passed to the utility. | |
105 | The expression must be terminated by a semicolon (``;''). | |
202dd4ce KB |
106 | If the string ``{}'' appears anywhere in the utility name or the |
107 | arguments it is replaced by the pathname of the current file. | |
45fc66f9 | 108 | Utility will be executed in the directory from which |
b5dc1377 | 109 | .Nm find |
45fc66f9 | 110 | was executed. |
b5dc1377 CL |
111 | .Tp Cx Ic fstype |
112 | .Cx \&\ \& | |
113 | .Ar type | |
114 | .Cx | |
45fc66f9 | 115 | True if the file is contained in a file system of type |
b5dc1377 | 116 | .Ar type . |
af67ecdf KB |
117 | Currently supported types are ``local'', ``mfs'', ``nfs'', ``pc'' and |
118 | ``ufs''. | |
119 | The type ``local'' is not a specific file system type, but matches | |
120 | any file system physically mounted on the system where the | |
b5dc1377 | 121 | .Nm find |
af67ecdf | 122 | is being executed. |
b5dc1377 CL |
123 | .Tp Cx Ic group |
124 | .Cx \&\ \& | |
125 | .Ar gname | |
126 | .Cx | |
45fc66f9 | 127 | True if the file belongs to the group |
b5dc1377 | 128 | .Ar gname . |
910ee6b3 | 129 | If |
b5dc1377 | 130 | .Ar gname |
45fc66f9 | 131 | is numeric and there is no such group name, then |
b5dc1377 | 132 | .Ar gname |
45fc66f9 | 133 | is treated as a group id. |
b5dc1377 CL |
134 | .Tp Cx Ic inum |
135 | .Cx \&\ \& | |
136 | .Ar n | |
137 | .Cx | |
45fc66f9 | 138 | True if the file has inode number |
b5dc1377 CL |
139 | .Ar n . |
140 | .Tp Cx Ic links | |
141 | .Cx \&\ \& | |
142 | .Ar n | |
143 | .Cx | |
910ee6b3 | 144 | True if the file has |
b5dc1377 | 145 | .Ar n |
910ee6b3 | 146 | links. |
b5dc1377 | 147 | .Tp Ic ls |
45fc66f9 KB |
148 | This primary always evaluates to true. |
149 | The following information for the current file is written to standard output: | |
150 | its inode number, size in 512\-byte blocks, file permissions, number of hard | |
151 | links, owner, group, size in bytes, last modification time, and pathname. | |
152 | If the file is a block or character special file, the major and minor numbers | |
153 | will be displayed instead of the size in bytes. | |
154 | If the file is a symbolic link, the pathname of the linked\-to file will be | |
155 | displayed preceded by ``\->''. | |
156 | The format is identical to that produced by ``ls \-dgils''. | |
b5dc1377 CL |
157 | .Tp Cx Ic mtime |
158 | .Cx \&\ \& | |
159 | .Ar n | |
160 | .Cx | |
45fc66f9 | 161 | True if the difference between the file last modification time and the time |
b5dc1377 | 162 | .Nm find |
45fc66f9 | 163 | was started, rounded up to the next full 24\-hour period, is |
b5dc1377 | 164 | .Ar n |
45fc66f9 | 165 | 24\-hour periods. |
5325ced3 | 166 | .Tp Cx Ic \&ok |
b5dc1377 CL |
167 | .Cx \&\ \& |
168 | .Ar utility | |
5325ced3 | 169 | .Ws |
b5dc1377 | 170 | .Op argument ... ; |
5325ced3 | 171 | .Cx |
45fc66f9 | 172 | The |
5325ced3 | 173 | .Ic \&ok |
45fc66f9 | 174 | primary is identical to the |
b5dc1377 | 175 | .Ic exec |
45fc66f9 | 176 | primary with the exception that |
b5dc1377 | 177 | .Nm find |
45fc66f9 KB |
178 | requests user affirmation for the execution of the utility by printing |
179 | a message to the terminal and reading a response. | |
180 | If the response is other than ``y'' the command is not executed and the | |
181 | value of the | |
5325ced3 | 182 | .Ar \&ok |
45fc66f9 | 183 | expression is false. |
b5dc1377 CL |
184 | .Tp Cx Ic name |
185 | .Cx \&\ \& | |
186 | .Ar pattern | |
187 | .Cx | |
45fc66f9 | 188 | True if the last component of the pathname being examined matches |
b5dc1377 | 189 | .Ar pattern . |
45fc66f9 KB |
190 | Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'') |
191 | may be used as part of | |
b5dc1377 | 192 | .Ar pattern . |
202dd4ce KB |
193 | These characters may be matched explicitly by escaping them with a |
194 | backslash (``\e''). | |
b5dc1377 CL |
195 | .Tp Cx Ic newer |
196 | .Cx \&\ \& | |
197 | .Ar file | |
198 | .Cx | |
45fc66f9 | 199 | True if the current file has a more recent last modification time than |
b5dc1377 CL |
200 | .Ar file . |
201 | .Tp Ic nouser | |
45fc66f9 | 202 | True if the file belongs to an unknown user. |
b5dc1377 | 203 | .Tp Ic nogroup |
45fc66f9 | 204 | True if the file belongs to an unknown group. |
b5dc1377 CL |
205 | .Tp Cx Ic perm |
206 | .Cx \&\ \& | |
207 | .Op Fl | |
208 | .Ar mode | |
209 | .Cx | |
45fc66f9 | 210 | The |
b5dc1377 | 211 | .Ar mode |
45fc66f9 | 212 | may be either symbolic (see |
b5dc1377 | 213 | .Xr chmod 1 ) |
45fc66f9 KB |
214 | or an octal number. |
215 | If the mode is symbolic, a starting value of zero is assumed and the | |
216 | mode sets or clears permissions without regard to the process' file mode | |
217 | creation mask. | |
218 | If the mode is octal, only bits 07777 of the file's mode bits participate | |
219 | in the comparison. | |
220 | If the mode is preceded by a dash (``\-''), this primary evaluates to true | |
221 | if at least all of the bits in the mode are set in the file's mode bits. | |
222 | If the mode is not preceded by a dash, this primary evaluates to true if | |
223 | the bits in the mode exactly match the file's mode bits. | |
224 | Note, the first character of a symbolic mode may not be a dash (``\-''). | |
b5dc1377 | 225 | .Tp Ic print |
45fc66f9 KB |
226 | This primary always evaluates to true. |
227 | It prints the pathname of the current file to standard output. | |
228 | The expression is appended to the user specified expression if neither | |
b5dc1377 CL |
229 | .Ic exec , |
230 | .Ic ls , | |
45fc66f9 | 231 | or |
5325ced3 | 232 | .Ic \&ok |
45fc66f9 | 233 | is specified. |
b5dc1377 | 234 | .Tp Ic prune |
45fc66f9 KB |
235 | This primary always evaluates to true. |
236 | It causes | |
b5dc1377 | 237 | .Nm find |
45fc66f9 | 238 | to not descend into the current file. |
b5dc1377 CL |
239 | .Tp Cx Ic size |
240 | .Cx \&\ \& | |
241 | .Ar n | |
242 | .Op Cm c | |
243 | .Cx | |
45fc66f9 | 244 | True if the file's size, rounded up, in 512\-byte blocks is |
b5dc1377 CL |
245 | .Ar n . |
246 | If | |
247 | .Ar n | |
45fc66f9 | 248 | is followed by a ``c'', then the primary is true if the |
b5dc1377 CL |
249 | file's size is |
250 | .Ar n | |
45fc66f9 | 251 | bytes. |
b5dc1377 CL |
252 | .Tp Cx Ic type |
253 | .Cx \&\ \& | |
254 | .Ar t | |
255 | .Cx | |
45fc66f9 KB |
256 | True if the file is of the specified type. |
257 | Possible file types are as follows: | |
b5dc1377 | 258 | .Pp |
5325ced3 | 259 | .Df I |
b5dc1377 CL |
260 | .Tw Ds |
261 | .Tp Cm b | |
45fc66f9 | 262 | block special |
b5dc1377 | 263 | .Tp Cm c |
45fc66f9 | 264 | character special |
b5dc1377 | 265 | .Tp Cm d |
45fc66f9 | 266 | directory |
b5dc1377 | 267 | .Tp Cm f |
45fc66f9 | 268 | regular file |
b5dc1377 | 269 | .Tp Cm l |
45fc66f9 | 270 | symbolic link |
b5dc1377 | 271 | .Tp Cm p |
45fc66f9 | 272 | FIFO |
b5dc1377 | 273 | .Tp Cm s |
45fc66f9 | 274 | socket |
b5dc1377 | 275 | .Tp |
5325ced3 | 276 | .De |
b5dc1377 CL |
277 | .Pp |
278 | .Tp Cx Ic user | |
279 | .Cx \&\ \& | |
280 | .Ar uname | |
281 | .Cx | |
45fc66f9 | 282 | True if the file belongs to the user |
b5dc1377 | 283 | .Ar uname . |
45fc66f9 | 284 | If |
b5dc1377 | 285 | .Ar uname |
45fc66f9 | 286 | is numeric and there is no such user name, then |
b5dc1377 | 287 | .Ar uname |
45fc66f9 | 288 | is treated as a user id. |
b5dc1377 CL |
289 | .Tp |
290 | .Pp | |
ae3aaa1b KB |
291 | All primaries which take a numeric argument allow the number to be |
292 | preceded by a plus sign (``+'') or a minus sign (``\-''). | |
293 | A preceding plus sign means ``more than | |
b5dc1377 | 294 | .Ar n ' ' , |
ae3aaa1b | 295 | a preceding minus sign means ``less than |
b5dc1377 | 296 | .Ar n ' ' |
ae3aaa1b | 297 | and neither means ``exactly |
b5dc1377 CL |
298 | .Ar n ' ' . |
299 | .Sh OPERATORS | |
45fc66f9 KB |
300 | The primaries may be combined using the following operators. |
301 | The operators are listed in order of decreasing precedence. | |
b5dc1377 CL |
302 | .Di L |
303 | .Dp Cx Ic \&( | |
304 | .Ar expression | |
305 | .Cx \&) | |
306 | .Cx | |
45fc66f9 KB |
307 | This evaluates to true if the parenthesized expression evaluates to |
308 | true. | |
b5dc1377 CL |
309 | .Pp |
310 | .Dp Cx Ic \&! | |
311 | .Cx \&\ \& | |
312 | .Ar expression | |
313 | .Cx | |
45fc66f9 KB |
314 | This is the unary NOT operator. |
315 | It evaluates to true if the expression is false. | |
b5dc1377 CL |
316 | .Pp |
317 | .Dp Cx Ar expression | |
318 | .Cx \&\ \& | |
319 | .Ic and | |
320 | .Cx \&\ \& | |
321 | .Ar expression | |
322 | .Cx | |
323 | .Dp Cx Ar expression expression | |
324 | .Cx | |
45fc66f9 | 325 | The |
b5dc1377 | 326 | .Ic and |
45fc66f9 KB |
327 | operator is the logical AND operator. |
328 | As it is implied by the juxtaposition of two expressions it does not | |
329 | have to be specified. | |
330 | The expression evaluates to true if both expressions are true. | |
331 | The second expression is not evaluated if the first expression is false. | |
b5dc1377 CL |
332 | .Pp |
333 | .Dp Cx Ar expression | |
334 | .Cx \&\ \& | |
335 | .Ic or | |
336 | .Cx \&\ \& | |
337 | .Ar expression | |
338 | .Cx | |
45fc66f9 | 339 | The |
b5dc1377 | 340 | .Ic or |
45fc66f9 KB |
341 | operator is the logical OR operator. |
342 | The expression evaluates to true if either the first or the second expression | |
343 | is true. | |
344 | The second expression is not evaluated if the first expression is true. | |
b5dc1377 CL |
345 | .Dp |
346 | .Pp | |
ae3aaa1b | 347 | All operands and primaries must be separate arguments to |
b5dc1377 | 348 | .Nm find . |
ae3aaa1b KB |
349 | Primaries which themselves take arguments expect each argument |
350 | to be a separate argument to | |
b5dc1377 CL |
351 | .Nm find . |
352 | .Sh EXAMPLES | |
353 | .Pp | |
45fc66f9 | 354 | The following examples are shown as given to the shell: |
b5dc1377 CL |
355 | .Tw findx |
356 | .Tp Li find / \e! name "*.c" print | |
45fc66f9 | 357 | Print out a list of all the files whose names do not end in ``.c''. |
b5dc1377 | 358 | .Tp Li find / newer ttt user wnj print |
45fc66f9 KB |
359 | Print out a list of all the files owned by user ``wnj'' that are newer |
360 | than the file ``ttt''. | |
b5dc1377 | 361 | .Tp Li find / \e! \e( newer ttt user wnj \e) print |
45fc66f9 KB |
362 | Print out a list of all the files which are not both newer than ``ttt'' |
363 | and owned by ``wnj''. | |
b5dc1377 | 364 | .Tp Li find / \e( newer ttt or user wnj \e) print |
45fc66f9 KB |
365 | Print out a list of all the files that are either owned by ``wnj'' or |
366 | that are newer than ``ttt''. | |
b5dc1377 CL |
367 | .Tp |
368 | .Sh SEE ALSO | |
369 | .Xr chmod 1 , | |
370 | .Xr sh 1 , | |
371 | .Xr test 1 , | |
372 | .Xr stat 2 , | |
373 | .Xr umask 2 , | |
374 | .Xr getpwent 3 , | |
375 | .Xr getgrent 3 , | |
376 | .Xr strmode 3 | |
377 | .Sh STANDARDS | |
45fc66f9 | 378 | The |
b5dc1377 | 379 | .Nm find |
202dd4ce KB |
380 | utility syntax is a replacement for the syntax specified by the POSIX |
381 | 1003.2 standard. | |
382 | The standard syntax is also supported; see the COMPATIBILITY section | |
383 | below for details. | |
b5dc1377 | 384 | .Pp |
202dd4ce | 385 | The |
b5dc1377 | 386 | .Fl s |
202dd4ce | 387 | option as well as the primaries |
b5dc1377 | 388 | .Ic inum |
45fc66f9 | 389 | and |
b5dc1377 | 390 | .Ic ls |
202dd4ce | 391 | are extensions to the POSIX standard. |
b5dc1377 | 392 | .Sh COMPATIBILITY |
202dd4ce | 393 | The traditional, and standardized, syntax for |
b5dc1377 | 394 | .Nm find |
202dd4ce KB |
395 | is as follows. |
396 | All of the primaries are preceded by a dash (``\-''), i.e. the | |
397 | primary ``group'' is specified as ``\-group''. | |
398 | The | |
b5dc1377 CL |
399 | .Fl d , |
400 | .Fl s , | |
202dd4ce | 401 | and |
b5dc1377 | 402 | .Fl x |
202dd4ce KB |
403 | options are implemented using the primaries ``\-depth'', ``\-follow'', |
404 | and ``\-xdev''. | |
405 | These primaries always evaluate to true. | |
406 | The operator ``or'' is implemented as ``\-o'', and the operator | |
407 | ``and'' is implemented as ``\-a''. | |
408 | The set of file trees to be traversed are specified as the first operands | |
409 | to | |
b5dc1377 | 410 | .Nm find . |
202dd4ce KB |
411 | The first operand beginning with a dash (``\-''), exclamation point (``!'') |
412 | or left parenthesis (``('') is assumed to be the beginning of the expression | |
413 | and the end of the files to be traversed. | |
b5dc1377 | 414 | .Pp |
202dd4ce | 415 | The |
b5dc1377 | 416 | .Nm find |
202dd4ce KB |
417 | syntax was changed for two reasons. |
418 | The first is that the ``\-depth'', ``\-follow'' and ``\-xdev'' primaries | |
419 | are really global variables that take effect before the traversal begins. | |
420 | This causes some legal expressions to have unexpected results. | |
421 | An example is the expression ``\-print \-o \-depth''. | |
422 | As \-print always evaluates to true, the standard order of evaluation | |
423 | implies that \-depth would never be evaluated. | |
424 | This is not the case. | |
b5dc1377 | 425 | .Pp |
202dd4ce KB |
426 | The second reason is that traversing file trees with names beginning with |
427 | a dash, exclamation point or left parenthesis was impossible. | |
b5dc1377 | 428 | .Sh BUGS |
202dd4ce | 429 | The special characters used by |
b5dc1377 | 430 | .Nm find |
202dd4ce | 431 | are also special characters to many shell programs. |
45fc66f9 KB |
432 | In particular, the characters ``*'', ``['', ``]'', ``?'', ``('', ``)'', |
433 | ``!'', ``\e'' and ``;'' may have to be escaped from the shell. |