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