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