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