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