]>
Commit | Line | Data |
---|---|---|
44bd5ea7 A |
1 | .\" $NetBSD: find.1,v 1.14 1998/05/27 13:15:30 msaitoh Exp $ |
2 | .\" | |
3 | .\" Copyright (c) 1990, 1993 | |
4 | .\" The Regents of the University of California. All rights reserved. | |
5 | .\" | |
6 | .\" This code is derived from software contributed to Berkeley by | |
7 | .\" the Institute of Electrical and Electronics Engineers, Inc. | |
8 | .\" | |
9 | .\" Redistribution and use in source and binary forms, with or without | |
10 | .\" modification, are permitted provided that the following conditions | |
11 | .\" are met: | |
12 | .\" 1. Redistributions of source code must retain the above copyright | |
13 | .\" notice, this list of conditions and the following disclaimer. | |
14 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
15 | .\" notice, this list of conditions and the following disclaimer in the | |
16 | .\" documentation and/or other materials provided with the distribution. | |
17 | .\" 3. All advertising materials mentioning features or use of this software | |
18 | .\" must display the following acknowledgement: | |
19 | .\" This product includes software developed by the University of | |
20 | .\" California, Berkeley and its contributors. | |
21 | .\" 4. Neither the name of the University nor the names of its contributors | |
22 | .\" may be used to endorse or promote products derived from this software | |
23 | .\" without specific prior written permission. | |
24 | .\" | |
25 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
26 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
27 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
28 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
29 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
30 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
31 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
32 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
33 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
34 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
35 | .\" SUCH DAMAGE. | |
36 | .\" | |
37 | .\" from: @(#)find.1 8.7 (Berkeley) 5/9/95 | |
38 | .\" | |
39 | .Dd May 9, 1995 | |
40 | .Dt FIND 1 | |
41 | .Os | |
42 | .Sh NAME | |
43 | .Nm find | |
44 | .Nd walk a file hierarchy | |
45 | .Sh SYNOPSIS | |
46 | .Nm find | |
47 | .Op Fl H | Fl L | Fl P | |
48 | .Op Fl Xdx | |
49 | .Op Fl f Ar file | |
50 | .Op Ar file ... | |
51 | .Ar expression | |
52 | .Sh DESCRIPTION | |
53 | .Nm | |
54 | recursively descends the directory tree for each | |
55 | .Ar file | |
56 | listed, evaluating an | |
57 | .Ar expression | |
58 | (composed of the ``primaries'' and ``operands'' listed below) in terms | |
59 | of each file in the tree. | |
60 | .Pp | |
61 | The options are as follows: | |
62 | .Pp | |
63 | .Bl -tag -width Ds | |
64 | .It Fl H | |
65 | The | |
66 | .Fl H | |
67 | option causes the file information and file type (see | |
68 | .Xr stat 2 ) , | |
69 | returned for each symbolic link encountered on the command line to be | |
70 | those of the file referenced by the link, not the link itself. | |
71 | If the referenced file does not exist, the file information and type will | |
72 | be for the link itself. File information of all symbolic links not on | |
73 | the command line is that of the link itself. | |
74 | .It Fl L | |
75 | The | |
76 | .Fl L | |
77 | option causes the file information and file type (see | |
78 | .Xr stat 2) | |
79 | returned for each symbolic link to be those of the file referenced by the | |
80 | link, not the link itself. | |
81 | If the referenced file does not exist, the file information and type will | |
82 | be for the link itself. | |
83 | .It Fl P | |
84 | The | |
85 | .Fl P | |
86 | option causes the file information and file type (see | |
87 | .Xr stat 2) | |
88 | returned for each symbolic link to be those of the link itself. | |
89 | .It Fl X | |
90 | The | |
91 | .Fl X | |
92 | option is a modification to permit | |
93 | .Nm | |
94 | to be safely used in conjunction with | |
95 | .Xr xargs 1 . | |
96 | If a file name contains any of the delimiting characters used by | |
97 | .Xr xargs , | |
98 | a diagnostic message is displayed on standard error, and the file | |
99 | is skipped. | |
100 | The delimiting characters include single (`` ' '') and double (`` " '') | |
101 | quotes, backslash (``\e''), space, tab and newline characters. | |
102 | .It Fl d | |
103 | The | |
104 | .Fl d | |
105 | option causes | |
106 | .Nm | |
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. | |
110 | By default, | |
111 | .Nm | |
112 | visits directories in pre\-order, i.e. before their contents. | |
113 | Note, the default is | |
114 | .Ar not | |
115 | a breadth\-first traversal. | |
116 | .It Fl f | |
117 | The | |
118 | .Fl f | |
119 | option specifies a file hierarchy for | |
120 | .Nm | |
121 | to traverse. | |
122 | File hierarchies may also be specified as the operands immediately | |
123 | following the options. | |
124 | .It Fl h | |
125 | The | |
126 | .Fl h | |
127 | option causes the file information and file type (see | |
128 | .Xr stat 2 ) , | |
129 | returned for each symbolic link to be those of the file referenced by the | |
130 | link, not the link itself. | |
131 | If the referenced file does not exist, the file information and type will | |
132 | be for the link itself. | |
133 | .It Fl x | |
134 | The | |
135 | .Fl x | |
136 | option prevents | |
137 | .Nm | |
138 | from descending into directories that have a device number different | |
139 | than that of the file from which the descent began. | |
140 | .El | |
141 | .Sh PRIMARIES | |
142 | .Bl -tag -width Ds | |
143 | .It Ic -atime Ar n | |
144 | True if the difference between the file last access time and the time | |
145 | .Nm | |
146 | was started, rounded up to the next full 24\-hour period, is | |
147 | .Ar n | |
148 | 24\-hour periods. | |
149 | .It Ic -ctime Ar n | |
150 | True if the difference between the time of last change of file status | |
151 | information and the time | |
152 | .Nm | |
153 | was started, rounded up to the next full 24\-hour period, is | |
154 | .Ar n | |
155 | 24\-hour periods. | |
156 | .It Ic -exec Ar utility Op argument ... ; | |
157 | True if the program named | |
158 | .Ar utility | |
159 | returns a zero value as its exit status. | |
160 | Optional arguments may be passed to the utility. | |
161 | The expression must be terminated by a semicolon (``;''). | |
162 | If the string ``{}'' appears anywhere in the utility name or the | |
163 | arguments it is replaced by the pathname of the current file. | |
164 | .Ar Utility | |
165 | will be executed from the directory from which | |
166 | .Nm | |
167 | was executed. | |
168 | .It Ic -follow | |
169 | Follow symbolic links. | |
170 | .It Ic -fstype Ar type | |
171 | True if the file is contained in a file system of type | |
172 | .Ar type . | |
173 | The | |
174 | .Xr sysctl 8 | |
175 | command can be used to find out the types of filesystems | |
176 | that are available on the system: | |
177 | .Bd -literal -offset indent | |
178 | sysctl vfs | |
179 | .Ed | |
180 | In addition, there are two pseudo-types, ``local'' and ``rdonly''. | |
181 | The former matches any file system physically mounted on the system where | |
182 | the | |
183 | .Nm | |
184 | is being executed, and the latter matches any file system which is | |
185 | mounted read-only. | |
186 | .It Ic -group Ar gname | |
187 | True if the file belongs to the group | |
188 | .Ar gname . | |
189 | If | |
190 | .Ar gname | |
191 | is numeric and there is no such group name, then | |
192 | .Ar gname | |
193 | is treated as a group id. | |
194 | .It Ic -inum Ar n | |
195 | True if the file has inode number | |
196 | .Ar n . | |
197 | .It Ic -links Ar n | |
198 | True if the file has | |
199 | .Ar n | |
200 | links. | |
201 | .It Ic -ls | |
202 | This primary always evaluates to true. | |
203 | The following information for the current file is written to standard output: | |
204 | its inode number, size in 512\-byte blocks, file permissions, number of hard | |
205 | links, owner, group, size in bytes, last modification time, and pathname. | |
206 | If the file is a block or character special file, the major and minor numbers | |
207 | will be displayed instead of the size in bytes. | |
208 | If the file is a symbolic link, the pathname of the linked\-to file will be | |
209 | displayed preceded by ``\->''. | |
210 | The format is identical to that produced by ``ls \-dgils''. | |
211 | .It Ic -mtime Ar n | |
212 | True if the difference between the file last modification time and the time | |
213 | .Nm | |
214 | was started, rounded up to the next full 24\-hour period, is | |
215 | .Ar n | |
216 | 24\-hour periods. | |
217 | .It Ic \&-ok Ar utility Op argument ... ; | |
218 | The | |
219 | .Ic \&-ok | |
220 | primary is identical to the | |
221 | .Ic -exec | |
222 | primary with the exception that | |
223 | .Nm | |
224 | requests user affirmation for the execution of the utility by printing | |
225 | a message to the terminal and reading a response. | |
226 | If the response is other than ``y'' the command is not executed and the | |
227 | value of the | |
228 | .Ar \&ok | |
229 | expression is false. | |
230 | .It Ic -name Ar pattern | |
231 | True if the last component of the pathname being examined matches | |
232 | .Ar pattern . | |
233 | Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'') | |
234 | may be used as part of | |
235 | .Ar pattern . | |
236 | These characters may be matched explicitly by escaping them with a | |
237 | backslash (``\e''). | |
238 | .It Ic -newer Ar file | |
239 | True if the current file has a more recent last modification time than | |
240 | .Ar file . | |
241 | .It Ic -nouser | |
242 | True if the file belongs to an unknown user. | |
243 | .It Ic -nogroup | |
244 | True if the file belongs to an unknown group. | |
245 | .It Ic -path Ar pattern | |
246 | True if the pathname being examined matches | |
247 | .Ar pattern . | |
248 | Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'') | |
249 | may be used as part of | |
250 | .Ar pattern . | |
251 | These characters may be matched explicitly by escaping them with a | |
252 | backslash (``\e''). | |
253 | Slashes (``/'') are treated as normal characters and do not have to be | |
254 | matched explicitly. | |
255 | .It Ic -perm Op Fl Ns Ar mode | |
256 | The | |
257 | .Ar mode | |
258 | may be either symbolic (see | |
259 | .Xr chmod 1 ) | |
260 | or an octal number. | |
261 | If the mode is symbolic, a starting value of zero is assumed and the | |
262 | mode sets or clears permissions without regard to the process' file mode | |
263 | creation mask. | |
264 | If the mode is octal, only bits 07777 | |
265 | .Pf ( Dv S_ISUID | |
266 | | | |
267 | .Dv S_ISGID | |
268 | | | |
269 | .Dv S_ISTXT | |
270 | | | |
271 | .Dv S_IRWXU | |
272 | | | |
273 | .Dv S_IRWXG | |
274 | | | |
275 | .Dv S_IRWXO ) | |
276 | of the file's mode bits participate | |
277 | in the comparison. | |
278 | If the mode is preceded by a dash (``\-''), this primary evaluates to true | |
279 | if at least all of the bits in the mode are set in the file's mode bits. | |
280 | If the mode is not preceded by a dash, this primary evaluates to true if | |
281 | the bits in the mode exactly match the file's mode bits. | |
282 | Note, the first character of a symbolic mode may not be a dash (``\-''). | |
283 | .It Ic -print | |
284 | This primary always evaluates to true. | |
285 | It prints the pathname of the current file to standard output, followed | |
286 | by a newline character. | |
287 | If none of | |
288 | .Ic -exec , | |
289 | .Ic -ls , | |
290 | .Ic -ok , | |
291 | nor | |
292 | .Ic -print0 | |
293 | is specified, the given expression shall be effectively replaced by | |
294 | .Cm \&( Ns Ar given\& expression Ns Cm \&) | |
295 | .Ic -print . | |
296 | .It Ic -print0 | |
297 | This primary always evaluates to true. | |
298 | It prints the pathname of the current file to standard output, followed | |
299 | by a null character. | |
300 | .It Ic -prune | |
301 | This primary always evaluates to true. | |
302 | It causes | |
303 | .Nm | |
304 | to not descend into the current file. | |
305 | Note, the | |
306 | .Ic -prune | |
307 | primary has no effect if the | |
308 | .Fl d | |
309 | option was specified. | |
310 | .It Ic -size Ar n Ns Op Cm c | |
311 | True if the file's size, rounded up, in 512\-byte blocks is | |
312 | .Ar n . | |
313 | If | |
314 | .Ar n | |
315 | is followed by a ``c'', then the primary is true if the | |
316 | file's size is | |
317 | .Ar n | |
318 | bytes. | |
319 | .It Ic -type Ar t | |
320 | True if the file is of the specified type. | |
321 | Possible file types are as follows: | |
322 | .Pp | |
323 | .Bl -tag -width flag -offset indent -compact | |
324 | .It Cm W | |
325 | whiteout | |
326 | .It Cm b | |
327 | block special | |
328 | .It Cm c | |
329 | character special | |
330 | .It Cm d | |
331 | directory | |
332 | .It Cm f | |
333 | regular file | |
334 | .It Cm l | |
335 | symbolic link | |
336 | .It Cm p | |
337 | FIFO | |
338 | .It Cm s | |
339 | socket | |
340 | .El | |
341 | .Pp | |
342 | .It Ic -user Ar uname | |
343 | True if the file belongs to the user | |
344 | .Ar uname . | |
345 | If | |
346 | .Ar uname | |
347 | is numeric and there is no such user name, then | |
348 | .Ar uname | |
349 | is treated as a user id. | |
350 | .El | |
351 | .Pp | |
352 | All primaries which take a numeric argument allow the number to be | |
353 | preceded by a plus sign (``+'') or a minus sign (``\-''). | |
354 | A preceding plus sign means ``more than n'', a preceding minus sign means | |
355 | ``less than n'' and neither means ``exactly n'' . | |
356 | .Sh OPERATORS | |
357 | The primaries may be combined using the following operators. | |
358 | The operators are listed in order of decreasing precedence. | |
359 | .Bl -tag -width (expression) | |
360 | .It Cm \&( Ns Ar expression Ns Cm \&) | |
361 | This evaluates to true if the parenthesized expression evaluates to | |
362 | true. | |
363 | .Pp | |
364 | .It Cm \&! Ns Ar expression | |
365 | This is the unary | |
366 | .Tn NOT | |
367 | operator. | |
368 | It evaluates to true if the expression is false. | |
369 | .Pp | |
370 | .It Ar expression Cm -and Ar expression | |
371 | .It Ar expression expression | |
372 | The | |
373 | .Cm -and | |
374 | operator is the logical | |
375 | .Tn AND | |
376 | operator. | |
377 | As it is implied by the juxtaposition of two expressions it does not | |
378 | have to be specified. | |
379 | The expression evaluates to true if both expressions are true. | |
380 | The second expression is not evaluated if the first expression is false. | |
381 | .Pp | |
382 | .It Ar expression Cm -or Ar expression | |
383 | The | |
384 | .Cm -or | |
385 | operator is the logical | |
386 | .Tn OR | |
387 | operator. | |
388 | The expression evaluates to true if either the first or the second expression | |
389 | is true. | |
390 | The second expression is not evaluated if the first expression is true. | |
391 | .El | |
392 | .Pp | |
393 | All operands and primaries must be separate arguments to | |
394 | .Nm "" . | |
395 | Primaries which themselves take arguments expect each argument | |
396 | to be a separate argument to | |
397 | .Nm "" . | |
398 | .Sh EXAMPLES | |
399 | .Pp | |
400 | The following examples are shown as given to the shell: | |
401 | .Bl -tag -width findx | |
402 | .It Li "find / \e! -name \*q*.c\*q -print" | |
403 | Print out a list of all the files whose names do not end in ``.c''. | |
404 | .It Li "find / -newer ttt -user wnj -print" | |
405 | Print out a list of all the files owned by user ``wnj'' that are newer | |
406 | than the file ``ttt''. | |
407 | .It Li "find / \e! \e( -newer ttt -user wnj \e) -print" | |
408 | Print out a list of all the files which are not both newer than ``ttt'' | |
409 | and owned by ``wnj''. | |
410 | .It Li "find / \e( -newer ttt -or -user wnj \e) -print" | |
411 | Print out a list of all the files that are either owned by ``wnj'' or | |
412 | that are newer than ``ttt''. | |
413 | .El | |
414 | .Sh SEE ALSO | |
415 | .Xr chmod 1 , | |
416 | .Xr locate 1 , | |
417 | .Xr stat 2 , | |
418 | .Xr fts 3 , | |
419 | .Xr getpwent 3 , | |
420 | .Xr getgrent 3 , | |
421 | .Xr strmode 3 , | |
422 | .Xr symlink 7 | |
423 | .Sh STANDARDS | |
424 | The | |
425 | .Nm | |
426 | utility syntax is a superset of the syntax specified by the | |
427 | .St -p1003.2 | |
428 | standard. | |
429 | .Pp | |
430 | The options and the | |
431 | .Ic -follow , | |
432 | .Ic -fstype , | |
433 | .Ic -inum , | |
434 | .Ic -links , | |
435 | .Ic -ls | |
436 | and | |
437 | .Ic -print0 | |
438 | primaries are extensions to | |
439 | .St -p1003.2 . | |
440 | .Pp | |
441 | Historically, the | |
442 | .Fl d , | |
443 | .Fl h | |
444 | and | |
445 | .Fl x | |
446 | options were implemented using the primaries ``\-depth'', ``\-follow'', | |
447 | and ``\-xdev''. | |
448 | These primaries always evaluated to true. | |
449 | As they were really global variables that took effect before the traversal | |
450 | began, some legal expressions could have unexpected results. | |
451 | An example is the expression ``\-print \-o \-depth''. | |
452 | As \-print always evaluates to true, the standard order of evaluation | |
453 | implies that \-depth would never be evaluated. | |
454 | This is not the case. | |
455 | .Pp | |
456 | The operator ``-or'' was implemented as ``\-o'', and the operator ``-and'' | |
457 | was implemented as ``\-a''. | |
458 | .Pp | |
459 | Historic implementations of the | |
460 | .Ic -exec | |
461 | and | |
462 | .Ic -ok | |
463 | primaries did not replace the string ``{}'' in the utility name or the | |
464 | utility arguments if it had preceding or following non-whitespace characters. | |
465 | This version replaces it no matter where in the utility name or arguments | |
466 | it appears. | |
467 | .Sh BUGS | |
468 | The special characters used by | |
469 | .Nm | |
470 | are also special characters to many shell programs. | |
471 | In particular, the characters ``*'', ``['', ``]'', ``?'', ``('', ``)'', | |
472 | ``!'', ``\e'' and ``;'' may have to be escaped from the shell. | |
473 | .Pp | |
474 | As there is no delimiter separating options and file names or file | |
475 | names and the | |
476 | .Ar expression , | |
477 | it is difficult to specify files named ``-xdev'' or ``!''. | |
478 | These problems are handled by the | |
479 | .Fl f | |
480 | option and the | |
481 | .Xr getopt 3 | |
482 | ``--'' construct. |