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