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