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