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