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.9 1997/05/19 16:33:26 eivind 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. 88This is the default. 89.It Fl X 90The 91.Fl X 92option is a modification to permit 93.Nm 94to be safely used in conjunction with 95.Xr xargs 1 . 96If a file name contains any of the delimiting characters used by 97.Xr xargs , 98a diagnostic message is displayed on standard error, and the file 99is skipped. 100The delimiting characters include single (`` ' '') and double (`` " '') 101quotes, backslash (``\e''), space, tab and newline characters. 102.It Fl d 103The 104.Fl d 105option causes 106.Nm find 107to perform a depth\-first traversal, i.e. directories 108are visited in post\-order and all entries in a directory will be acted 109on before the directory itself. 110By default, 111.Nm find 112visits directories in pre\-order, i.e. before their contents. 113Note, the default is 114.Ar not 115a breadth\-first traversal. 116.It Fl f 117The 118.Fl f 119option specifies a file hierarchy for 120.Nm find 121to traverse. 122File hierarchies may also be specified as the operands immediately 123following the options. 124.It Fl x 125The 126.Fl x 127option prevents 128.Nm find 129from descending into directories that have a device number different 130than that of the file from which the descent began. 131.El 132.Sh PRIMARIES 133.Bl -tag -width Ds 134.It Ic -atime Ar n 135True if the difference between the file last access time and the time 136.Nm find 137was started, rounded up to the next full 24\-hour period, is 138.Ar n 13924\-hour periods. 140.It Ic -ctime Ar n 141True if the difference between the time of last change of file status 142information and the time 143.Nm find 144was started, rounded up to the next full 24\-hour period, is 145.Ar n 14624\-hour periods. 147.It Ic -delete 148Delete found files and/or directories. Always returns True. This executes 149from the current working directory as 150.Nm 151recurses down the tree. It will not attempt to delete a filename with a ``/'' 152character in its pathname relative to "." for security reasons. 153Depth\-first traversal processing is implied by this option. 154.It Ic -exec Ar utility Op argument ... ; 155True if the program named 156.Ar utility 157returns a zero value as its exit status. 158Optional arguments may be passed to the utility. 159The expression must be terminated by a semicolon (``;''). 160If the string ``{}'' appears anywhere in the utility name or the 161arguments it is replaced by the pathname of the current file. 162.Ar Utility 163will be executed from the directory from which 164.Nm find 165was executed. 166.It Ic -fstype Ar type 167True if the file is contained in a file system of type 168.Ar type . 169The 170.Xr sysctl 8 171command can be used to find out the types of filesystems 172that are available on the system: 173.Bd -literal -offset indent 174sysctl vfs 175.Ed 176In addition, there are two pseudo-types, ``local'' and ``rdonly''. 177The former matches any file system physically mounted on the system where 178the 179.Nm find 180is being executed and the latter matches any file system which is 181mounted read-only. 182.It Ic -group Ar gname 183True if the file belongs to the group 184.Ar gname . 185If 186.Ar gname 187is numeric and there is no such group name, then 188.Ar gname 189is treated as a group id. 190.It Ic -inum Ar n 191True if the file has inode number 192.Ar n . 193.It Ic -links Ar n 194True if the file has 195.Ar n 196links. 197.It Ic -ls 198This primary always evaluates to true. 199The following information for the current file is written to standard output: 200its inode number, size in 512\-byte blocks, file permissions, number of hard 201links, owner, group, size in bytes, last modification time, and pathname. 202If the file is a block or character special file, the major and minor numbers 203will be displayed instead of the size in bytes. 204If the file is a symbolic link, the pathname of the linked\-to file will be 205displayed preceded by ``\->''. 206The format is identical to that produced by ``ls \-dgils''. 207.It Ic -mtime Ar n 208True if the difference between the file last modification time and the time 209.Nm find 210was started, rounded up to the next full 24\-hour period, is 211.Ar n 21224\-hour periods. 213.It Ic \&-ok Ar utility Op argument ... ; 214The 215.Ic \&-ok 216primary is identical to the 217.Ic -exec 218primary with the exception that 219.Nm find 220requests user affirmation for the execution of the utility by printing 221a message to the terminal and reading a response. 222If the response is other than ``y'' the command is not executed and the 223value of the 224.Ar \&ok 225expression is false. 226.It Ic -name Ar pattern 227True if the last component of the pathname being examined matches 228.Ar pattern . 229Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'') 230may be used as part of 231.Ar pattern . 232These characters may be matched explicitly by escaping them with a 233backslash (``\e''). 234.It Ic -newer Ar file 235True if the current file has a more recent last modification time than 236.Ar file . 237.It Ic -nouser 238True if the file belongs to an unknown user. 239.It Ic -nogroup 240True if the file belongs to an unknown group. 241.It Ic -path Ar pattern 242True if the pathname being examined matches 243.Ar pattern . 244Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'') 245may be used as part of 246.Ar pattern . 247These characters may be matched explicitly by escaping them with a 248backslash (``\e''). 249Slashes (``/'') are treated as normal characters and do not have to be 250matched explicitly. 251.It Ic -perm Op Fl Ns Ar mode 252The 253.Ar mode 254may be either symbolic (see 255.Xr chmod 1 ) 256or an octal number. 257If the mode is symbolic, a starting value of zero is assumed and the 258mode sets or clears permissions without regard to the process' file mode 259creation mask. 260If the mode is octal, only bits 07777 261.Pf ( Dv S_ISUID 262| 263.Dv S_ISGID 264| 265.Dv S_ISTXT 266| 267.Dv S_IRWXU 268| 269.Dv S_IRWXG 270| 271.Dv S_IRWXO ) 272of the file's mode bits participate 273in the comparison. 274If the mode is preceded by a dash (``\-''), this primary evaluates to true 275if at least all of the bits in the mode are set in the file's mode bits. 276If the mode is not preceded by a dash, this primary evaluates to true if 277the bits in the mode exactly match the file's mode bits. 278Note, the first character of a symbolic mode may not be a dash (``\-''). 279.It Ic -print 280This primary always evaluates to true. 281It prints the pathname of the current file to standard output. 282If none of 283.Ic -exec , 284.Ic -ls , 285.Ic -print0 , 286or 287.Ic \&-ok 288is specified, the given expression shall be effectively replaced by 289.Cm \&( Ns Ar given\& expression Ns Cm \&) 290.Ic -print . 291.It Ic -print0 292This primary always evaluates to true. 293It prints the pathname of the current file to standard output, followed by an 294.Tn ASCII 295.Tn NUL 296character (character code 0). 297.It Ic -prune 298This primary always evaluates to true. 299It causes 300.Nm find 301to not descend into the current file. 302Note, the 303.Ic -prune 304primary has no effect if the 305.Fl d 306option was specified. 307.It Ic -size Ar n Ns Op Cm c 308True if the file's size, rounded up, in 512\-byte blocks is 309.Ar n . 310If 311.Ar n 312is followed by a ``c'', then the primary is true if the 313file's size is 314.Ar n 315bytes. 316.It Ic -type Ar t 317True if the file is of the specified type. 318Possible file types are as follows: 319.Pp 320.Bl -tag -width flag -offset indent -compact 321.It Cm b 322block special 323.It Cm c 324character special 325.It Cm d 326directory 327.It Cm f 328regular file 329.It Cm l 330symbolic link 331.It Cm p 332FIFO 333.It Cm s 334socket 335.El 336.Pp 337.It Ic -user Ar uname 338True if the file belongs to the user 339.Ar uname . 340If 341.Ar uname 342is numeric and there is no such user name, then 343.Ar uname 344is treated as a user id. 345.El 346.Pp 347All primaries which take a numeric argument allow the number to be 348preceded by a plus sign (``+'') or a minus sign (``\-''). 349A preceding plus sign means ``more than n'', a preceding minus sign means 350``less than n'' and neither means ``exactly n'' . 351.Sh OPERATORS 352The primaries may be combined using the following operators. 353The operators are listed in order of decreasing precedence. 354.Bl -tag -width (expression) 355.It Cm \&( Ns Ar expression Ns Cm \&) 356This evaluates to true if the parenthesized expression evaluates to 357true. 358.Pp 359.It Cm \&! Ns Ar expression 360This is the unary 361.Tn NOT 362operator. 363It evaluates to true if the expression is false. 364.Pp 365.It Ar expression Cm -and Ar expression 366.It Ar expression expression 367The 368.Cm -and 369operator is the logical 370.Tn AND 371operator. 372As it is implied by the juxtaposition of two expressions it does not 373have to be specified. 374The expression evaluates to true if both expressions are true. 375The second expression is not evaluated if the first expression is false. 376.Pp 377.It Ar expression Cm -or Ar expression 378The 379.Cm -or 380operator is the logical 381.Tn OR 382operator. 383The expression evaluates to true if either the first or the second expression 384is true. 385The second expression is not evaluated if the first expression is true. 386.El 387.Pp 388All operands and primaries must be separate arguments to 389.Nm find . 390Primaries which themselves take arguments expect each argument 391to be a separate argument to 392.Nm find . 393.Sh EXAMPLES 394.Pp 395The following examples are shown as given to the shell: 396.Bl -tag -width findx 397.It Li "find / \e! -name \*q*.c\*q -print" 398Print out a list of all the files whose names do not end in ``.c''. 399.It Li "find / -newer ttt -user wnj -print" 400Print out a list of all the files owned by user ``wnj'' that are newer 401than the file ``ttt''. 402.It Li "find / \e! \e( -newer ttt -user wnj \e) -print" 403Print out a list of all the files which are not both newer than ``ttt'' 404and owned by ``wnj''. 405.It Li "find / \e( -newer ttt -or -user wnj \e) -print" 406Print out a list of all the files that are either owned by ``wnj'' or 407that are newer than ``ttt''. 408.El 409.Sh SEE ALSO 410.Xr chmod 1 , 411.Xr locate 1 , 412.Xr stat 2 , 413.Xr fts 3 , 414.Xr getgrent 3 , 415.Xr getpwent 3 , 416.Xr strmode 3 , 417.Xr symlink 7 418.Sh STANDARDS 419The 420.Nm find 421utility syntax is a superset of the syntax specified by the 422.St -p1003.2 423standard. 424.Pp 425The 426.Fl s 427and 428.Fl X 429options and the 430.Ic -inum , 431.Ic -print0 , 432.Ic -delete , 433and 434.Ic -ls 435primaries are extensions to 436.St -p1003.2 . 437.Pp 438Historically, the 439.Fl d , 440.Fl h 441and 442.Fl x 443options were implemented using the primaries ``\-depth'', ``\-follow'', 444and ``\-xdev''. 445These primaries always evaluated to true. 446As they were really global variables that took effect before the traversal 447began, some legal expressions could have unexpected results. 448An example is the expression ``\-print \-o \-depth''. 449As \-print always evaluates to true, the standard order of evaluation 450implies that \-depth would never be evaluated. 451This is not the case. 452.Pp 453The operator ``-or'' was implemented as ``\-o'', and the operator ``-and'' 454was implemented as ``\-a''. 455.Pp 456Historic implementations of the 457.Ic exec 458and 459.Ic ok 460primaries did not replace the string ``{}'' in the utility name or the 461utility arguments if it had preceding or following non-whitespace characters. 462This version replaces it no matter where in the utility name or arguments 463it appears. 464.Sh BUGS 465The special characters used by 466.Nm find 467are also special characters to many shell programs. 468In particular, the characters ``*'', ``['', ``]'', ``?'', ``('', ``)'', 469``!'', ``\e'' and ``;'' may have to be escaped from the shell. 470.Pp 471As there is no delimiter separating options and file names or file 472names and the 473.Ar expression , 474it is difficult to specify files named ``-xdev'' or ``!''. 475These problems are handled by the 476.Fl f 477option and the 478.Xr getopt 3 479``--'' construct. 480.Pp 481The 482.Ic -delete 483primary do not interact well with other options that cause the filesystem 484tree traversal options to be changed. 485.Sh HISTORY 486A 487.Nm 488command appeared in 489.At v1 . 490