]> git.saurik.com Git - apple/shell_cmds.git/blame - find/find.1
shell_cmds-162.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
f14763b6 36.\" $FreeBSD: src/usr.bin/find/find.1,v 1.87 2009/09/20 16:47:56 jilles 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.
f14763b6
A
214.It Ic -acl
215May be used in conjunction with other primaries to locate
216files with extended ACLs.
217See
218.Xr acl 3
219for 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.
f14763b6 315Following symlinks is incompatible with this option.
c0fcf4e1
A
316.It Ic -depth
317Always true;
318same as the
319.Fl d
320option.
e1a085ba
A
321.It Ic -depth Ar n
322True if the depth of the file relative to the starting point of the traversal
323is
324.Ar n .
c0fcf4e1
A
325.It Ic -empty
326True if the current file or directory is empty.
e1a085ba 327.It Ic -exec Ar utility Oo Ar argument ... Oc Li \&;
44bd5ea7
A
328True if the program named
329.Ar utility
330returns a zero value as its exit status.
c0fcf4e1
A
331Optional
332.Ar arguments
333may be passed to the utility.
334The expression must be terminated by a semicolon
335.Pq Dq Li \&; .
e1a085ba
A
336If you invoke
337.Nm
338from a shell you may need to quote the semicolon if the shell would
339otherwise treat it as a control operator.
c0fcf4e1
A
340If the string
341.Dq Li {}
342appears anywhere in the utility name or the
44bd5ea7
A
343arguments it is replaced by the pathname of the current file.
344.Ar Utility
345will be executed from the directory from which
346.Nm
347was executed.
c0fcf4e1
A
348.Ar Utility
349and
350.Ar arguments
351are not subject to the further expansion of shell patterns
352and constructs.
e1a085ba
A
353.It Ic -exec Ar utility Oo Ar argument ... Oc Li {} +
354Same as
355.Ic -exec ,
356except that
357.Dq Li {}
358is replaced with as many pathnames as possible for each invocation of
359.Ar utility .
360This behaviour is similar to that of
361.Xr xargs 1 .
362.It Ic -execdir Ar utility Oo Ar argument ... Oc Li \&;
c0fcf4e1
A
363The
364.Ic -execdir
365primary is identical to the
366.Ic -exec
367primary with the exception that
368.Ar utility
369will be executed from the directory that holds
370the current file.
371The filename substituted for
372the string
373.Dq Li {}
374is not qualified.
ddb4a88b
A
375.It Ic -execdir Ar utility Oo Ar argument ... Oc Li {} +
376Same as
377.Ic -execdir ,
378except that
379.Dq Li {}
380is replaced with as many pathnames as possible for each invocation of
381.Ar utility .
382This behaviour is similar to that of
383.Xr xargs 1 .
c0fcf4e1
A
384.It Ic -flags Oo Cm - Ns | Ns Cm + Oc Ns Ar flags , Ns Ar notflags
385The flags are specified using symbolic names (see
386.Xr chflags 1 ) .
387Those with the
388.Qq Li no
389prefix (except
390.Qq Li nodump )
391are said to be
392.Ar notflags .
393Flags in
394.Ar flags
395are checked to be set, and flags in
396.Ar notflags
397are checked to be not set.
398Note that this is different from
399.Ic -perm ,
400which only allows the user to specify mode bits that are set.
401.Pp
402If flags are preceded by a dash
403.Pq Dq Li - ,
404this primary evaluates to true
405if at least all of the bits in
406.Ar flags
407and none of the bits in
408.Ar notflags
409are set in the file's flags bits.
410If flags are preceded by a plus
411.Pq Dq Li + ,
412this primary evaluates to true
413if any of the bits in
414.Ar flags
415is set in the file's flags bits,
416or any of the bits in
417.Ar notflags
418is not set in the file's flags bits.
419Otherwise,
420this primary evaluates to true
421if the bits in
422.Ar flags
423exactly match the file's flags bits,
424and none of the
425.Ar flags
426bits match those of
427.Ar notflags .
428.It Ic -fstype Ar type
44bd5ea7
A
429True if the file is contained in a file system of type
430.Ar type .
431The
432.Xr sysctl 8
e1a085ba 433command can be used to find out the types of file systems
44bd5ea7 434that are available on the system:
c0fcf4e1
A
435.Pp
436.Dl "sysctl vfs"
437.Pp
438In addition, there are two pseudo-types,
439.Dq Li local
440and
441.Dq Li rdonly .
44bd5ea7
A
442The former matches any file system physically mounted on the system where
443the
444.Nm
c0fcf4e1 445is being executed and the latter matches any file system which is
44bd5ea7 446mounted read-only.
ddb4a88b
A
447.It Ic -gid Ar gname
448The same thing as
449.Ar -group Ar gname
450for compatibility with GNU find.
451GNU find imposes a restriction that
452.Ar gname
453is numeric, while
454.Xr find 1
455does not.
c0fcf4e1 456.It Ic -group Ar gname
44bd5ea7 457True if the file belongs to the group
c0fcf4e1 458.Ar gname .
44bd5ea7
A
459If
460.Ar gname
461is numeric and there is no such group name, then
462.Ar gname
c0fcf4e1 463is treated as a group ID.
ddb4a88b
A
464.It Ic -ignore_readdir_race
465This option is for GNU find compatibility and is ignored.
466.It Ic -ilname Ar pattern
467Like
468.Ic -lname ,
469but the match is case insensitive.
470This is a GNU find extension.
c0fcf4e1
A
471.It Ic -iname Ar pattern
472Like
473.Ic -name ,
474but the match is case insensitive.
475.It Ic -inum Ar n
44bd5ea7 476True if the file has inode number
c0fcf4e1
A
477.Ar n .
478.It Ic -ipath Ar pattern
479Like
480.Ic -path ,
481but the match is case insensitive.
482.It Ic -iregex Ar pattern
483Like
484.Ic -regex ,
485but the match is case insensitive.
ddb4a88b
A
486.It Ic -iwholename Ar pattern
487The same thing as
488.Ic -ipath ,
489for GNU find compatibility.
c0fcf4e1 490.It Ic -links Ar n
44bd5ea7
A
491True if the file has
492.Ar n
493links.
ddb4a88b
A
494.It Ic -lname Ar pattern
495Like
496.Ic -name ,
497but the contents of the symbolic link are matched instead of the file
498name.
499This is a GNU find extension.
44bd5ea7
A
500.It Ic -ls
501This primary always evaluates to true.
502The following information for the current file is written to standard output:
e1a085ba 503its inode number, size in 512-byte blocks, file permissions, number of hard
44bd5ea7
A
504links, owner, group, size in bytes, last modification time, and pathname.
505If the file is a block or character special file, the major and minor numbers
506will be displayed instead of the size in bytes.
e1a085ba 507If the file is a symbolic link, the pathname of the linked-to file will be
c0fcf4e1
A
508displayed preceded by
509.Dq Li -> .
510The format is identical to that produced by
511.Bk -words
ddb4a88b 512.Dq Nm ls Fl dgils .
c0fcf4e1
A
513.Ek
514.It Ic -maxdepth Ar n
e1a085ba
A
515Always true; descend at most
516.Ar n
517directory levels below the command line arguments.
518If any
519.Ic -maxdepth
520primary is specified, it applies to the entire expression even if it would
521not normally be evaluated.
ddb4a88b 522.Dq Ic -maxdepth Li 0
e1a085ba 523limits the whole search to the command line arguments.
c0fcf4e1 524.It Ic -mindepth Ar n
e1a085ba 525Always true; do not apply any tests or actions at levels less than
c0fcf4e1 526.Ar n .
e1a085ba
A
527If any
528.Ic -mindepth
529primary is specified, it applies to the entire expression even if it would
530not normally be evaluated.
ddb4a88b 531.Dq Ic -mindepth Li 1
e1a085ba 532processes all but the command line arguments.
c0fcf4e1
A
533.It Ic -mmin Ar n
534True if the difference between the file last modification time and the time
535.Nm
536was started, rounded up to the next full minute, is
537.Ar n
538minutes.
539.It Ic -mnewer Ar file
540Same as
541.Ic -newer .
ddb4a88b
A
542.It Ic -mount
543The same thing as
544.Ic -xdev ,
545for GNU find compatibility.
e1a085ba
A
546.It Ic -mtime Ar n Ns Op Cm smhdw
547If no units are specified, this primary evaluates to
548true if the difference between the file last modification time and the time
549.Nm
550was started, rounded up to the next full 24-hour period, is
551.Ar n
55224-hour periods.
553.Pp
554If units are specified, this primary evaluates to
555true if the difference between the file last modification time and the time
44bd5ea7 556.Nm
e1a085ba 557was started is exactly
44bd5ea7 558.Ar n
e1a085ba
A
559units.
560Please refer to the
561.Ic -atime
562primary description for information on supported time units.
c0fcf4e1
A
563.It Ic -name Ar pattern
564True if the last component of the pathname being examined matches
565.Ar pattern .
566Special shell pattern matching characters
567.Dq ( Li \&[ ,
568.Dq Li \&] ,
569.Dq Li * ,
570and
571.Dq Li \&? )
572may be used as part of
573.Ar pattern .
574These characters may be matched explicitly by escaping them with a
575backslash
576.Pq Dq Li \e .
577.It Ic -newer Ar file
578True if the current file has a more recent last modification time than
579.Ar file .
580.It Ic -newer Ns Ar X Ns Ar Y Ar file
581True if the current file has a more recent last access time
ddb4a88b 582.Pq Ar X Ns = Ns Cm a ,
e1a085ba 583inode creation time
ddb4a88b 584.Pq Ar X Ns = Ns Cm B ,
c0fcf4e1 585change time
ddb4a88b 586.Pq Ar X Ns = Ns Cm c ,
c0fcf4e1 587or modification time
ddb4a88b 588.Pq Ar X Ns = Ns Cm m
c0fcf4e1 589than the last access time
ddb4a88b 590.Pq Ar Y Ns = Ns Cm a ,
e1a085ba 591inode creation time
ddb4a88b 592.Pq Ar Y Ns = Ns Cm B ,
c0fcf4e1 593change time
ddb4a88b 594.Pq Ar Y Ns = Ns Cm c ,
c0fcf4e1 595or modification time
ddb4a88b 596.Pq Ar Y Ns = Ns Cm m
c0fcf4e1
A
597of
598.Ar file .
599In addition, if
600.Ar Y Ns = Ns Cm t ,
601then
602.Ar file
603is instead interpreted as a direct date specification of the form
604understood by
605.Xr cvs 1 .
606Note that
607.Ic -newermm
608is equivalent to
609.Ic -newer .
610.It Ic -nogroup
611True if the file belongs to an unknown group.
ddb4a88b
A
612.It Ic -noignore_readdir_race
613This option is for GNU find compatibility and is ignored.
614.It Ic -noleaf
615This option is for GNU find compatibility.
616In GNU find it disables an optimization not relevant to
617.Xr find 1 ,
618so it is ignored.
c0fcf4e1
A
619.It Ic -nouser
620True if the file belongs to an unknown user.
e1a085ba 621.It Ic -ok Ar utility Oo Ar argument ... Oc Li \&;
44bd5ea7 622The
c0fcf4e1 623.Ic -ok
44bd5ea7
A
624primary is identical to the
625.Ic -exec
626primary with the exception that
627.Nm
c0fcf4e1
A
628requests user affirmation for the execution of the
629.Ar utility
630by printing
44bd5ea7 631a message to the terminal and reading a response.
e1a085ba
A
632If the response is not affirmative
633.Ql ( y
634in the
635.Dq Li POSIX
636locale),
c0fcf4e1 637the command is not executed and the
44bd5ea7 638value of the
c0fcf4e1 639.Ic -ok
44bd5ea7 640expression is false.
e1a085ba 641.It Ic -okdir Ar utility Oo Ar argument ... Oc Li \&;
c0fcf4e1
A
642The
643.Ic -okdir
644primary is identical to the
645.Ic -execdir
646primary with the same exception as described for the
647.Ic -ok
648primary.
649.It Ic -path Ar pattern
44bd5ea7 650True if the pathname being examined matches
c0fcf4e1
A
651.Ar pattern .
652Special shell pattern matching characters
653.Dq ( Li \&[ ,
654.Dq Li \&] ,
655.Dq Li * ,
656and
657.Dq Li \&? )
44bd5ea7 658may be used as part of
c0fcf4e1 659.Ar pattern .
44bd5ea7 660These characters may be matched explicitly by escaping them with a
c0fcf4e1
A
661backslash
662.Pq Dq Li \e .
663Slashes
664.Pq Dq Li /
665are treated as normal characters and do not have to be
44bd5ea7 666matched explicitly.
c0fcf4e1 667.It Ic -perm Oo Cm - Ns | Ns Cm + Oc Ns Ar mode
44bd5ea7
A
668The
669.Ar mode
670may be either symbolic (see
c0fcf4e1 671.Xr chmod 1 )
44bd5ea7 672or an octal number.
c0fcf4e1
A
673If the
674.Ar mode
675is symbolic, a starting value of zero is assumed and the
676.Ar mode
677sets or clears permissions without regard to the process' file mode
44bd5ea7 678creation mask.
c0fcf4e1
A
679If the
680.Ar mode
681is octal, only bits 07777
682.Pq Dv S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO
44bd5ea7
A
683of the file's mode bits participate
684in the comparison.
c0fcf4e1
A
685If the
686.Ar mode
687is preceded by a dash
688.Pq Dq Li - ,
689this primary evaluates to true
690if at least all of the bits in the
691.Ar mode
692are set in the file's mode bits.
693If the
694.Ar mode
695is preceded by a plus
696.Pq Dq Li + ,
697this primary evaluates to true
698if any of the bits in the
699.Ar mode
700are set in the file's mode bits.
701Otherwise, this primary evaluates to true if
702the bits in the
703.Ar mode
704exactly match the file's mode bits.
705Note, the first character of a symbolic mode may not be a dash
706.Pq Dq Li - .
44bd5ea7
A
707.It Ic -print
708This primary always evaluates to true.
c0fcf4e1 709It prints the pathname of the current file to standard output.
44bd5ea7 710If none of
e1a085ba
A
711.\" 4772561
712.Ic -exec , -ls , -print , -print0 ,
c0fcf4e1
A
713or
714.Ic -ok
44bd5ea7 715is specified, the given expression shall be effectively replaced by
c0fcf4e1 716.Cm \&( Ar "given expression" Cm \&) Ic -print .
44bd5ea7
A
717.It Ic -print0
718This primary always evaluates to true.
c0fcf4e1 719It prints the pathname of the current file to standard output, followed by an
e1a085ba
A
720.Tn ASCII
721.Dv NUL
c0fcf4e1 722character (character code 0).
44bd5ea7
A
723.It Ic -prune
724This primary always evaluates to true.
725It causes
726.Nm
727to not descend into the current file.
728Note, the
729.Ic -prune
730primary has no effect if the
731.Fl d
732option was specified.
c0fcf4e1
A
733.It Ic -regex Ar pattern
734True if the whole path of the file matches
735.Ar pattern
736using regular expression.
737To match a file named
738.Dq Pa ./foo/xyzzy ,
739you can use the regular expression
740.Dq Li ".*/[xyz]*"
741or
742.Dq Li ".*/foo/.*" ,
743but not
744.Dq Li xyzzy
745or
746.Dq Li /foo/ .
ddb4a88b
A
747.It Ic -samefile Ar name
748True if the file is a hard link to
749.Ar name .
750If the command option
751.Ic -L
752is specified, it is also true if the file is a symbolic link and
753points to
754.Ar name .
e1a085ba
A
755.It Ic -size Ar n Ns Op Cm ckMGTP
756True if the file's size, rounded up, in 512-byte blocks is
c0fcf4e1 757.Ar n .
44bd5ea7
A
758If
759.Ar n
c0fcf4e1
A
760is followed by a
761.Cm c ,
762then the primary is true if the
44bd5ea7
A
763file's size is
764.Ar n
c0fcf4e1 765bytes (characters).
e1a085ba
A
766Similarly if
767.Ar n
768is followed by a scale indicator then the file's size is compared to
769.Ar n
770scaled as:
771.Pp
772.Bl -tag -width indent -compact
773.It Cm k
774kilobytes (1024 bytes)
775.It Cm M
776megabytes (1024 kilobytes)
777.It Cm G
778gigabytes (1024 megabytes)
779.It Cm T
780terabytes (1024 gigabytes)
781.It Cm P
782petabytes (1024 terabytes)
783.El
c0fcf4e1 784.It Ic -type Ar t
44bd5ea7
A
785True if the file is of the specified type.
786Possible file types are as follows:
787.Pp
c0fcf4e1 788.Bl -tag -width indent -compact
44bd5ea7
A
789.It Cm b
790block special
791.It Cm c
792character special
793.It Cm d
794directory
795.It Cm f
796regular file
797.It Cm l
798symbolic link
799.It Cm p
800FIFO
801.It Cm s
802socket
803.El
ddb4a88b
A
804.It Ic -uid Ar uname
805The same thing as
806.Ar -user Ar uname
807for compatibility with GNU find.
808GNU find imposes a restriction that
809.Ar uname
810is numeric, while
811.Xr find 1
812does not.
c0fcf4e1 813.It Ic -user Ar uname
44bd5ea7 814True if the file belongs to the user
c0fcf4e1 815.Ar uname .
44bd5ea7
A
816If
817.Ar uname
818is numeric and there is no such user name, then
819.Ar uname
c0fcf4e1 820is treated as a user ID.
ddb4a88b
A
821.It Ic -wholename Ar pattern
822The same thing as
823.Ic -path ,
824for GNU find compatibility.
f14763b6
A
825.It Ic -xattr
826True if the file has any extended attributes.
827.It Ic -xattrname Ar name
828True if the file has an extended attribute with the specified
829.Ar name .
44bd5ea7
A
830.El
831.Pp
832All primaries which take a numeric argument allow the number to be
c0fcf4e1
A
833preceded by a plus sign
834.Pq Dq Li +
835or a minus sign
836.Pq Dq Li - .
837A preceding plus sign means
838.Dq more than n ,
839a preceding minus sign means
840.Dq less than n
841and neither means
842.Dq exactly n .
44bd5ea7
A
843.Sh OPERATORS
844The primaries may be combined using the following operators.
845The operators are listed in order of decreasing precedence.
c0fcf4e1 846.Pp
ddb4a88b 847.Bl -tag -width indent -compact
c0fcf4e1 848.It Cm \&( Ar expression Cm \&)
44bd5ea7
A
849This evaluates to true if the parenthesized expression evaluates to
850true.
851.Pp
e1a085ba 852.It Cm \&! Ar expression
9bafe280 853.It Cm -not Ar expression
44bd5ea7
A
854This is the unary
855.Tn NOT
856operator.
857It evaluates to true if the expression is false.
858.Pp
ddb4a88b
A
859.It Cm -false
860Always false.
861.It Cm -true
862Always true.
863.Pp
c0fcf4e1
A
864.It Ar expression Cm -and Ar expression
865.It Ar expression expression
44bd5ea7
A
866The
867.Cm -and
868operator is the logical
869.Tn AND
870operator.
871As it is implied by the juxtaposition of two expressions it does not
872have to be specified.
873The expression evaluates to true if both expressions are true.
874The second expression is not evaluated if the first expression is false.
875.Pp
c0fcf4e1 876.It Ar expression Cm -or Ar expression
44bd5ea7
A
877The
878.Cm -or
879operator is the logical
880.Tn OR
881operator.
882The expression evaluates to true if either the first or the second expression
883is true.
884The second expression is not evaluated if the first expression is true.
885.El
886.Pp
887All operands and primaries must be separate arguments to
c0fcf4e1 888.Nm .
44bd5ea7
A
889Primaries which themselves take arguments expect each argument
890to be a separate argument to
c0fcf4e1 891.Nm .
e1a085ba
A
892.Sh ENVIRONMENT
893The
894.Ev LANG , LC_ALL , LC_COLLATE , LC_CTYPE , LC_MESSAGES
895and
896.Ev LC_TIME
897environment variables affect the execution of the
898.Nm
899utility as described in
900.Xr environ 7 .
44bd5ea7 901.Sh EXAMPLES
44bd5ea7 902The following examples are shown as given to the shell:
c0fcf4e1
A
903.Bl -tag -width indent
904.It Li "find / \e! -name \*q*.c\*q -print"
905Print out a list of all the files whose names do not end in
906.Pa .c .
907.It Li "find / -newer ttt -user wnj -print"
908Print out a list of all the files owned by user
909.Dq wnj
910that are newer
911than the file
912.Pa ttt .
913.It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
914Print out a list of all the files which are not both newer than
915.Pa ttt
916and owned by
917.Dq wnj .
918.It Li "find / \e( -newer ttt -or -user wnj \e) -print"
919Print out a list of all the files that are either owned by
920.Dq wnj
921or that are newer than
922.Pa ttt .
e1a085ba 923.It Li "find / -newerct '1 minute ago' -print"
c0fcf4e1
A
924Print out a list of all the files whose inode change time is more
925recent than the current time minus one minute.
e1a085ba
A
926.It Li "find / -type f -exec echo {} \e;"
927Use the
928.Xr echo 1
929command to print out a list of all the files.
f14763b6 930.It Li "find -L /usr/ports/packages -type l -exec rm -- {} +"
e1a085ba
A
931Delete all broken symbolic links in
932.Pa /usr/ports/packages .
933.It Li "find /usr/src -name CVS -prune -o -depth +6 -print"
934Find files and directories that are at least seven levels deep
935in the working directory
936.Pa /usr/src .
937.It Li "find /usr/src -name CVS -prune -o -mindepth 7 -print"
938Is not equivalent to the previous example, since
939.Ic -prune
940is not evaluated below level seven.
44bd5ea7 941.El
e1a085ba
A
942.Sh COMPATIBILITY
943The
944.Ic -follow
945primary is deprecated; the
946.Fl L
947option should be used instead.
948See the
949.Sx STANDARDS
950section below for details.
44bd5ea7 951.Sh SEE ALSO
c0fcf4e1 952.Xr chflags 1 ,
44bd5ea7 953.Xr chmod 1 ,
c0fcf4e1 954.Xr cvs 1 ,
44bd5ea7 955.Xr locate 1 ,
c0fcf4e1
A
956.Xr whereis 1 ,
957.Xr which 1 ,
e1a085ba 958.Xr xargs 1 ,
44bd5ea7 959.Xr stat 2 ,
f14763b6 960.Xr acl 3 ,
44bd5ea7 961.Xr fts 3 ,
44bd5ea7 962.Xr getgrent 3 ,
c0fcf4e1 963.Xr getpwent 3 ,
44bd5ea7 964.Xr strmode 3 ,
c0fcf4e1 965.Xr re_format 7 ,
44bd5ea7
A
966.Xr symlink 7
967.Sh STANDARDS
968The
969.Nm
970utility syntax is a superset of the syntax specified by the
e1a085ba 971.St -p1003.1-2001
44bd5ea7
A
972standard.
973.Pp
e1a085ba 974All the single character options except
ddb4a88b 975.Fl H
44bd5ea7 976and
ddb4a88b 977.Fl L
e1a085ba
A
978as well as
979.Ic -amin , -anewer , -cmin , -cnewer , -delete , -empty , -fstype ,
980.Ic -iname , -inum , -iregex , -ls , -maxdepth , -mindepth , -mmin ,
981.Ic -path , -print0 , -regex
982and all of the
ddb4a88b 983.Ic -B*
e1a085ba
A
984birthtime related primaries are extensions to
985.St -p1003.1-2001 .
44bd5ea7
A
986.Pp
987Historically, the
e1a085ba 988.Fl d , L
44bd5ea7
A
989and
990.Fl x
c0fcf4e1
A
991options were implemented using the primaries
992.Ic -depth , -follow ,
993and
994.Ic -xdev .
44bd5ea7
A
995These primaries always evaluated to true.
996As they were really global variables that took effect before the traversal
997began, some legal expressions could have unexpected results.
c0fcf4e1
A
998An example is the expression
999.Ic -print Cm -o Ic -depth .
1000As
1001.Ic -print
1002always evaluates to true, the standard order of evaluation
1003implies that
1004.Ic -depth
1005would never be evaluated.
44bd5ea7
A
1006This is not the case.
1007.Pp
c0fcf4e1
A
1008The operator
1009.Cm -or
1010was implemented as
1011.Cm -o ,
1012and the operator
1013.Cm -and
1014was implemented as
1015.Cm -a .
44bd5ea7
A
1016.Pp
1017Historic implementations of the
1018.Ic -exec
1019and
1020.Ic -ok
c0fcf4e1
A
1021primaries did not replace the string
1022.Dq Li {}
1023in the utility name or the
44bd5ea7
A
1024utility arguments if it had preceding or following non-whitespace characters.
1025This version replaces it no matter where in the utility name or arguments
1026it appears.
c0fcf4e1
A
1027.Pp
1028The
1029.Fl E
e1a085ba 1030option was inspired by the equivalent
c0fcf4e1
A
1031.Xr grep 1
1032and
e1a085ba
A
1033.Xr sed 1
1034options.
1035.Sh HISTORY
1036A
1037.Nm
1038command appeared in
1039.At v1 .
44bd5ea7
A
1040.Sh BUGS
1041The special characters used by
1042.Nm
1043are also special characters to many shell programs.
c0fcf4e1
A
1044In particular, the characters
1045.Dq Li * ,
1046.Dq Li \&[ ,
1047.Dq Li \&] ,
1048.Dq Li \&? ,
1049.Dq Li \&( ,
1050.Dq Li \&) ,
1051.Dq Li \&! ,
1052.Dq Li \e
1053and
1054.Dq Li \&;
1055may have to be escaped from the shell.
44bd5ea7
A
1056.Pp
1057As there is no delimiter separating options and file names or file
1058names and the
1059.Ar expression ,
c0fcf4e1
A
1060it is difficult to specify files named
1061.Pa -xdev
1062or
1063.Pa \&! .
44bd5ea7
A
1064These problems are handled by the
1065.Fl f
1066option and the
1067.Xr getopt 3
c0fcf4e1
A
1068.Dq Fl Fl
1069construct.
1070.Pp
1071The
1072.Ic -delete
e1a085ba 1073primary does not interact well with other options that cause the file system
c0fcf4e1 1074tree traversal options to be changed.
e1a085ba
A
1075.Pp
1076The
1077.Ic -mindepth
1078and
1079.Ic -maxdepth
1080primaries are actually global options (as documented above).
1081They should
1082probably be replaced by options which look like options.