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.4 (Berkeley) 4/1/94 36.\" $Id: find.1,v 1.3 1996/08/29 18:05:51 wosch Exp $ 37.\" 38.Dd April 1, 1994 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 . 168Currently supported types are ``local'', ``mfs'', ``nfs'', ``msdos'', 169``rdonly'' and ``ufs''. 170The types ``local'' and ``rdonly'' are not specific file system types. 171The former matches any file system physically mounted on the system where 172the 173.Nm find 174is being executed and the latter matches any file system which is 175mounted read-only. 176.It Ic -group Ar gname 177True if the file belongs to the group 178.Ar gname . 179If 180.Ar gname 181is numeric and there is no such group name, then 182.Ar gname 183is treated as a group id. 184.It Ic -inum Ar n 185True if the file has inode number 186.Ar n . 187.It Ic -links Ar n 188True if the file has 189.Ar n 190links. 191.It Ic -ls 192This primary always evaluates to true. 193The following information for the current file is written to standard output: 194its inode number, size in 512\-byte blocks, file permissions, number of hard 195links, owner, group, size in bytes, last modification time, and pathname. 196If the file is a block or character special file, the major and minor numbers 197will be displayed instead of the size in bytes. 198If the file is a symbolic link, the pathname of the linked\-to file will be 199displayed preceded by ``\->''. 200The format is identical to that produced by ``ls \-dgils''. 201.It Ic -mtime Ar n 202True if the difference between the file last modification time and the time 203.Nm find 204was started, rounded up to the next full 24\-hour period, is 205.Ar n 20624\-hour periods. 207.It Ic \&-ok Ar utility Ns Op argument ... ; 208The 209.Ic \&-ok 210primary is identical to the 211.Ic -exec 212primary with the exception that 213.Nm find 214requests user affirmation for the execution of the utility by printing 215a message to the terminal and reading a response. 216If the response is other than ``y'' the command is not executed and the 217value of the 218.Ar \&ok 219expression is false. 220.It Ic -name Ar pattern 221True if the last component of the pathname being examined matches 222.Ar pattern . 223Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'') 224may be used as part of 225.Ar pattern . 226These characters may be matched explicitly by escaping them with a 227backslash (``\e''). 228.It Ic -newer Ar file 229True if the current file has a more recent last modification time than 230.Ar file . 231.It Ic -nouser 232True if the file belongs to an unknown user. 233.It Ic -nogroup 234True if the file belongs to an unknown group. 235.It Ic -path Ar pattern 236True if the pathname being examined matches 237.Ar pattern . 238Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'') 239may be used as part of 240.Ar pattern . 241These characters may be matched explicitly by escaping them with a 242backslash (``\e''). 243Slashes (``/'') are treated as normal characters and do not have to be 244matched explicitly. 245.It Ic -perm Op Fl Ns Ar mode 246The 247.Ar mode 248may be either symbolic (see 249.Xr chmod 1 ) 250or an octal number. 251If the mode is symbolic, a starting value of zero is assumed and the 252mode sets or clears permissions without regard to the process' file mode 253creation mask. 254If the mode is octal, only bits 07777 255.Pf ( Dv S_ISUID 256| 257.Dv S_ISGID 258| 259.Dv S_ISTXT 260| 261.Dv S_IRWXU 262| 263.Dv S_IRWXG 264| 265.Dv S_IRWXO ) 266of the file's mode bits participate 267in the comparison. 268If the mode is preceded by a dash (``\-''), this primary evaluates to true 269if at least all of the bits in the mode are set in the file's mode bits. 270If the mode is not preceded by a dash, this primary evaluates to true if 271the bits in the mode exactly match the file's mode bits. 272Note, the first character of a symbolic mode may not be a dash (``\-''). 273.It Ic -print 274This primary always evaluates to true. 275It prints the pathname of the current file to standard output. 276The expression is appended to the user specified expression if none of 277.Ic -exec , 278.Ic -ls , 279.Ic -print0 , 280or 281.Ic \&-ok 282are specified. 283.It Ic -print0 284This primary always evaluates to true. 285It prints the pathname of the current file to standard output, followed by a 286.Tn ASCII 287.Tn NUL 288character (character code 0). 289.It Ic -prune 290This primary always evaluates to true. 291It causes 292.Nm find 293to not descend into the current file. 294Note, the 295.Ic -prune 296primary has no effect if the 297.Fl d 298option was specified. 299.It Ic -size Ar n Ns Op Cm c 300True if the file's size, rounded up, in 512\-byte blocks is 301.Ar n . 302If 303.Ar n 304is followed by a ``c'', then the primary is true if the 305file's size is 306.Ar n 307bytes. 308.It Ic -type Ar t 309True if the file is of the specified type. 310Possible file types are as follows: 311.Pp 312.Bl -tag -width flag -offset indent -compact 313.It Cm b 314block special 315.It Cm c 316character special 317.It Cm d 318directory 319.It Cm f 320regular file 321.It Cm l 322symbolic link 323.It Cm p 324FIFO 325.It Cm s 326socket 327.El 328.Pp 329.It Ic -user Ar uname 330True if the file belongs to the user 331.Ar uname . 332If 333.Ar uname 334is numeric and there is no such user name, then 335.Ar uname 336is treated as a user id. 337.El 338.Pp 339All primaries which take a numeric argument allow the number to be 340preceded by a plus sign (``+'') or a minus sign (``\-''). 341A preceding plus sign means ``more than n'', a preceding minus sign means 342``less than n'' and neither means ``exactly n'' . 343.Sh OPERATORS 344The primaries may be combined using the following operators. 345The operators are listed in order of decreasing precedence. 346.Bl -tag -width (expression) 347.It Cm \&( Ns Ar expression Ns Cm \&) 348This evaluates to true if the parenthesized expression evaluates to 349true. 350.Pp 351.It Cm \&! Ns Ar expression 352This is the unary 353.Tn NOT 354operator. 355It evaluates to true if the expression is false. 356.Pp 357.It Ar expression Cm -and Ar expression 358.It Ar expression expression 359The 360.Cm -and 361operator is the logical 362.Tn AND 363operator. 364As it is implied by the juxtaposition of two expressions it does not 365have to be specified. 366The expression evaluates to true if both expressions are true. 367The second expression is not evaluated if the first expression is false. 368.Pp 369.It Ar expression Cm -or Ar expression 370The 371.Cm -or 372operator is the logical 373.Tn OR 374operator. 375The expression evaluates to true if either the first or the second expression 376is true. 377The second expression is not evaluated if the first expression is true. 378.El 379.Pp 380All operands and primaries must be separate arguments to 381.Nm find . 382Primaries which themselves take arguments expect each argument 383to be a separate argument to 384.Nm find . 385.Sh EXAMPLES 386.Pp 387The following examples are shown as given to the shell: 388.Bl -tag -width findx 389.It Li "find / \e! -name \*q*.c\*q -print" 390Print out a list of all the files whose names do not end in ``.c''. 391.It Li "find / -newer ttt -user wnj -print" 392Print out a list of all the files owned by user ``wnj'' that are newer 393than the file ``ttt''. 394.It Li "find / \e! \e( -newer ttt -user wnj \e) -print" 395Print out a list of all the files which are not both newer than ``ttt'' 396and owned by ``wnj''. 397.It Li "find / \e( -newer ttt -or -user wnj \e) -print" 398Print out a list of all the files that are either owned by ``wnj'' or 399that are newer than ``ttt''. 400.El 401.Sh SEE ALSO 402.Xr chmod 1 , 403.Xr locate 1 , 404.Xr stat 2 , 405.Xr fts 3 , 406.Xr getgrent 3 , 407.Xr getpwent 3 , 408.Xr strmode 3 , 409.Xr symlink 7 410.Sh STANDARDS 411The 412.Nm find 413utility syntax is a superset of the syntax specified by the 414.St -p1003.2 415standard. 416.Pp 417The 418.Fl s 419and 420.Fl X 421options and the 422.Ic -inum , 423.Ic -print0 , 424.Ic -delete , 425and 426.Ic -ls 427primaries are extensions to 428.St -p1003.2 . 429.Pp 430Historically, the 431.Fl d , 432.Fl h 433and 434.Fl x 435options were implemented using the primaries ``\-depth'', ``\-follow'', 436and ``\-xdev''. 437These primaries always evaluated to true. 438As they were really global variables that took effect before the traversal 439began, some legal expressions could have unexpected results. 440An example is the expression ``\-print \-o \-depth''. 441As \-print always evaluates to true, the standard order of evaluation 442implies that \-depth would never be evaluated. 443This is not the case. 444.Pp 445The operator ``-or'' was implemented as ``\-o'', and the operator ``-and'' 446was implemented as ``\-a''. 447.Pp 448Historic implementations of the 449.Ic exec 450and 451.Ic ok 452primaries did not replace the string ``{}'' in the utility name or the 453utility arguments if it had preceding or following non-whitespace characters. 454This version replaces it no matter where in the utility name or arguments 455it appears. 456.Sh BUGS 457The special characters used by 458.Nm find 459are also special characters to many shell programs. 460In particular, the characters ``*'', ``['', ``]'', ``?'', ``('', ``)'', 461``!'', ``\e'' and ``;'' may have to be escaped from the shell. 462.Pp 463As there is no delimiter separating options and file names or file 464names and the 465.Ar expression , 466it is difficult to specify files named ``-xdev'' or ``!''. 467These problems are handled by the 468.Fl f 469option and the 470.Xr getopt 3 471``--'' construct. 472.Pp 473The 474.Ic -delete 475primary do not interact well with other options that cause the filesystem 476tree traversal options to be changed. 477.Sh HISTORY 478A 479.Nm 480command appeared in 481.At v1 . 482