]> git.saurik.com Git - apple/shell_cmds.git/blame - find/find.1
shell_cmds-18.tar.gz
[apple/shell_cmds.git] / find / find.1
CommitLineData
44bd5ea7
A
1.\" $NetBSD: find.1,v 1.14 1998/05/27 13:15:30 msaitoh Exp $
2.\"
3.\" Copyright (c) 1990, 1993
4.\" The Regents of the University of California. All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" the Institute of Electrical and Electronics Engineers, Inc.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\" must display the following acknowledgement:
19.\" This product includes software developed by the University of
20.\" California, Berkeley and its contributors.
21.\" 4. Neither the name of the University nor the names of its contributors
22.\" may be used to endorse or promote products derived from this software
23.\" without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35.\" SUCH DAMAGE.
36.\"
37.\" from: @(#)find.1 8.7 (Berkeley) 5/9/95
38.\"
39.Dd May 9, 1995
40.Dt FIND 1
41.Os
42.Sh NAME
43.Nm find
44.Nd walk a file hierarchy
45.Sh SYNOPSIS
46.Nm find
47.Op Fl H | Fl L | Fl P
48.Op Fl Xdx
49.Op Fl f Ar file
50.Op Ar file ...
51.Ar expression
52.Sh DESCRIPTION
53.Nm
54recursively descends the directory tree for each
55.Ar file
56listed, evaluating an
57.Ar expression
58(composed of the ``primaries'' and ``operands'' listed below) in terms
59of each file in the tree.
60.Pp
61The options are as follows:
62.Pp
63.Bl -tag -width Ds
64.It Fl H
65The
66.Fl H
67option causes the file information and file type (see
68.Xr stat 2 ) ,
69returned for each symbolic link encountered on the command line to be
70those of the file referenced by the link, not the link itself.
71If the referenced file does not exist, the file information and type will
72be for the link itself. File 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.
89.It Fl X
90The
91.Fl X
92option is a modification to permit
93.Nm
94to be safely used in conjunction with
95.Xr xargs 1 .
96If a file name contains any of the delimiting characters used by
97.Xr xargs ,
98a diagnostic message is displayed on standard error, and the file
99is skipped.
100The delimiting characters include single (`` ' '') and double (`` " '')
101quotes, backslash (``\e''), space, tab and newline characters.
102.It Fl d
103The
104.Fl d
105option causes
106.Nm
107to perform a depth\-first traversal, i.e. directories
108are visited in post\-order and all entries in a directory will be acted
109on before the directory itself.
110By default,
111.Nm
112visits directories in pre\-order, i.e. before their contents.
113Note, the default is
114.Ar not
115a breadth\-first traversal.
116.It Fl f
117The
118.Fl f
119option specifies a file hierarchy for
120.Nm
121to traverse.
122File hierarchies may also be specified as the operands immediately
123following the options.
124.It Fl h
125The
126.Fl h
127option causes the file information and file type (see
128.Xr stat 2 ) ,
129returned for each symbolic link to be those of the file referenced by the
130link, not the link itself.
131If the referenced file does not exist, the file information and type will
132be for the link itself.
133.It Fl x
134The
135.Fl x
136option prevents
137.Nm
138from descending into directories that have a device number different
139than that of the file from which the descent began.
140.El
141.Sh PRIMARIES
142.Bl -tag -width Ds
143.It Ic -atime Ar n
144True if the difference between the file last access time and the time
145.Nm
146was started, rounded up to the next full 24\-hour period, is
147.Ar n
14824\-hour periods.
149.It Ic -ctime Ar n
150True if the difference between the time of last change of file status
151information and the time
152.Nm
153was started, rounded up to the next full 24\-hour period, is
154.Ar n
15524\-hour periods.
156.It Ic -exec Ar utility Op argument ... ;
157True if the program named
158.Ar utility
159returns a zero value as its exit status.
160Optional arguments may be passed to the utility.
161The expression must be terminated by a semicolon (``;'').
162If the string ``{}'' appears anywhere in the utility name or the
163arguments it is replaced by the pathname of the current file.
164.Ar Utility
165will be executed from the directory from which
166.Nm
167was executed.
168.It Ic -follow
169Follow symbolic links.
170.It Ic -fstype Ar type
171True if the file is contained in a file system of type
172.Ar type .
173The
174.Xr sysctl 8
175command can be used to find out the types of filesystems
176that are available on the system:
177.Bd -literal -offset indent
178sysctl vfs
179.Ed
180In addition, there are two pseudo-types, ``local'' and ``rdonly''.
181The former matches any file system physically mounted on the system where
182the
183.Nm
184is being executed, and the latter matches any file system which is
185mounted read-only.
186.It Ic -group Ar gname
187True if the file belongs to the group
188.Ar gname .
189If
190.Ar gname
191is numeric and there is no such group name, then
192.Ar gname
193is treated as a group id.
194.It Ic -inum Ar n
195True if the file has inode number
196.Ar n .
197.It Ic -links Ar n
198True if the file has
199.Ar n
200links.
201.It Ic -ls
202This primary always evaluates to true.
203The following information for the current file is written to standard output:
204its inode number, size in 512\-byte blocks, file permissions, number of hard
205links, owner, group, size in bytes, last modification time, and pathname.
206If the file is a block or character special file, the major and minor numbers
207will be displayed instead of the size in bytes.
208If the file is a symbolic link, the pathname of the linked\-to file will be
209displayed preceded by ``\->''.
210The format is identical to that produced by ``ls \-dgils''.
211.It Ic -mtime Ar n
212True if the difference between the file last modification time and the time
213.Nm
214was started, rounded up to the next full 24\-hour period, is
215.Ar n
21624\-hour periods.
217.It Ic \&-ok Ar utility Op argument ... ;
218The
219.Ic \&-ok
220primary is identical to the
221.Ic -exec
222primary with the exception that
223.Nm
224requests user affirmation for the execution of the utility by printing
225a message to the terminal and reading a response.
226If the response is other than ``y'' the command is not executed and the
227value of the
228.Ar \&ok
229expression is false.
230.It Ic -name Ar pattern
231True if the last component of the pathname being examined matches
232.Ar pattern .
233Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'')
234may be used as part of
235.Ar pattern .
236These characters may be matched explicitly by escaping them with a
237backslash (``\e'').
238.It Ic -newer Ar file
239True if the current file has a more recent last modification time than
240.Ar file .
241.It Ic -nouser
242True if the file belongs to an unknown user.
243.It Ic -nogroup
244True if the file belongs to an unknown group.
245.It Ic -path Ar pattern
246True if the pathname being examined matches
247.Ar pattern .
248Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'')
249may be used as part of
250.Ar pattern .
251These characters may be matched explicitly by escaping them with a
252backslash (``\e'').
253Slashes (``/'') are treated as normal characters and do not have to be
254matched explicitly.
255.It Ic -perm Op Fl Ns Ar mode
256The
257.Ar mode
258may be either symbolic (see
259.Xr chmod 1 )
260or an octal number.
261If the mode is symbolic, a starting value of zero is assumed and the
262mode sets or clears permissions without regard to the process' file mode
263creation mask.
264If the mode is octal, only bits 07777
265.Pf ( Dv S_ISUID
266|
267.Dv S_ISGID
268|
269.Dv S_ISTXT
270|
271.Dv S_IRWXU
272|
273.Dv S_IRWXG
274|
275.Dv S_IRWXO )
276of the file's mode bits participate
277in the comparison.
278If the mode is preceded by a dash (``\-''), this primary evaluates to true
279if at least all of the bits in the mode are set in the file's mode bits.
280If the mode is not preceded by a dash, this primary evaluates to true if
281the bits in the mode exactly match the file's mode bits.
282Note, the first character of a symbolic mode may not be a dash (``\-'').
283.It Ic -print
284This primary always evaluates to true.
285It prints the pathname of the current file to standard output, followed
286by a newline character.
287If none of
288.Ic -exec ,
289.Ic -ls ,
290.Ic -ok ,
291nor
292.Ic -print0
293is specified, the given expression shall be effectively replaced by
294.Cm \&( Ns Ar given\& expression Ns Cm \&)
295.Ic -print .
296.It Ic -print0
297This primary always evaluates to true.
298It prints the pathname of the current file to standard output, followed
299by a null character.
300.It Ic -prune
301This primary always evaluates to true.
302It causes
303.Nm
304to not descend into the current file.
305Note, the
306.Ic -prune
307primary has no effect if the
308.Fl d
309option was specified.
310.It Ic -size Ar n Ns Op Cm c
311True if the file's size, rounded up, in 512\-byte blocks is
312.Ar n .
313If
314.Ar n
315is followed by a ``c'', then the primary is true if the
316file's size is
317.Ar n
318bytes.
319.It Ic -type Ar t
320True if the file is of the specified type.
321Possible file types are as follows:
322.Pp
323.Bl -tag -width flag -offset indent -compact
324.It Cm W
325whiteout
326.It Cm b
327block special
328.It Cm c
329character special
330.It Cm d
331directory
332.It Cm f
333regular file
334.It Cm l
335symbolic link
336.It Cm p
337FIFO
338.It Cm s
339socket
340.El
341.Pp
342.It Ic -user Ar uname
343True if the file belongs to the user
344.Ar uname .
345If
346.Ar uname
347is numeric and there is no such user name, then
348.Ar uname
349is treated as a user id.
350.El
351.Pp
352All primaries which take a numeric argument allow the number to be
353preceded by a plus sign (``+'') or a minus sign (``\-'').
354A preceding plus sign means ``more than n'', a preceding minus sign means
355``less than n'' and neither means ``exactly n'' .
356.Sh OPERATORS
357The primaries may be combined using the following operators.
358The operators are listed in order of decreasing precedence.
359.Bl -tag -width (expression)
360.It Cm \&( Ns Ar expression Ns Cm \&)
361This evaluates to true if the parenthesized expression evaluates to
362true.
363.Pp
364.It Cm \&! Ns Ar expression
365This is the unary
366.Tn NOT
367operator.
368It evaluates to true if the expression is false.
369.Pp
370.It Ar expression Cm -and Ar expression
371.It Ar expression expression
372The
373.Cm -and
374operator is the logical
375.Tn AND
376operator.
377As it is implied by the juxtaposition of two expressions it does not
378have to be specified.
379The expression evaluates to true if both expressions are true.
380The second expression is not evaluated if the first expression is false.
381.Pp
382.It Ar expression Cm -or Ar expression
383The
384.Cm -or
385operator is the logical
386.Tn OR
387operator.
388The expression evaluates to true if either the first or the second expression
389is true.
390The second expression is not evaluated if the first expression is true.
391.El
392.Pp
393All operands and primaries must be separate arguments to
394.Nm "" .
395Primaries which themselves take arguments expect each argument
396to be a separate argument to
397.Nm "" .
398.Sh EXAMPLES
399.Pp
400The following examples are shown as given to the shell:
401.Bl -tag -width findx
402.It Li "find / \e! -name \*q*.c\*q -print"
403Print out a list of all the files whose names do not end in ``.c''.
404.It Li "find / -newer ttt -user wnj -print"
405Print out a list of all the files owned by user ``wnj'' that are newer
406than the file ``ttt''.
407.It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
408Print out a list of all the files which are not both newer than ``ttt''
409and owned by ``wnj''.
410.It Li "find / \e( -newer ttt -or -user wnj \e) -print"
411Print out a list of all the files that are either owned by ``wnj'' or
412that are newer than ``ttt''.
413.El
414.Sh SEE ALSO
415.Xr chmod 1 ,
416.Xr locate 1 ,
417.Xr stat 2 ,
418.Xr fts 3 ,
419.Xr getpwent 3 ,
420.Xr getgrent 3 ,
421.Xr strmode 3 ,
422.Xr symlink 7
423.Sh STANDARDS
424The
425.Nm
426utility syntax is a superset of the syntax specified by the
427.St -p1003.2
428standard.
429.Pp
430The options and the
431.Ic -follow ,
432.Ic -fstype ,
433.Ic -inum ,
434.Ic -links ,
435.Ic -ls
436and
437.Ic -print0
438primaries are extensions to
439.St -p1003.2 .
440.Pp
441Historically, the
442.Fl d ,
443.Fl h
444and
445.Fl x
446options were implemented using the primaries ``\-depth'', ``\-follow'',
447and ``\-xdev''.
448These primaries always evaluated to true.
449As they were really global variables that took effect before the traversal
450began, some legal expressions could have unexpected results.
451An example is the expression ``\-print \-o \-depth''.
452As \-print always evaluates to true, the standard order of evaluation
453implies that \-depth would never be evaluated.
454This is not the case.
455.Pp
456The operator ``-or'' was implemented as ``\-o'', and the operator ``-and''
457was implemented as ``\-a''.
458.Pp
459Historic implementations of the
460.Ic -exec
461and
462.Ic -ok
463primaries did not replace the string ``{}'' in the utility name or the
464utility arguments if it had preceding or following non-whitespace characters.
465This version replaces it no matter where in the utility name or arguments
466it appears.
467.Sh BUGS
468The special characters used by
469.Nm
470are also special characters to many shell programs.
471In particular, the characters ``*'', ``['', ``]'', ``?'', ``('', ``)'',
472``!'', ``\e'' and ``;'' may have to be escaped from the shell.
473.Pp
474As there is no delimiter separating options and file names or file
475names and the
476.Ar expression ,
477it is difficult to specify files named ``-xdev'' or ``!''.
478These problems are handled by the
479.Fl f
480option and the
481.Xr getopt 3
482``--'' construct.