1) Fix -E (no escape char) mode, has error with 0xFF char
[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.
15637ed4
RG
192.It Ic -name Ar pattern
193True if the last component of the pathname being examined matches
194.Ar pattern .
195Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'')
196may be used as part of
197.Ar pattern .
198These characters may be matched explicitly by escaping them with a
199backslash (``\e'').
200.It Ic -newer Ar file
201True if the current file has a more recent last modification time than
202.Ar file .
203.It Ic -nouser
204True if the file belongs to an unknown user.
205.It Ic -nogroup
206True if the file belongs to an unknown group.
a558e4ae
GW
207.It Ic \&-ok Ar utility Ns Op argument ... ;
208The
209.Ic \&-ok
210primary is identical to the
211.Ic -exec
212primary with the exception that
213.Nm find
214requests user affirmation for the execution of the utility by printing
215a message to the terminal and reading a response.
216If the response is other than ``y'' the command is not executed and the
217value of the
218.Ar \&ok
219expression is false.
a558e4ae 220.It Ic -path Ar pattern
0b253bdd 221True if the pathname being examined matches
15637ed4
RG
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.
a558e4ae 261The expression is appended to the user specified expression if none of
15637ed4 262.Ic -exec ,
a558e4ae
GW
263.Ic -ls ,
264.Ic -print0 ,
265.Ic -printf
266and
15637ed4 267.Ic \&-ok
a558e4ae
GW
268are specified.
269.It Ic -print0
270This primary prints the pathname of the current file to standard output,
271followed by a NUL (ASCII 0) character. No newline is output. It
272is intended for use when the files being reported may contain newlines or
273other special characters.
274.It Ic -printf
275This primary takes one argument, which is interpreted as a format string
276to be passed to
277.Xr printf 3 .
278It must contain exactly one
279.Dq Li \&%s
280format specifier, with or without modifier flags, which receives the
281full pathname of the current file. No C-style escape processing is
282performed.
15637ed4
RG
283.It Ic -prune
284This primary always evaluates to true.
285It causes
286.Nm find
287to not descend into the current file.
288Note, the
289.Ic -prune
290primary has no effect if the
291.Fl d
292option was specified.
293.It Ic -size Ar n Ns Op Cm c
294True if the file's size, rounded up, in 512\-byte blocks is
295.Ar n .
296If
297.Ar n
298is followed by a ``c'', then the primary is true if the
299file's size is
300.Ar n
301bytes.
302.It Ic -type Ar t
303True if the file is of the specified type.
304Possible file types are as follows:
305.Pp
306.Bl -tag -width flag -offset indent -compact
307.It Cm b
308block special
309.It Cm c
310character special
311.It Cm d
312directory
313.It Cm f
314regular file
315.It Cm l
316symbolic link
317.It Cm p
318FIFO
319.It Cm s
320socket
321.El
322.Pp
323.It Ic -user Ar uname
324True if the file belongs to the user
325.Ar uname .
326If
327.Ar uname
328is numeric and there is no such user name, then
329.Ar uname
330is treated as a user id.
331.El
332.Pp
333All primaries which take a numeric argument allow the number to be
334preceded by a plus sign (``+'') or a minus sign (``\-'').
335A preceding plus sign means ``more than n'', a preceding minus sign means
336``less than n'' and neither means ``exactly n'' .
337.Sh OPERATORS
338The primaries may be combined using the following operators.
339The operators are listed in order of decreasing precedence.
340.Bl -tag -width (expression)
341.It Cm \&( Ns Ar expression Ns Cm \&)
342This evaluates to true if the parenthesized expression evaluates to
343true.
344.Pp
345.It Cm \&! Ns Ar expression
346This is the unary
347.Tn NOT
348operator.
349It evaluates to true if the expression is false.
350.Pp
351.It Ar expression Cm -and Ar expression
352.It Ar expression expression
353The
354.Cm -and
355operator is the logical
356.Tn AND
357operator.
358As it is implied by the juxtaposition of two expressions it does not
359have to be specified.
360The expression evaluates to true if both expressions are true.
361The second expression is not evaluated if the first expression is false.
362.Pp
363.It Ar expression Cm -or Ar expression
364The
365.Cm -or
366operator is the logical
367.Tn OR
368operator.
369The expression evaluates to true if either the first or the second expression
370is true.
371The second expression is not evaluated if the first expression is true.
372.El
373.Pp
374All operands and primaries must be separate arguments to
375.Nm find .
376Primaries which themselves take arguments expect each argument
377to be a separate argument to
378.Nm find .
379.Sh EXAMPLES
380.Pp
381The following examples are shown as given to the shell:
382.Bl -tag -width findx
383.It Li "find / \e! -name \*q*.c\*q -print"
384Print out a list of all the files whose names do not end in ``.c''.
385.It Li "find / -newer ttt -user wnj -print"
386Print out a list of all the files owned by user ``wnj'' that are newer
387than the file ``ttt''.
388.It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
389Print out a list of all the files which are not both newer than ``ttt''
390and owned by ``wnj''.
391.It Li "find / \e( -newer ttt -or -user wnj \e) -print"
392Print out a list of all the files that are either owned by ``wnj'' or
393that are newer than ``ttt''.
a558e4ae
GW
394.It Li "find / -name \e*~ -print0 | perl -n0e unlink"
395Find all the
396.Xr emacs 1
397backup files and delete them quickly using
398.Xr perl 1 .
15637ed4
RG
399.El
400.Sh SEE ALSO
401.Xr chmod 1 ,
4e97a0eb 402.Xr locate 1 ,
a558e4ae 403.Xr xargs 1 ,
15637ed4 404.Xr stat 2 ,
6b479535 405.Xr fts 3 ,
15637ed4
RG
406.Xr getpwent 3 ,
407.Xr getgrent 3 ,
a558e4ae 408.Xr printf 3 ,
6b479535
NW
409.Xr strmode 3 ,
410.Xr symlink 7
15637ed4
RG
411.Sh STANDARDS
412The
413.Nm find
414utility syntax is a superset of the syntax specified by the
415.St -p1003.2
416standard.
417.Pp
418The
419.Fl s
420and
421.Fl X
422options and the
a558e4ae
GW
423.Ic -inum ,
424.Ic -ls ,
425.Ic -print0 ,
15637ed4 426and
a558e4ae 427.Ic -printf
15637ed4
RG
428primaries are extensions to
429.St -p1003.2 .
430.Pp
431Historically, the
432.Fl d ,
433.Fl s
434and
435.Fl x
436options were implemented using the primaries ``\-depth'', ``\-follow'',
437and ``\-xdev''.
438These primaries always evaluated to true.
439As they were really global variables that took effect before the traversal
440began, some legal expressions could have unexpected results.
441An example is the expression ``\-print \-o \-depth''.
442As \-print always evaluates to true, the standard order of evaluation
443implies that \-depth would never be evaluated.
444This is not the case.
445.Pp
446The operator ``-or'' was implemented as ``\-o'', and the operator ``-and''
447was implemented as ``\-a''.
448.Pp
449Historic implementations of the
450.Ic exec
451and
452.Ic ok
453primaries did not replace the string ``{}'' in the utility name or the
454utility arguments if it had preceding or following non-whitespace characters.
455This version replaces it no matter where in the utility name or arguments
456it appears.
457.Sh BUGS
458The special characters used by
459.Nm find
460are also special characters to many shell programs.
461In particular, the characters ``*'', ``['', ``]'', ``?'', ``('', ``)'',
462``!'', ``\e'' and ``;'' may have to be escaped from the shell.
463.Pp
464As there is no delimiter separating options and file names or file
465names and the
466.Ar expression ,
467it is difficult to specify files named ``-xdev'' or ``!''.
468These problems are handled by the
469.Fl f
470option and the
471.Xr getopt 3
472``--'' construct.