]> git.saurik.com Git - apple/shell_cmds.git/blame - find/find.1
shell_cmds-179.tar.gz
[apple/shell_cmds.git] / find / find.1
CommitLineData
e1a085ba 1.\" Copyright (c) 1990, 1993
44bd5ea7
A
2.\" The Regents of the University of California. All rights reserved.
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.
44bd5ea7
A
15.\" 4. Neither the name of the University nor the names of its contributors
16.\" may be used to endorse or promote products derived from this software
17.\" without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
c0fcf4e1 31.\" @(#)find.1 8.7 (Berkeley) 5/9/95
1e9ba8f2 32.\" $FreeBSD: src/usr.bin/find/find.1,v 1.91 2011/09/28 18:53:36 ed Exp $
44bd5ea7 33.\"
1e9ba8f2 34.Dd September 28, 2011
44bd5ea7
A
35.Dt FIND 1
36.Os
37.Sh NAME
38.Nm find
39.Nd walk a file hierarchy
40.Sh SYNOPSIS
c0fcf4e1 41.Nm
44bd5ea7 42.Op Fl H | Fl L | Fl P
c0fcf4e1 43.Op Fl EXdsx
ddb4a88b
A
44.Op Fl f Ar path
45.Ar path ...
46.Op Ar expression
e1a085ba
A
47.Nm
48.Op Fl H | Fl L | Fl P
49.Op Fl EXdsx
ddb4a88b
A
50.Fl f Ar path
51.Op Ar path ...
52.Op Ar expression
44bd5ea7 53.Sh DESCRIPTION
e1a085ba
A
54The
55.Nm
56utility recursively descends the directory tree for each
ddb4a88b 57.Ar path
44bd5ea7
A
58listed, evaluating an
59.Ar expression
c0fcf4e1
A
60(composed of the
61.Dq primaries
62and
63.Dq operands
64listed below) in terms
44bd5ea7
A
65of each file in the tree.
66.Pp
67The options are as follows:
c0fcf4e1
A
68.Bl -tag -width indent
69.It Fl E
70Interpret regular expressions followed by
71.Ic -regex
72and
73.Ic -iregex
ddb4a88b 74primaries as extended (modern) regular expressions rather than basic
c0fcf4e1
A
75regular expressions (BRE's).
76The
77.Xr re_format 7
78manual page fully describes both formats.
44bd5ea7 79.It Fl H
e1a085ba 80Cause the file information and file type (see
c0fcf4e1
A
81.Xr stat 2 )
82returned for each symbolic link specified on the command line to be
44bd5ea7
A
83those of the file referenced by the link, not the link itself.
84If the referenced file does not exist, the file information and type will
c0fcf4e1
A
85be for the link itself.
86File information of all symbolic links not on
44bd5ea7
A
87the command line is that of the link itself.
88.It Fl L
e1a085ba 89Cause the file information and file type (see
c0fcf4e1 90.Xr stat 2 )
44bd5ea7
A
91returned for each symbolic link to be those of the file referenced by the
92link, not the link itself.
93If the referenced file does not exist, the file information and type will
94be for the link itself.
e1a085ba
A
95.Pp
96This option is equivalent to the deprecated
97.Ic -follow
98primary.
44bd5ea7 99.It Fl P
e1a085ba 100Cause the file information and file type (see
c0fcf4e1 101.Xr stat 2 )
44bd5ea7 102returned for each symbolic link to be those of the link itself.
c0fcf4e1 103This is the default.
44bd5ea7 104.It Fl X
e1a085ba 105Permit
44bd5ea7
A
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
c0fcf4e1 110.Xr xargs 1 ,
44bd5ea7
A
111a diagnostic message is displayed on standard error, and the file
112is skipped.
c0fcf4e1
A
113The delimiting characters include single
114.Pq Dq Li " ' "
115and double
116.Pq Dq Li " \*q "
117quotes, backslash
118.Pq Dq Li \e ,
119space, tab and newline characters.
e1a085ba
A
120.Pp
121However, you may wish to consider the
122.Fl print0
123primary in conjunction with
124.Dq Nm xargs Fl 0
125as an effective alternative.
44bd5ea7 126.It Fl d
e1a085ba 127Cause
44bd5ea7 128.Nm
e1a085ba
A
129to perform a depth-first traversal, i.e., directories
130are visited in post-order and all entries in a directory will be acted
44bd5ea7
A
131on before the directory itself.
132By default,
133.Nm
e1a085ba 134visits directories in pre-order, i.e., before their contents.
44bd5ea7 135Note, the default is
c0fcf4e1 136.Em not
e1a085ba
A
137a breadth-first traversal.
138.Pp
139This option is equivalent to the
140.Ic -depth
141primary of
142.St -p1003.1-2001 .
ddb4a88b 143The
e1a085ba 144.Fl d
ddb4a88b 145option
e1a085ba
A
146can be useful when
147.Nm
148is used with
149.Xr cpio 1
150to process files that are contained in directories with unusual permissions.
151It ensures that you have write permission while you are placing files in a
152directory, then sets the directory's permissions as the last thing.
44bd5ea7 153.It Fl f
e1a085ba 154Specify a file hierarchy for
44bd5ea7
A
155.Nm
156to traverse.
157File hierarchies may also be specified as the operands immediately
158following the options.
c0fcf4e1 159.It Fl s
e1a085ba 160Cause
c0fcf4e1
A
161.Nm
162to traverse the file hierarchies in lexicographical order,
163i.e., alphabetical order within each directory.
164Note:
165.Ql find -s
166and
167.Ql "find | sort"
168may give different results.
44bd5ea7 169.It Fl x
e1a085ba 170Prevent
44bd5ea7
A
171.Nm
172from descending into directories that have a device number different
173than that of the file from which the descent began.
e1a085ba
A
174.Pp
175This option is equivalent to the deprecated
176.Ic -xdev
177primary.
44bd5ea7
A
178.El
179.Sh PRIMARIES
1e9ba8f2
A
180.Pp
181All primaries which take a numeric argument allow the number to be
182preceded by a plus sign
183.Pq Dq Li +
184or a minus sign
185.Pq Dq Li - .
186A preceding plus sign means
187.Dq more than n ,
188a preceding minus sign means
189.Dq less than n
190and neither means
191.Dq exactly n .
c0fcf4e1 192.Bl -tag -width indent
e1a085ba
A
193.It Ic -Bmin Ar n
194True if the difference between the time of a file's inode creation
195and the time
196.Nm
197was started, rounded up to the next full minute, is
198.Ar n
199minutes.
200.It Ic -Bnewer Ar file
201Same as
202.Ic -newerBm .
203.It Ic -Btime Ar n Ns Op Cm smhdw
204If no units are specified, this primary evaluates to
205true if the difference between the time of a file's inode creation
206and the time
207.Nm
208was started, rounded up to the next full 24-hour period, is
209.Ar n
21024-hour periods.
211.Pp
212If units are specified, this primary evaluates to
213true if the difference between the time of a file's inode creation
214and the time
215.Nm
216was started is exactly
217.Ar n
218units.
219Please refer to the
220.Ic -atime
221primary description for information on supported time units.
f14763b6
A
222.It Ic -acl
223May be used in conjunction with other primaries to locate
224files with extended ACLs.
225See
226.Xr acl 3
227for more information.
c0fcf4e1
A
228.It Ic -amin Ar n
229True if the difference between the file last access time and the time
230.Nm
231was started, rounded up to the next full minute, is
232.Ar n
233minutes.
234.It Ic -anewer Ar file
235Same as
236.Ic -neweram .
e1a085ba
A
237.It Ic -atime Ar n Ns Op Cm smhdw
238If no units are specified, this primary evaluates to
239true if the difference between the file last access time and the time
240.Nm
241was started, rounded up to the next full 24-hour period, is
242.Ar n
24324-hour periods.
244.Pp
245If units are specified, this primary evaluates to
246true if the difference between the file last access time and the time
44bd5ea7 247.Nm
e1a085ba 248was started is exactly
44bd5ea7 249.Ar n
e1a085ba
A
250units.
251Possible time units are as follows:
252.Pp
253.Bl -tag -width indent -compact
254.It Cm s
255second
256.It Cm m
257minute (60 seconds)
258.It Cm h
259hour (60 minutes)
260.It Cm d
261day (24 hours)
262.It Cm w
263week (7 days)
264.El
265.Pp
266Any number of units may be combined in one
267.Ic -atime
268argument, for example,
269.Dq Li "-atime -1h30m" .
270Units are probably only useful when used in conjunction with the
271.Cm +
272or
273.Cm -
274modifier.
c0fcf4e1
A
275.It Ic -cmin Ar n
276True if the difference between the time of last change of file status
277information and the time
278.Nm
279was started, rounded up to the next full minute, is
280.Ar n
281minutes.
282.It Ic -cnewer Ar file
283Same as
284.Ic -newercm .
e1a085ba
A
285.It Ic -ctime Ar n Ns Op Cm smhdw
286If no units are specified, this primary evaluates to
287true if the difference between the time of last change of file status
44bd5ea7
A
288information and the time
289.Nm
e1a085ba 290was started, rounded up to the next full 24-hour period, is
44bd5ea7 291.Ar n
e1a085ba
A
29224-hour periods.
293.Pp
294If units are specified, this primary evaluates to
295true if the difference between the time of last change of file status
296information and the time
297.Nm
298was started is exactly
299.Ar n
300units.
301Please refer to the
302.Ic -atime
303primary description for information on supported time units.
ddb4a88b
A
304.It Ic -d
305Same as
306.Ic depth .
307GNU find implements this as a primary in mistaken emulation of
308.Fx
309.Xr find 1 .
c0fcf4e1
A
310.It Ic -delete
311Delete found files and/or directories.
312Always returns true.
313This executes
314from the current working directory as
315.Nm
316recurses down the tree.
317It will not attempt to delete a filename with a
318.Dq Pa /
319character in its pathname relative to
320.Dq Pa \&.
321for security reasons.
e1a085ba 322Depth-first traversal processing is implied by this option.
f14763b6 323Following symlinks is incompatible with this option.
c0fcf4e1
A
324.It Ic -depth
325Always true;
326same as the
327.Fl d
328option.
e1a085ba
A
329.It Ic -depth Ar n
330True if the depth of the file relative to the starting point of the traversal
331is
332.Ar n .
c0fcf4e1
A
333.It Ic -empty
334True if the current file or directory is empty.
e1a085ba 335.It Ic -exec Ar utility Oo Ar argument ... Oc Li \&;
44bd5ea7
A
336True if the program named
337.Ar utility
338returns a zero value as its exit status.
c0fcf4e1
A
339Optional
340.Ar arguments
341may be passed to the utility.
342The expression must be terminated by a semicolon
343.Pq Dq Li \&; .
e1a085ba
A
344If you invoke
345.Nm
346from a shell you may need to quote the semicolon if the shell would
347otherwise treat it as a control operator.
c0fcf4e1
A
348If the string
349.Dq Li {}
350appears anywhere in the utility name or the
44bd5ea7
A
351arguments it is replaced by the pathname of the current file.
352.Ar Utility
353will be executed from the directory from which
354.Nm
355was executed.
c0fcf4e1
A
356.Ar Utility
357and
358.Ar arguments
359are not subject to the further expansion of shell patterns
360and constructs.
e1a085ba
A
361.It Ic -exec Ar utility Oo Ar argument ... Oc Li {} +
362Same as
363.Ic -exec ,
364except that
365.Dq Li {}
366is replaced with as many pathnames as possible for each invocation of
367.Ar utility .
368This behaviour is similar to that of
369.Xr xargs 1 .
370.It Ic -execdir Ar utility Oo Ar argument ... Oc Li \&;
c0fcf4e1
A
371The
372.Ic -execdir
373primary is identical to the
374.Ic -exec
375primary with the exception that
376.Ar utility
377will be executed from the directory that holds
378the current file.
379The filename substituted for
380the string
381.Dq Li {}
382is not qualified.
ddb4a88b
A
383.It Ic -execdir Ar utility Oo Ar argument ... Oc Li {} +
384Same as
385.Ic -execdir ,
386except that
387.Dq Li {}
388is replaced with as many pathnames as possible for each invocation of
389.Ar utility .
390This behaviour is similar to that of
391.Xr xargs 1 .
c0fcf4e1
A
392.It Ic -flags Oo Cm - Ns | Ns Cm + Oc Ns Ar flags , Ns Ar notflags
393The flags are specified using symbolic names (see
394.Xr chflags 1 ) .
395Those with the
396.Qq Li no
397prefix (except
398.Qq Li nodump )
399are said to be
400.Ar notflags .
401Flags in
402.Ar flags
403are checked to be set, and flags in
404.Ar notflags
405are checked to be not set.
406Note that this is different from
407.Ic -perm ,
408which only allows the user to specify mode bits that are set.
409.Pp
410If flags are preceded by a dash
411.Pq Dq Li - ,
412this primary evaluates to true
413if at least all of the bits in
414.Ar flags
415and none of the bits in
416.Ar notflags
417are set in the file's flags bits.
418If flags are preceded by a plus
419.Pq Dq Li + ,
420this primary evaluates to true
421if any of the bits in
422.Ar flags
423is set in the file's flags bits,
424or any of the bits in
425.Ar notflags
426is not set in the file's flags bits.
427Otherwise,
428this primary evaluates to true
429if the bits in
430.Ar flags
431exactly match the file's flags bits,
432and none of the
433.Ar flags
434bits match those of
435.Ar notflags .
436.It Ic -fstype Ar type
44bd5ea7
A
437True if the file is contained in a file system of type
438.Ar type .
439The
1e9ba8f2 440.Xr lsvfs 1
e1a085ba 441command can be used to find out the types of file systems
1e9ba8f2 442that are available on the system.
c0fcf4e1
A
443In addition, there are two pseudo-types,
444.Dq Li local
445and
446.Dq Li rdonly .
44bd5ea7
A
447The former matches any file system physically mounted on the system where
448the
449.Nm
c0fcf4e1 450is being executed and the latter matches any file system which is
44bd5ea7 451mounted read-only.
ddb4a88b
A
452.It Ic -gid Ar gname
453The same thing as
454.Ar -group Ar gname
455for compatibility with GNU find.
456GNU find imposes a restriction that
457.Ar gname
458is numeric, while
459.Xr find 1
460does not.
c0fcf4e1 461.It Ic -group Ar gname
44bd5ea7 462True if the file belongs to the group
c0fcf4e1 463.Ar gname .
44bd5ea7
A
464If
465.Ar gname
466is numeric and there is no such group name, then
467.Ar gname
c0fcf4e1 468is treated as a group ID.
ddb4a88b
A
469.It Ic -ignore_readdir_race
470This option is for GNU find compatibility and is ignored.
471.It Ic -ilname Ar pattern
472Like
473.Ic -lname ,
474but the match is case insensitive.
475This is a GNU find extension.
c0fcf4e1
A
476.It Ic -iname Ar pattern
477Like
478.Ic -name ,
479but the match is case insensitive.
480.It Ic -inum Ar n
44bd5ea7 481True if the file has inode number
c0fcf4e1
A
482.Ar n .
483.It Ic -ipath Ar pattern
484Like
485.Ic -path ,
486but the match is case insensitive.
487.It Ic -iregex Ar pattern
488Like
489.Ic -regex ,
490but the match is case insensitive.
ddb4a88b
A
491.It Ic -iwholename Ar pattern
492The same thing as
493.Ic -ipath ,
494for GNU find compatibility.
c0fcf4e1 495.It Ic -links Ar n
44bd5ea7
A
496True if the file has
497.Ar n
498links.
ddb4a88b
A
499.It Ic -lname Ar pattern
500Like
501.Ic -name ,
502but the contents of the symbolic link are matched instead of the file
503name.
504This is a GNU find extension.
44bd5ea7
A
505.It Ic -ls
506This primary always evaluates to true.
507The following information for the current file is written to standard output:
e1a085ba 508its inode number, size in 512-byte blocks, file permissions, number of hard
44bd5ea7 509links, owner, group, size in bytes, last modification time, and pathname.
1e9ba8f2 510If the file is a block or character special file, the device number
44bd5ea7 511will be displayed instead of the size in bytes.
e1a085ba 512If the file is a symbolic link, the pathname of the linked-to file will be
c0fcf4e1
A
513displayed preceded by
514.Dq Li -> .
515The format is identical to that produced by
516.Bk -words
ddb4a88b 517.Dq Nm ls Fl dgils .
c0fcf4e1
A
518.Ek
519.It Ic -maxdepth Ar n
e1a085ba
A
520Always true; descend at most
521.Ar n
522directory levels below the command line arguments.
523If any
524.Ic -maxdepth
525primary is specified, it applies to the entire expression even if it would
526not normally be evaluated.
ddb4a88b 527.Dq Ic -maxdepth Li 0
e1a085ba 528limits the whole search to the command line arguments.
c0fcf4e1 529.It Ic -mindepth Ar n
e1a085ba 530Always true; do not apply any tests or actions at levels less than
c0fcf4e1 531.Ar n .
e1a085ba
A
532If any
533.Ic -mindepth
534primary is specified, it applies to the entire expression even if it would
535not normally be evaluated.
ddb4a88b 536.Dq Ic -mindepth Li 1
e1a085ba 537processes all but the command line arguments.
c0fcf4e1
A
538.It Ic -mmin Ar n
539True if the difference between the file last modification time and the time
540.Nm
541was started, rounded up to the next full minute, is
542.Ar n
543minutes.
544.It Ic -mnewer Ar file
545Same as
546.Ic -newer .
ddb4a88b
A
547.It Ic -mount
548The same thing as
549.Ic -xdev ,
550for GNU find compatibility.
e1a085ba
A
551.It Ic -mtime Ar n Ns Op Cm smhdw
552If no units are specified, this primary evaluates to
553true if the difference between the file last modification time and the time
554.Nm
555was started, rounded up to the next full 24-hour period, is
556.Ar n
55724-hour periods.
558.Pp
559If units are specified, this primary evaluates to
560true if the difference between the file last modification time and the time
44bd5ea7 561.Nm
e1a085ba 562was started is exactly
44bd5ea7 563.Ar n
e1a085ba
A
564units.
565Please refer to the
566.Ic -atime
567primary description for information on supported time units.
c0fcf4e1
A
568.It Ic -name Ar pattern
569True if the last component of the pathname being examined matches
570.Ar pattern .
571Special shell pattern matching characters
572.Dq ( Li \&[ ,
573.Dq Li \&] ,
574.Dq Li * ,
575and
576.Dq Li \&? )
577may be used as part of
578.Ar pattern .
579These characters may be matched explicitly by escaping them with a
580backslash
581.Pq Dq Li \e .
582.It Ic -newer Ar file
583True if the current file has a more recent last modification time than
584.Ar file .
585.It Ic -newer Ns Ar X Ns Ar Y Ar file
586True if the current file has a more recent last access time
ddb4a88b 587.Pq Ar X Ns = Ns Cm a ,
e1a085ba 588inode creation time
ddb4a88b 589.Pq Ar X Ns = Ns Cm B ,
c0fcf4e1 590change time
ddb4a88b 591.Pq Ar X Ns = Ns Cm c ,
c0fcf4e1 592or modification time
ddb4a88b 593.Pq Ar X Ns = Ns Cm m
c0fcf4e1 594than the last access time
ddb4a88b 595.Pq Ar Y Ns = Ns Cm a ,
e1a085ba 596inode creation time
ddb4a88b 597.Pq Ar Y Ns = Ns Cm B ,
c0fcf4e1 598change time
ddb4a88b 599.Pq Ar Y Ns = Ns Cm c ,
c0fcf4e1 600or modification time
ddb4a88b 601.Pq Ar Y Ns = Ns Cm m
c0fcf4e1
A
602of
603.Ar file .
604In addition, if
605.Ar Y Ns = Ns Cm t ,
606then
607.Ar file
608is instead interpreted as a direct date specification of the form
609understood by
610.Xr cvs 1 .
611Note that
612.Ic -newermm
613is equivalent to
614.Ic -newer .
615.It Ic -nogroup
616True if the file belongs to an unknown group.
ddb4a88b
A
617.It Ic -noignore_readdir_race
618This option is for GNU find compatibility and is ignored.
619.It Ic -noleaf
620This option is for GNU find compatibility.
621In GNU find it disables an optimization not relevant to
622.Xr find 1 ,
623so it is ignored.
c0fcf4e1
A
624.It Ic -nouser
625True if the file belongs to an unknown user.
e1a085ba 626.It Ic -ok Ar utility Oo Ar argument ... Oc Li \&;
44bd5ea7 627The
c0fcf4e1 628.Ic -ok
44bd5ea7
A
629primary is identical to the
630.Ic -exec
631primary with the exception that
632.Nm
c0fcf4e1
A
633requests user affirmation for the execution of the
634.Ar utility
635by printing
44bd5ea7 636a message to the terminal and reading a response.
e1a085ba
A
637If the response is not affirmative
638.Ql ( y
639in the
640.Dq Li POSIX
641locale),
c0fcf4e1 642the command is not executed and the
44bd5ea7 643value of the
c0fcf4e1 644.Ic -ok
44bd5ea7 645expression is false.
e1a085ba 646.It Ic -okdir Ar utility Oo Ar argument ... Oc Li \&;
c0fcf4e1
A
647The
648.Ic -okdir
649primary is identical to the
650.Ic -execdir
651primary with the same exception as described for the
652.Ic -ok
653primary.
654.It Ic -path Ar pattern
44bd5ea7 655True if the pathname being examined matches
c0fcf4e1
A
656.Ar pattern .
657Special shell pattern matching characters
658.Dq ( Li \&[ ,
659.Dq Li \&] ,
660.Dq Li * ,
661and
662.Dq Li \&? )
44bd5ea7 663may be used as part of
c0fcf4e1 664.Ar pattern .
44bd5ea7 665These characters may be matched explicitly by escaping them with a
c0fcf4e1
A
666backslash
667.Pq Dq Li \e .
668Slashes
669.Pq Dq Li /
670are treated as normal characters and do not have to be
44bd5ea7 671matched explicitly.
c0fcf4e1 672.It Ic -perm Oo Cm - Ns | Ns Cm + Oc Ns Ar mode
44bd5ea7
A
673The
674.Ar mode
675may be either symbolic (see
c0fcf4e1 676.Xr chmod 1 )
44bd5ea7 677or an octal number.
c0fcf4e1
A
678If the
679.Ar mode
680is symbolic, a starting value of zero is assumed and the
681.Ar mode
682sets or clears permissions without regard to the process' file mode
44bd5ea7 683creation mask.
c0fcf4e1
A
684If the
685.Ar mode
686is octal, only bits 07777
687.Pq Dv S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO
44bd5ea7
A
688of the file's mode bits participate
689in the comparison.
c0fcf4e1
A
690If the
691.Ar mode
692is preceded by a dash
693.Pq Dq Li - ,
694this primary evaluates to true
695if at least all of the bits in the
696.Ar mode
697are set in the file's mode bits.
698If the
699.Ar mode
700is preceded by a plus
701.Pq Dq Li + ,
702this primary evaluates to true
703if any of the bits in the
704.Ar mode
705are set in the file's mode bits.
706Otherwise, this primary evaluates to true if
707the bits in the
708.Ar mode
709exactly match the file's mode bits.
710Note, the first character of a symbolic mode may not be a dash
711.Pq Dq Li - .
44bd5ea7
A
712.It Ic -print
713This primary always evaluates to true.
c0fcf4e1 714It prints the pathname of the current file to standard output.
44bd5ea7 715If none of
e1a085ba
A
716.\" 4772561
717.Ic -exec , -ls , -print , -print0 ,
c0fcf4e1
A
718or
719.Ic -ok
44bd5ea7 720is specified, the given expression shall be effectively replaced by
c0fcf4e1 721.Cm \&( Ar "given expression" Cm \&) Ic -print .
44bd5ea7
A
722.It Ic -print0
723This primary always evaluates to true.
c0fcf4e1 724It prints the pathname of the current file to standard output, followed by an
e1a085ba
A
725.Tn ASCII
726.Dv NUL
c0fcf4e1 727character (character code 0).
44bd5ea7
A
728.It Ic -prune
729This primary always evaluates to true.
730It causes
731.Nm
732to not descend into the current file.
733Note, the
734.Ic -prune
735primary has no effect if the
736.Fl d
737option was specified.
c0fcf4e1
A
738.It Ic -regex Ar pattern
739True if the whole path of the file matches
740.Ar pattern
741using regular expression.
742To match a file named
743.Dq Pa ./foo/xyzzy ,
744you can use the regular expression
745.Dq Li ".*/[xyz]*"
746or
747.Dq Li ".*/foo/.*" ,
748but not
749.Dq Li xyzzy
750or
751.Dq Li /foo/ .
ddb4a88b
A
752.It Ic -samefile Ar name
753True if the file is a hard link to
754.Ar name .
755If the command option
756.Ic -L
757is specified, it is also true if the file is a symbolic link and
758points to
759.Ar name .
e1a085ba
A
760.It Ic -size Ar n Ns Op Cm ckMGTP
761True if the file's size, rounded up, in 512-byte blocks is
c0fcf4e1 762.Ar n .
44bd5ea7
A
763If
764.Ar n
c0fcf4e1
A
765is followed by a
766.Cm c ,
767then the primary is true if the
44bd5ea7
A
768file's size is
769.Ar n
c0fcf4e1 770bytes (characters).
e1a085ba
A
771Similarly if
772.Ar n
773is followed by a scale indicator then the file's size is compared to
774.Ar n
775scaled as:
776.Pp
777.Bl -tag -width indent -compact
778.It Cm k
779kilobytes (1024 bytes)
780.It Cm M
781megabytes (1024 kilobytes)
782.It Cm G
783gigabytes (1024 megabytes)
784.It Cm T
785terabytes (1024 gigabytes)
786.It Cm P
787petabytes (1024 terabytes)
788.El
c0fcf4e1 789.It Ic -type Ar t
44bd5ea7
A
790True if the file is of the specified type.
791Possible file types are as follows:
792.Pp
c0fcf4e1 793.Bl -tag -width indent -compact
44bd5ea7
A
794.It Cm b
795block special
796.It Cm c
797character special
798.It Cm d
799directory
800.It Cm f
801regular file
802.It Cm l
803symbolic link
804.It Cm p
805FIFO
806.It Cm s
807socket
808.El
ddb4a88b
A
809.It Ic -uid Ar uname
810The same thing as
811.Ar -user Ar uname
812for compatibility with GNU find.
813GNU find imposes a restriction that
814.Ar uname
815is numeric, while
816.Xr find 1
817does not.
c0fcf4e1 818.It Ic -user Ar uname
44bd5ea7 819True if the file belongs to the user
c0fcf4e1 820.Ar uname .
44bd5ea7
A
821If
822.Ar uname
823is numeric and there is no such user name, then
824.Ar uname
c0fcf4e1 825is treated as a user ID.
ddb4a88b
A
826.It Ic -wholename Ar pattern
827The same thing as
828.Ic -path ,
829for GNU find compatibility.
f14763b6
A
830.It Ic -xattr
831True if the file has any extended attributes.
832.It Ic -xattrname Ar name
833True if the file has an extended attribute with the specified
834.Ar name .
44bd5ea7 835.El
44bd5ea7
A
836.Sh OPERATORS
837The primaries may be combined using the following operators.
838The operators are listed in order of decreasing precedence.
c0fcf4e1 839.Pp
ddb4a88b 840.Bl -tag -width indent -compact
c0fcf4e1 841.It Cm \&( Ar expression Cm \&)
44bd5ea7
A
842This evaluates to true if the parenthesized expression evaluates to
843true.
844.Pp
e1a085ba 845.It Cm \&! Ar expression
9bafe280 846.It Cm -not Ar expression
44bd5ea7
A
847This is the unary
848.Tn NOT
849operator.
850It evaluates to true if the expression is false.
851.Pp
ddb4a88b
A
852.It Cm -false
853Always false.
854.It Cm -true
855Always true.
856.Pp
c0fcf4e1
A
857.It Ar expression Cm -and Ar expression
858.It Ar expression expression
44bd5ea7
A
859The
860.Cm -and
861operator is the logical
862.Tn AND
863operator.
864As it is implied by the juxtaposition of two expressions it does not
865have to be specified.
866The expression evaluates to true if both expressions are true.
867The second expression is not evaluated if the first expression is false.
868.Pp
c0fcf4e1 869.It Ar expression Cm -or Ar expression
44bd5ea7
A
870The
871.Cm -or
872operator is the logical
873.Tn OR
874operator.
875The expression evaluates to true if either the first or the second expression
876is true.
877The second expression is not evaluated if the first expression is true.
878.El
879.Pp
880All operands and primaries must be separate arguments to
c0fcf4e1 881.Nm .
44bd5ea7
A
882Primaries which themselves take arguments expect each argument
883to be a separate argument to
c0fcf4e1 884.Nm .
e1a085ba
A
885.Sh ENVIRONMENT
886The
887.Ev LANG , LC_ALL , LC_COLLATE , LC_CTYPE , LC_MESSAGES
888and
889.Ev LC_TIME
890environment variables affect the execution of the
891.Nm
892utility as described in
893.Xr environ 7 .
44bd5ea7 894.Sh EXAMPLES
44bd5ea7 895The following examples are shown as given to the shell:
c0fcf4e1
A
896.Bl -tag -width indent
897.It Li "find / \e! -name \*q*.c\*q -print"
898Print out a list of all the files whose names do not end in
899.Pa .c .
900.It Li "find / -newer ttt -user wnj -print"
901Print out a list of all the files owned by user
902.Dq wnj
903that are newer
904than the file
905.Pa ttt .
906.It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
907Print out a list of all the files which are not both newer than
908.Pa ttt
909and owned by
910.Dq wnj .
911.It Li "find / \e( -newer ttt -or -user wnj \e) -print"
912Print out a list of all the files that are either owned by
913.Dq wnj
914or that are newer than
915.Pa ttt .
e1a085ba 916.It Li "find / -newerct '1 minute ago' -print"
c0fcf4e1
A
917Print out a list of all the files whose inode change time is more
918recent than the current time minus one minute.
e1a085ba
A
919.It Li "find / -type f -exec echo {} \e;"
920Use the
921.Xr echo 1
922command to print out a list of all the files.
f14763b6 923.It Li "find -L /usr/ports/packages -type l -exec rm -- {} +"
e1a085ba
A
924Delete all broken symbolic links in
925.Pa /usr/ports/packages .
926.It Li "find /usr/src -name CVS -prune -o -depth +6 -print"
927Find files and directories that are at least seven levels deep
928in the working directory
929.Pa /usr/src .
930.It Li "find /usr/src -name CVS -prune -o -mindepth 7 -print"
931Is not equivalent to the previous example, since
932.Ic -prune
933is not evaluated below level seven.
44bd5ea7 934.El
e1a085ba
A
935.Sh COMPATIBILITY
936The
937.Ic -follow
938primary is deprecated; the
939.Fl L
940option should be used instead.
941See the
942.Sx STANDARDS
943section below for details.
44bd5ea7 944.Sh SEE ALSO
c0fcf4e1 945.Xr chflags 1 ,
44bd5ea7 946.Xr chmod 1 ,
c0fcf4e1 947.Xr cvs 1 ,
44bd5ea7 948.Xr locate 1 ,
1e9ba8f2 949.Xr lsvfs 1 ,
c0fcf4e1
A
950.Xr whereis 1 ,
951.Xr which 1 ,
e1a085ba 952.Xr xargs 1 ,
44bd5ea7 953.Xr stat 2 ,
f14763b6 954.Xr acl 3 ,
44bd5ea7 955.Xr fts 3 ,
44bd5ea7 956.Xr getgrent 3 ,
c0fcf4e1 957.Xr getpwent 3 ,
44bd5ea7 958.Xr strmode 3 ,
c0fcf4e1 959.Xr re_format 7 ,
44bd5ea7
A
960.Xr symlink 7
961.Sh STANDARDS
962The
963.Nm
964utility syntax is a superset of the syntax specified by the
e1a085ba 965.St -p1003.1-2001
44bd5ea7
A
966standard.
967.Pp
e1a085ba 968All the single character options except
ddb4a88b 969.Fl H
44bd5ea7 970and
ddb4a88b 971.Fl L
e1a085ba
A
972as well as
973.Ic -amin , -anewer , -cmin , -cnewer , -delete , -empty , -fstype ,
974.Ic -iname , -inum , -iregex , -ls , -maxdepth , -mindepth , -mmin ,
975.Ic -path , -print0 , -regex
976and all of the
ddb4a88b 977.Ic -B*
e1a085ba
A
978birthtime related primaries are extensions to
979.St -p1003.1-2001 .
44bd5ea7
A
980.Pp
981Historically, the
e1a085ba 982.Fl d , L
44bd5ea7
A
983and
984.Fl x
c0fcf4e1
A
985options were implemented using the primaries
986.Ic -depth , -follow ,
987and
988.Ic -xdev .
44bd5ea7
A
989These primaries always evaluated to true.
990As they were really global variables that took effect before the traversal
991began, some legal expressions could have unexpected results.
c0fcf4e1
A
992An example is the expression
993.Ic -print Cm -o Ic -depth .
994As
995.Ic -print
996always evaluates to true, the standard order of evaluation
997implies that
998.Ic -depth
999would never be evaluated.
44bd5ea7
A
1000This is not the case.
1001.Pp
c0fcf4e1
A
1002The operator
1003.Cm -or
1004was implemented as
1005.Cm -o ,
1006and the operator
1007.Cm -and
1008was implemented as
1009.Cm -a .
44bd5ea7
A
1010.Pp
1011Historic implementations of the
1012.Ic -exec
1013and
1014.Ic -ok
c0fcf4e1
A
1015primaries did not replace the string
1016.Dq Li {}
1017in the utility name or the
44bd5ea7
A
1018utility arguments if it had preceding or following non-whitespace characters.
1019This version replaces it no matter where in the utility name or arguments
1020it appears.
c0fcf4e1
A
1021.Pp
1022The
1023.Fl E
e1a085ba 1024option was inspired by the equivalent
c0fcf4e1
A
1025.Xr grep 1
1026and
e1a085ba
A
1027.Xr sed 1
1028options.
1029.Sh HISTORY
1030A
1031.Nm
1032command appeared in
1033.At v1 .
44bd5ea7
A
1034.Sh BUGS
1035The special characters used by
1036.Nm
1037are also special characters to many shell programs.
c0fcf4e1
A
1038In particular, the characters
1039.Dq Li * ,
1040.Dq Li \&[ ,
1041.Dq Li \&] ,
1042.Dq Li \&? ,
1043.Dq Li \&( ,
1044.Dq Li \&) ,
1045.Dq Li \&! ,
1046.Dq Li \e
1047and
1048.Dq Li \&;
1049may have to be escaped from the shell.
44bd5ea7
A
1050.Pp
1051As there is no delimiter separating options and file names or file
1052names and the
1053.Ar expression ,
c0fcf4e1
A
1054it is difficult to specify files named
1055.Pa -xdev
1056or
1057.Pa \&! .
44bd5ea7
A
1058These problems are handled by the
1059.Fl f
1060option and the
1061.Xr getopt 3
c0fcf4e1
A
1062.Dq Fl Fl
1063construct.
1064.Pp
1065The
1066.Ic -delete
e1a085ba 1067primary does not interact well with other options that cause the file system
c0fcf4e1 1068tree traversal options to be changed.
e1a085ba
A
1069.Pp
1070The
1071.Ic -mindepth
1072and
1073.Ic -maxdepth
1074primaries are actually global options (as documented above).
1075They should
1076probably be replaced by options which look like options.