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