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