xref: /freebsd/usr.bin/find/find.1 (revision 321dc6ee7e81e1b06db725f218db08a8aca47d31)
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 July 22, 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
179.Xr ASCII 8 .
180In locales other than
181.Ar C
182results may vary more due to collation differences.
183.It Fl x
184Prevent
185.Nm
186from descending into directories that have a device number different
187than that of the file from which the descent began.
188.Pp
189This option is equivalent to the deprecated
190.Ic -xdev
191primary.
192.El
193.Sh PRIMARIES
194All primaries which take a numeric argument allow the number to be
195preceded by a plus sign
196.Pq Dq Li +
197or a minus sign
198.Pq Dq Li - .
199A preceding plus sign means
200.Dq more than n ,
201a preceding minus sign means
202.Dq less than n
203and neither means
204.Dq exactly n .
205.Bl -tag -width indent
206.It Ic -Bmin Ar n
207True if the difference between the time of a file's inode creation
208and the time
209.Nm
210was started, rounded up to the next full minute, is
211.Ar n
212minutes.
213.It Ic -Bnewer Ar file
214Same as
215.Ic -newerBm .
216.It Ic -Btime Ar n Ns Op Cm smhdw
217If no units are specified, this primary evaluates to
218true if the difference between the time of a file's inode creation
219and the time
220.Nm
221was started, rounded up to the next full 24-hour period, is
222.Ar n
22324-hour periods.
224.Pp
225If units are specified, this primary evaluates to
226true if the difference between the time of a file's inode creation
227and the time
228.Nm
229was started is exactly
230.Ar n
231units.
232Please refer to the
233.Ic -atime
234primary description for information on supported time units.
235.It Ic -acl
236May be used in conjunction with other primaries to locate
237files with extended ACLs.
238See
239.Xr acl 3
240for more information.
241.It Ic -amin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
242True if the difference between the file last access time and the time
243.Nm
244was started, rounded up to the next full minute, is
245more than
246.Ar n
247.Pq + Ns Ar n ,
248less than
249.Ar n
250.Pq - Ns Ar n ,
251or exactly
252.Ar n
253minutes ago.
254.It Ic -anewer Ar file
255Same as
256.Ic -neweram .
257.It Ic -atime Ar n Ns Op Cm smhdw
258If no units are specified, this primary evaluates to
259true if the difference between the file last access time and the time
260.Nm
261was started, rounded up to the next full 24-hour period, is
262.Ar n
26324-hour periods.
264.Pp
265If units are specified, this primary evaluates to
266true if the difference between the file last access time and the time
267.Nm
268was started is exactly
269.Ar n
270units.
271Possible time units are as follows:
272.Pp
273.Bl -tag -width indent -compact
274.It Cm s
275second
276.It Cm m
277minute (60 seconds)
278.It Cm h
279hour (60 minutes)
280.It Cm d
281day (24 hours)
282.It Cm w
283week (7 days)
284.El
285.Pp
286Any number of units may be combined in one
287.Ic -atime
288argument, for example,
289.Dq Li "-atime -1h30m" .
290Units are probably only useful when used in conjunction with the
291.Cm +
292or
293.Cm -
294modifier.
295.It Ic -cmin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
296True if the difference between the time of last change of file status
297information and the time
298.Nm
299was started, rounded up to the next full minute, is
300more than
301.Ar n
302.Pq + Ns Ar n ,
303less than
304.Ar n
305.Pq - Ns Ar n ,
306or exactly
307.Ar n
308minutes ago.
309.It Ic -cnewer Ar file
310Same as
311.Ic -newercm .
312.It Ic -ctime Ar n Ns Op Cm smhdw
313If no units are specified, this primary evaluates to
314true if the difference between the time of last change of file status
315information and the time
316.Nm
317was started, rounded up to the next full 24-hour period, is
318.Ar n
31924-hour periods.
320.Pp
321If units are specified, this primary evaluates to
322true if the difference between the time of last change of file status
323information and the time
324.Nm
325was started is exactly
326.Ar n
327units.
328Please refer to the
329.Ic -atime
330primary description for information on supported time units.
331.It Ic -d
332Non-portable, BSD-specific version of
333.Ic depth .
334GNU find implements this as a primary in mistaken emulation of
335.Fx
336.Nm .
337.It Ic -delete
338Delete found files and/or directories.
339Always returns true.
340This executes
341from the current working directory as
342.Nm
343recurses down the tree.
344It will not attempt to delete a filename with a
345.Dq Pa /
346character in its pathname relative to
347.Dq Pa \&.
348for security reasons.
349Depth-first traversal processing is implied by this option.
350The
351.Ic -delete
352primary will fail to delete a directory if it is not empty.
353Following symlinks is incompatible with this option.
354.It Ic -depth
355Always true;
356same as the non-portable
357.Fl d
358option.
359Cause
360.Nm
361to perform a depth-first traversal, i.e., directories
362are visited in post-order and all entries in a directory will be acted
363on before the directory itself.
364By default,
365.Nm
366visits directories in pre-order, i.e., before their contents.
367Note, the default is
368.Em not
369a breadth-first traversal.
370.Pp
371The
372.Ic -depth
373primary
374can be useful when
375.Nm
376is used with
377.Xr cpio 1
378to process files that are contained in directories with unusual permissions.
379It ensures that you have write permission while you are placing files in a
380directory, then sets the directory's permissions as the last thing.
381.It Ic -depth Ar n
382True if the depth of the file relative to the starting point of the traversal
383is
384.Ar n .
385.It Ic -empty
386True if the current file or directory is empty.
387.It Ic -exec Ar utility Oo Ar argument ... Oc Li \&;
388True if the program named
389.Ar utility
390returns a zero value as its exit status.
391Optional
392.Ar arguments
393may be passed to the utility.
394The expression must be terminated by a semicolon
395.Pq Dq Li \&; .
396If you invoke
397.Nm
398from a shell you may need to quote the semicolon if the shell would
399otherwise treat it as a control operator.
400If the string
401.Dq Li {}
402appears anywhere in the utility name or the
403arguments it is replaced by the pathname of the current file.
404.Ar Utility
405will be executed from the directory from which
406.Nm
407was executed.
408.Ar Utility
409and
410.Ar arguments
411are not subject to the further expansion of shell patterns
412and constructs.
413.It Ic -exec Ar utility Oo Ar argument ... Oc Li {} +
414Same as
415.Ic -exec ,
416except that
417.Dq Li {}
418is replaced with as many pathnames as possible for each invocation of
419.Ar utility .
420This behaviour is similar to that of
421.Xr xargs 1 .
422The primary always returns true;
423if at least one invocation of
424.Ar utility
425returns a non-zero exit status,
426.Nm
427will return a non-zero exit status.
428.It Ic -execdir Ar utility Oo Ar argument ... Oc Li \&;
429The
430.Ic -execdir
431primary is identical to the
432.Ic -exec
433primary with the exception that
434.Ar utility
435will be executed from the directory that holds
436the current file.
437The filename substituted for
438the string
439.Dq Li {}
440is not qualified.
441.It Ic -execdir Ar utility Oo Ar argument ... Oc Li {} +
442Same as
443.Ic -execdir ,
444except that
445.Dq Li {}
446is replaced with as many pathnames as possible for each invocation of
447.Ar utility .
448This behaviour is similar to that of
449.Xr xargs 1 .
450The primary always returns true;
451if at least one invocation of
452.Ar utility
453returns a non-zero exit status,
454.Nm
455will return a non-zero exit status.
456.It Ic -flags Oo Cm - Ns | Ns Cm + Oc Ns Ar flags , Ns Ar notflags
457The flags are specified using symbolic names (see
458.Xr chflags 1 ) .
459Those with the
460.Qq Li no
461prefix (except
462.Qq Li nodump )
463are said to be
464.Ar notflags .
465Flags in
466.Ar flags
467are checked to be set, and flags in
468.Ar notflags
469are checked to be not set.
470Note that this is different from
471.Ic -perm ,
472which only allows the user to specify mode bits that are set.
473.Pp
474If flags are preceded by a dash
475.Pq Dq Li - ,
476this primary evaluates to true
477if at least all of the bits in
478.Ar flags
479and none of the bits in
480.Ar notflags
481are set in the file's flags bits.
482If flags are preceded by a plus
483.Pq Dq Li + ,
484this primary evaluates to true
485if any of the bits in
486.Ar flags
487is set in the file's flags bits,
488or any of the bits in
489.Ar notflags
490is not set in the file's flags bits.
491Otherwise,
492this primary evaluates to true
493if the bits in
494.Ar flags
495exactly match the file's flags bits,
496and none of the
497.Ar flags
498bits match those of
499.Ar notflags .
500.It Ic -fstype Ar type
501True if the file is contained in a file system of type
502.Ar type .
503The
504.Xr lsvfs 1
505command can be used to find out the types of file systems
506that are available on the system.
507In addition, there are two pseudo-types,
508.Dq Li local
509and
510.Dq Li rdonly .
511The former matches any file system physically mounted on the system where
512the
513.Nm
514is being executed and the latter matches any file system which is
515mounted read-only.
516.It Ic -gid Ar gname
517The same thing as
518.Ic -group Ar gname
519for compatibility with GNU find.
520GNU find imposes a restriction that
521.Ar gname
522is numeric, while
523.Nm
524does not.
525.It Ic -group Ar gname
526True if the file belongs to the group
527.Ar gname .
528If
529.Ar gname
530is numeric and there is no such group name, then
531.Ar gname
532is treated as a group ID.
533.It Ic -ignore_readdir_race
534Ignore errors because a file or a directory is deleted
535after reading the name from a directory.
536This option does not affect errors occurring on starting points.
537.It Ic -ilname Ar pattern
538Like
539.Ic -lname ,
540but the match is case insensitive.
541This is a GNU find extension.
542.It Ic -iname Ar pattern
543Like
544.Ic -name ,
545but the match is case insensitive.
546.It Ic -inum Ar n
547True if the file has inode number
548.Ar n .
549.It Ic -ipath Ar pattern
550Like
551.Ic -path ,
552but the match is case insensitive.
553.It Ic -iregex Ar pattern
554Like
555.Ic -regex ,
556but the match is case insensitive.
557.It Ic -iwholename Ar pattern
558The same thing as
559.Ic -ipath ,
560for GNU find compatibility.
561.It Ic -links Ar n
562True if the file has
563.Ar n
564links.
565.It Ic -lname Ar pattern
566Like
567.Ic -name ,
568but the contents of the symbolic link are matched instead of the file
569name.
570Note that this only matches broken symbolic links
571if symbolic links are being followed.
572This is a GNU find extension.
573.It Ic -ls
574This primary always evaluates to true.
575The following information for the current file is written to standard output:
576its inode number, size in 512-byte blocks, file permissions, number of hard
577links, owner, group, size in bytes, last modification time, and pathname.
578If the file is a block or character special file, the device number
579will be displayed instead of the size in bytes.
580If the file is a symbolic link, the pathname of the linked-to file will be
581displayed preceded by
582.Dq Li -> .
583The format is identical to that produced by
584.Bk -words
585.Dq Nm ls Fl dgils .
586.Ek
587.It Ic -maxdepth Ar n
588Always true; descend at most
589.Ar n
590directory levels below the command line arguments.
591If any
592.Ic -maxdepth
593primary is specified, it applies to the entire expression even if it would
594not normally be evaluated.
595.Dq Ic -maxdepth Li 0
596limits the whole search to the command line arguments.
597.It Ic -mindepth Ar n
598Always true; do not apply any tests or actions at levels less than
599.Ar n .
600If any
601.Ic -mindepth
602primary is specified, it applies to the entire expression even if it would
603not normally be evaluated.
604.Dq Ic -mindepth Li 1
605processes all but the command line arguments.
606.It Ic -mmin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
607True if the difference between the file last modification time and the time
608.Nm
609was started, rounded up to the next full minute, is
610more than
611.Ar n
612.Pq + Ns Ar n ,
613less than
614.Ar n
615.Pq - Ns Ar n ,
616or exactly
617.Ar n
618minutes ago.
619.It Ic -mnewer Ar file
620Same as
621.Ic -newer .
622.It Ic -mount
623The same thing as
624.Ic -xdev ,
625for GNU find compatibility.
626.It Ic -mtime Ar n Ns Op Cm smhdw
627If no units are specified, this primary evaluates to
628true if the difference between the file last modification time and the time
629.Nm
630was started, rounded up to the next full 24-hour period, is
631.Ar n
63224-hour periods.
633.Pp
634If units are specified, this primary evaluates to
635true if the difference between the file last modification time and the time
636.Nm
637was started is exactly
638.Ar n
639units.
640Please refer to the
641.Ic -atime
642primary description for information on supported time units.
643.It Ic -name Ar pattern
644True if the last component of the pathname being examined matches
645.Ar pattern .
646Special shell pattern matching characters
647.Dq ( Li \&[ ,
648.Dq Li \&] ,
649.Dq Li * ,
650and
651.Dq Li \&? )
652may be used as part of
653.Ar pattern .
654These characters may be matched explicitly by escaping them with a
655backslash
656.Pq Dq Li \e .
657.It Ic -newer Ar file
658True if the current file has a more recent last modification time than
659.Ar file .
660.It Ic -newer Ns Ar X Ns Ar Y Ar file
661True if the current file has a more recent last access time
662.Pq Ar X Ns = Ns Cm a ,
663inode creation time
664.Pq Ar X Ns = Ns Cm B ,
665change time
666.Pq Ar X Ns = Ns Cm c ,
667or modification time
668.Pq Ar X Ns = Ns Cm m
669than the last access time
670.Pq Ar Y Ns = Ns Cm a ,
671inode creation time
672.Pq Ar Y Ns = Ns Cm B ,
673change time
674.Pq Ar Y Ns = Ns Cm c ,
675or modification time
676.Pq Ar Y Ns = Ns Cm m
677of
678.Ar file .
679In addition, if
680.Ar Y Ns = Ns Cm t ,
681then
682.Ar file
683is instead interpreted as a direct date specification of the form
684understood by ISO8601 or RFC822.
685Note that
686.Ic -newermm
687is equivalent to
688.Ic -newer .
689.It Ic -nogroup
690True if the file belongs to an unknown group.
691.It Ic -noignore_readdir_race
692Turn off the effect of
693.Ic -ignore_readdir_race .
694This is default behaviour.
695.It Ic -noleaf
696This option is for GNU find compatibility.
697In GNU find it disables an optimization not relevant to
698.Nm ,
699so it is ignored.
700.It Ic -nouser
701True if the file belongs to an unknown user.
702.It Ic -ok Ar utility Oo Ar argument ... Oc Li \&;
703The
704.Ic -ok
705primary is identical to the
706.Ic -exec
707primary with the exception that
708.Nm
709requests user affirmation for the execution of the
710.Ar utility
711by printing
712a message to the terminal and reading a response.
713If the response is not affirmative
714.Ql ( y
715in the
716.Dq Li POSIX
717locale),
718the command is not executed and the
719value of the
720.Ic -ok
721expression is false.
722.It Ic -okdir Ar utility Oo Ar argument ... Oc Li \&;
723The
724.Ic -okdir
725primary is identical to the
726.Ic -execdir
727primary with the same exception as described for the
728.Ic -ok
729primary.
730.It Ic -path Ar pattern
731True if the pathname being examined matches
732.Ar pattern .
733Special shell pattern matching characters
734.Dq ( Li \&[ ,
735.Dq Li \&] ,
736.Dq Li * ,
737and
738.Dq Li \&? )
739may be used as part of
740.Ar pattern .
741These characters may be matched explicitly by escaping them with a
742backslash
743.Pq Dq Li \e .
744Slashes
745.Pq Dq Li /
746are treated as normal characters and do not have to be
747matched explicitly.
748.It Ic -perm Oo Cm - Ns | Ns Cm + Oc Ns Ar mode
749The
750.Ar mode
751may be either symbolic (see
752.Xr chmod 1 )
753or an octal number.
754If the
755.Ar mode
756is symbolic, a starting value of zero is assumed and the
757.Ar mode
758sets or clears permissions without regard to the process' file mode
759creation mask.
760If the
761.Ar mode
762is octal, only bits 07777
763.Pq Dv S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO
764of the file's mode bits participate
765in the comparison.
766If the
767.Ar mode
768is preceded by a dash
769.Pq Dq Li - ,
770this primary evaluates to true
771if at least all of the bits in the
772.Ar mode
773are set in the file's mode bits.
774If the
775.Ar mode
776is preceded by a plus
777.Pq Dq Li + ,
778this primary evaluates to true
779if any of the bits in the
780.Ar mode
781are set in the file's mode bits.
782Otherwise, this primary evaluates to true if
783the bits in the
784.Ar mode
785exactly match the file's mode bits.
786Note, the first character of a symbolic mode may not be a dash
787.Pq Dq Li - .
788.It Ic -print
789This primary always evaluates to true.
790It prints the pathname of the current file to standard output.
791If none of
792.Ic -exec , -ls , -print0 ,
793or
794.Ic -ok
795is specified, the given expression shall be effectively replaced by
796.Cm \&( Ar "given expression" Cm \&) Ic -print .
797.It Ic -print0
798This primary always evaluates to true.
799It prints the pathname of the current file to standard output, followed by an
800.Xr ASCII 8
801.Dv NUL
802character (character code 0).
803.It Ic -prune
804This primary always evaluates to true.
805It causes
806.Nm
807to not descend into the current file.
808Note, the
809.Ic -prune
810primary has no effect if the
811.Fl d
812option was specified.
813.It Ic -quit
814Causes
815.Nm
816to terminate immediately.
817.It Ic -regex Ar pattern
818True if the whole path of the file matches
819.Ar pattern
820using regular expression.
821To match a file named
822.Dq Pa ./foo/xyzzy ,
823you can use the regular expression
824.Dq Li ".*/[xyz]*"
825or
826.Dq Li ".*/foo/.*" ,
827but not
828.Dq Li xyzzy
829or
830.Dq Li /foo/ .
831.It Ic -samefile Ar name
832True if the file is a hard link to
833.Ar name .
834If the command option
835.Ic -L
836is specified, it is also true if the file is a symbolic link and
837points to
838.Ar name .
839.It Ic -size Ar n Ns Op Cm ckMGTP
840True if the file's size, rounded up, in 512-byte blocks is
841.Ar n .
842If
843.Ar n
844is followed by a
845.Cm c ,
846then the primary is true if the
847file's size is
848.Ar n
849bytes (characters).
850Similarly if
851.Ar n
852is followed by a scale indicator then the file's size is compared to
853.Ar n
854scaled as:
855.Pp
856.Bl -tag -width indent -compact
857.It Cm k
858kilobytes (1024 bytes)
859.It Cm M
860megabytes (1024 kilobytes)
861.It Cm G
862gigabytes (1024 megabytes)
863.It Cm T
864terabytes (1024 gigabytes)
865.It Cm P
866petabytes (1024 terabytes)
867.El
868.It Ic -sparse
869True if the current file is sparse,
870i.e. has fewer blocks allocated than expected based on its size in bytes.
871This might also match files that have been compressed by the filesystem.
872.It Ic -type Ar t
873True if the file is of the specified type.
874Possible file types are as follows:
875.Pp
876.Bl -tag -width indent -compact
877.It Cm b
878block special
879.It Cm c
880character special
881.It Cm d
882directory
883.It Cm f
884regular file
885.It Cm l
886symbolic link
887.It Cm p
888FIFO
889.It Cm s
890socket
891.El
892.It Ic -uid Ar uname
893The same thing as
894.Ar -user Ar uname
895for compatibility with GNU find.
896GNU find imposes a restriction that
897.Ar uname
898is numeric, while
899.Nm
900does not.
901.It Ic -user Ar uname
902True if the file belongs to the user
903.Ar uname .
904If
905.Ar uname
906is numeric and there is no such user name, then
907.Ar uname
908is treated as a user ID.
909.It Ic -wholename Ar pattern
910The same thing as
911.Ic -path ,
912for GNU find compatibility.
913.El
914.Sh OPERATORS
915The primaries may be combined using the following operators.
916The operators are listed in order of decreasing precedence.
917.Pp
918.Bl -tag -width indent -compact
919.It Cm \&( Ar expression Cm \&)
920This evaluates to true if the parenthesized expression evaluates to
921true.
922.Pp
923.It Cm \&! Ar expression
924.It Cm -not Ar expression
925This is the unary
926.Tn NOT
927operator.
928It evaluates to true if the expression is false.
929.Pp
930.It Cm -false
931Always false.
932.It Cm -true
933Always true.
934.Pp
935.It Ar expression Cm -and Ar expression
936.It Ar expression expression
937The
938.Cm -and
939operator is the logical
940.Tn AND
941operator.
942As it is implied by the juxtaposition of two expressions it does not
943have to be specified.
944The expression evaluates to true if both expressions are true.
945The second expression is not evaluated if the first expression is false.
946.Pp
947.It Ar expression Cm -or Ar expression
948The
949.Cm -or
950operator is the logical
951.Tn OR
952operator.
953The expression evaluates to true if either the first or the second expression
954is true.
955The second expression is not evaluated if the first expression is true.
956.El
957.Pp
958All operands and primaries must be separate arguments to
959.Nm .
960Primaries which themselves take arguments expect each argument
961to be a separate argument to
962.Nm .
963.Sh ENVIRONMENT
964The
965.Ev LANG , LC_ALL , LC_COLLATE , LC_CTYPE , LC_MESSAGES
966and
967.Ev LC_TIME
968environment variables affect the execution of the
969.Nm
970utility as described in
971.Xr environ 7 .
972.Sh EXAMPLES
973The following examples are shown as given to the shell:
974.Bl -tag -width indent
975.It Li "find / \e! -name \*q*.c\*q -print"
976Print out a list of all the files whose names do not end in
977.Pa .c .
978.It Li "find / -newer ttt -user wnj -print"
979Print out a list of all the files owned by user
980.Dq wnj
981that are newer
982than the file
983.Pa ttt .
984.It Li "find / \e! \e( -newer ttt -user wnj \e) -print"
985Print out a list of all the files which are not both newer than
986.Pa ttt
987and owned by
988.Dq wnj .
989.It Li "find / \e( -newer ttt -or -user wnj \e) -print"
990Print out a list of all the files that are either owned by
991.Dq wnj
992or that are newer than
993.Pa ttt .
994.It Li "find / -newerct '1 minute ago' -print"
995Print out a list of all the files whose inode change time is more
996recent than the current time minus one minute.
997.It Li "find / -type f -exec echo {} \e;"
998Use the
999.Xr echo 1
1000command to print out a list of all the files.
1001.It Li "find -L /usr/ports/packages -type l -exec rm -- {} +"
1002Delete all broken symbolic links in
1003.Pa /usr/ports/packages .
1004.It Li "find /usr/src -name CVS -prune -o -depth +6 -print"
1005Find files and directories that are at least seven levels deep
1006in the working directory
1007.Pa /usr/src .
1008.It Li "find /usr/src -name CVS -prune -o -mindepth 7 -print"
1009Is not equivalent to the previous example, since
1010.Ic -prune
1011is not evaluated below level seven.
1012.El
1013.Sh COMPATIBILITY
1014The
1015.Ic -follow
1016primary is deprecated; the
1017.Fl L
1018option should be used instead.
1019See the
1020.Sx STANDARDS
1021section below for details.
1022.Sh SEE ALSO
1023.Xr chflags 1 ,
1024.Xr chmod 1 ,
1025.Xr locate 1 ,
1026.Xr lsvfs 1 ,
1027.Xr whereis 1 ,
1028.Xr which 1 ,
1029.Xr xargs 1 ,
1030.Xr stat 2 ,
1031.Xr acl 3 ,
1032.Xr fts 3 ,
1033.Xr getgrent 3 ,
1034.Xr getpwent 3 ,
1035.Xr strmode 3 ,
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