2 .\" Copyright 1989 AT&T
3 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
4 .\" Copyright 2011 Nexenta Systems, Inc. All rights reserved.
5 .\" Copyright (c) 2013 Andrew Stormont. All rights reserved.
6 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
8 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
9 .\" permission to reproduce portions of its copyrighted documentation.
10 .\" Original documentation from The Open Group can be obtained online at
11 .\" http://www.opengroup.org/bookstore/.
12 .\" The Institute of Electrical and Electronics Engineers and The Open Group,
13 .\" have given us permission to reprint portions of their documentation.
14 .\" In the following statement, the phrase "this text" refers to portions of
15 .\" the system documentation. Portions of this text are reprinted and
16 .\" reproduced in electronic form in the Sun OS Reference Manual, from
17 .\" IEEE Std 1003.1, 2004 Edition, Standard for Information Technology --
18 .\" Portable Operating System Interface (POSIX), The Open Group Base
19 .\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of
20 .\" Electrical and Electronics Engineers, Inc and The Open Group. In the event
21 .\" of any discrepancy between these versions and the original IEEE and
22 .\" The Open Group Standard, the original IEEE and The Open Group Standard
23 .\" is the referee document. The original Standard can be obtained online
24 .\" at http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
26 .\" The contents of this file are subject to the terms of the Common Development
27 .\" and Distribution License (the "License"). You may not use this file except
28 .\" in compliance with the License.
29 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or
30 .\" http://www.opensolaris.org/os/licensing. See the License for the specific
31 .\" language governing permissions and limitations under the License.
32 .\" When distributing Covered Code, include this CDDL HEADER in each file and
33 .\" include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable,
34 .\" add the following below this CDDL HEADER, with the fields enclosed by
35 .\" brackets "[]" replaced with your own identifying information:
36 .\" Portions Copyright [yyyy] [name of copyright owner]
37 .TH FIND 1 "Sep 5, 2011"
43 \fB/usr/bin/find\fR [\fB-E\fR] [\fB-H\fR | \fB-L\fR] \fIpath\fR... \fIexpression\fR
48 \fB/usr/xpg4/bin/find\fR [\fB-H\fR | \fB-L\fR] \fIpath\fR... \fIexpression\fR
54 The \fBfind\fR utility recursively descends the directory hierarchy for each
55 \fIpath\fR seeking files that match a Boolean \fIexpression\fR written in the
56 primaries specified below.
59 \fBfind\fR is able to descend to arbitrary depths in a file hierarchy and does
60 not fail due to path length limitations (unless a \fIpath\fR operand specified
61 by the application exceeds \fIPATH_MAX\fR requirements).
64 \fBfind\fR detects infinite loops; that is, entering a previously visited
65 directory that is an ancestor of the last file encountered.
69 The following options are supported:
76 Interpret regular expressions followed by \fB-regex\fR and \fB-iregex\fR
77 primaries as extended regular expressions.
86 Causes the file information and file type evaluated for each symbolic link
87 encountered on the command line to be those of the file referenced by the link,
88 and not the link itself. If the referenced file does not exist, the file
89 information and type is for the link itself. File information for all symbolic
90 links not on the command line is that of the link itself.
99 Causes the file information and file type evaluated for each symbolic link to
100 be those of the file referenced by the link, and not the link itself. See
106 Specifying more than one of the mutually-exclusive options \fB-H\fR and
107 \fB-L\fR is not considered an error. The last option specified determines the
108 behavior of the utility.
112 The following operands are supported:
119 A pathname of a starting point in the directory hierarchy.
125 \fB\fIexpression\fR\fR
128 The first argument that starts with a \fB\(mi\fR, or is a \fB!\fR or a \fB(\fR,
129 and all subsequent arguments are interpreted as an \fIexpression\fR made up of
130 the following primaries and operators. In the descriptions, wherever \fIn\fR is
131 used as a primary argument, it is interpreted as a decimal integer optionally
132 preceded by a plus (\fB+\fR) or minus (\fB\(mi\fR) sign, as follows:
165 Valid expressions are:
172 True if the file have additional ACLs defined.
178 \fB\fB-amin\fR \fIn\fR\fR
181 File was last accessed \fIn\fR minutes ago.
187 \fB\fB-atime\fR \fIn\fR\fR
190 True if the file was accessed \fIn\fR days ago. The access time of directories
191 in \fIpath\fR is changed by \fBfind\fR itself.
197 \fB\fB-cmin\fR \fIn\fR\fR
200 File's status was last changed \fIn\fR minutes ago.
206 \fB\fB-cpio\fR \fIdevice\fR\fR
209 Always true. Writes the current file on \fIdevice\fR in \fBcpio\fR format
216 \fB\fB-ctime\fR \fIn\fR\fR
219 True if the file's status was changed \fIn\fR days ago.
228 Always true. Causes descent of the directory hierarchy to be done so that all
229 entries in a directory are acted on before the directory itself. This can be
230 useful when \fBfind\fR is used with \fBcpio\fR(1) to transfer files that are
231 contained in directories without write permission.
237 \fB\fB-exec\fR \fIcommand\fR\fR
240 True if the executed command returns a zero value as exit status. The end of
241 command must be punctuated by an escaped semicolon (\fB;\fR). A command
242 argument \fB{}\fR is replaced by the current pathname. If the last argument to
243 \fB-exec\fR is \fB{}\fR and you specify \fB+\fR rather than the semicolon
244 (\fB;\fR), the command is invoked fewer times, with \fB{}\fR replaced by groups
245 of pathnames. If any invocation of the command returns a non-zero value as exit
246 status, find returns a non-zero exit status.
255 Always true and always evaluated no matter where it appears in
256 \fIexpression\fR. The behavior is unspecified if \fB-follow\fR is used when the
257 \fBfind\fR command is invoked with either the \fB-H\fR or the \fB-L\fR option.
258 Causes symbolic links to be followed. When following symbolic links, \fBfind\fR
259 keeps track of the directories visited so that it can detect infinite loops.
260 For example, such a loop would occur if a symbolic link pointed to an ancestor.
261 This expression should not be used with the find-type \fBl\fR expression. See
268 \fB\fB-fstype\fR \fItype\fR\fR
271 True if the filesystem to which the file belongs is of type \fItype\fR.
277 \fB\fB-group\fR \fIgname\fR\fR
280 True if the file belongs to the group \fIgname\fR. If \fIgname\fR is numeric
281 and there's no such group name, it is taken as a group \fBID\fR.
287 \fB\fB-groupacl\fR \fIgname\fR\fR
290 True if the file's ACL contains an entry for the group \fIgname\fR.
291 If \fIgname\fR is numeric and there's no such group name, it is taken
298 \fB\fB-iname\fR \fIpattern\fR\fR
301 Like \fB-name\fR, but the match is case insensitive.
307 \fB\fB-inum\fR \fIn\fR\fR
310 True if the file has inode number \fIn\fR.
316 \fB\fB-ipath\fR \fIpattern\fR\fR
319 Like \fB-path\fR, but the match is case insensitive.
325 \fB\fB-iregex\fR \fIpattern\fR\fR
328 Like \fB-regex\fR, but the match is case insensitive.
334 \fB\fB-links\fR \fIn\fR\fR
337 True if the file has \fIn\fR links.
346 True if the file system type is not a remote file system type as defined in the
347 \fB/etc/dfs/fstypes\fR file. \fBnfs\fR is used as the default remote filesystem
348 type if the \fB/etc/dfs/fstypes\fR file is not present. The \fB-local\fR option
349 descends the hierarchy of non-local directories. See \fBEXAMPLES\fR for an
350 example of how to search for local files without descending.
359 Always true. Prints current pathname together with its associated statistics.
360 These include (respectively):
371 size in kilobytes (1024 bytes)
409 If the file is a special file, the size field instead contains the major and
410 minor device numbers.
412 If the file is a symbolic link, the pathname of the linked-to file is printed
413 preceded by `\fB\(->\fR\&'. The format is identical to that of \fBls\fR
414 \fB-gilds\fR (see \fBls\fR(1B)).
416 Formatting is done internally, without executing the \fBls\fR program.
422 \fB\fB-maxdepth\fR \fIn\fR\fR
425 Always true; descend at most \fIn\fR directory levels below the command
426 line arguments. If any \fB-maxdepth\fR primary is specified, it
427 applies to the entire expression even if it would not normally be
428 evaluated. \fB-maxdepth 0\fR limits the whole search to
429 the command line arguments.
435 \fB\fB-mindepth\fR \fIn\fR\fR
438 Always true; do not apply any tests or actions at levels less
439 than \fIn\fR. If any \fB-mindepth\fR primary is specified, it applies to the
440 entire expression even if it would not normally be evaluated.
441 \fB-mindepth 1\fR processes all but the command line arguments.
447 \fB\fB-mmin\fR \fIn\fR\fR
450 File's data was last modified \fIn\fR minutes ago.
459 Always true. Restricts the search to the file system containing the directory
460 specified. Does not list mount points to other file systems.
466 \fB\fB-mtime\fR \fIn\fR\fR
469 True if the file's data was modified \fIn\fR days ago.
475 \fB\fB-name\fR \fIpattern\fR\fR
478 True if \fIpattern\fR matches the basename of the current file name. Normal
479 shell file name generation characters (see \fBsh\fR(1)) can be used. A
480 backslash (\fB\|\e\|\fR) is used as an escape character within the pattern. The
481 pattern should be escaped or quoted when \fBfind\fR is invoked from the shell.
483 Unless the character '\fB\&.\fR' is explicitly specified in the beginning of
484 \fIpattern\fR, a current file name beginning with '\fB\&.\fR' does not match
485 \fIpattern\fR when using \fB/usr/bin/find\fR. \fB/usr/xpg4/bin/find\fR does not
486 make this distinction; wildcard file name generation characters can match file
487 names beginning with '\fB\&.\fR'.
493 \fB\fB-ncpio\fR \fIdevice\fR\fR
496 Always true. Writes the current file on \fIdevice\fR in \fBcpio\fR \fB-c\fR
497 format (5120 byte records).
503 \fB\fB-newer\fR \fIfile\fR\fR
506 True if the current file has been modified more recently than the argument
516 True if the file belongs to non-existing group.
525 True if the file belongs to non-existing user.
531 \fB\fB-ok\fR \fIcommand\fR\fR
534 Like \fB-exec\fR, except that the generated command line is printed with a
535 question mark first, and is executed only if the response is affirmative.
544 Like \fB-name\fR, but matches the entire file path and not just basename.
550 \fB\fB-perm\fR [\fB-\fR]\fImode\fR\fR
553 The \fImode\fR argument is used to represent file mode bits. It is identical in
554 format to the symbolic mode operand, \fIsymbolic_mode_list\fR, described in
555 \fBchmod\fR(1), and is interpreted as follows. To start, a template is assumed
556 with all file mode bits cleared. An \fIop\fR symbol of:
563 Set the appropriate mode bits in the template
572 Clear the appropriate bits
581 Set the appropriate mode bits, without regard to the contents of the file mode
582 creation mask of the process
585 The \fIop\fR symbol of \fB\(mi\fR cannot be the first character of \fImode\fR,
586 to avoid ambiguity with the optional leading hyphen. Since the initial mode is
587 all bits off, there are no symbolic modes that need to use \fB\(mi\fR as the
590 If the hyphen is omitted, the primary evaluates as true when the file
591 permission bits exactly match the value of the resulting template.
593 Otherwise, if \fImode\fR is prefixed by a hyphen, the primary evaluates as true
594 if at least all the bits in the resulting template are set in the file
601 \fB\fB-perm\fR [\fB-\fR]\fIonum\fR\fR
604 True if the file permission flags exactly match the octal number \fIonum\fR
605 (see \fBchmod\fR(1)). If \fIonum\fR is prefixed by a minus sign (\fB\(mi\fR),
606 only the bits that are set in \fIonum\fR are compared with the file permission
607 flags, and the expression evaluates true if they match.
616 Always true. Causes the current pathname to be printed.
625 Always true. Causes the current pathname to be printed, terminated by an ASCII
626 NUL character (character code 0) instead of a newline.
635 Always yields true. Does not examine any directories or files in the directory
636 structure below the \fIpattern\fR just matched. (See EXAMPLES). If \fB-depth\fR
637 is specified, \fB-prune\fR has no effect.
643 \fB\fB-regex\fR \fIpattern\fR\fB
646 True if the full path of the file matches \fIpattern\fR using regular
653 \fB\fB-size\fR \fIn\fR[\fBc\fR]\fR
656 True if the file is \fIn\fR blocks long (512 bytes per block). If \fIn\fR is
657 followed by a \fBc\fR, the size is in bytes.
663 \fB\fB-type\fR \fIc\fR\fR
666 True if the type of the file is \fIc\fR, where \fIc\fR is \fBb\fR, \fBc\fR,
667 \fBd\fR, \fBD\fR, \fBf\fR, \fBl\fR, \fBp\fR, or \fBs\fR for block special file,
668 character special file, directory, door, plain file, symbolic link, fifo (named
669 pipe), or socket, respectively.
675 \fB\fB-user\fR \fIuname\fR\fR
678 True if the file belongs to the user \fIuname\fR. If \fIuname\fR is numeric and
679 there's no such user name, it is taken as a user \fBID\fR.
685 \fB\fB-useracl\fR \fIuname\fR\fR
688 True if the file's ACL contains an entry for the user \fIuname\fR.
689 If \fIuname\fR is numeric and there's no such user name, it is
690 taken as a user \fBID\fR.
699 Same as the \fB-mount\fR primary.
708 True if the file has extended attributes.
711 .SS "Complex Expressions"
714 The primaries can be combined using the following operators (in order of
715 decreasing precedence):
719 \fB1)\fB(\fR\fIexpression\fR\fB)\fR\fR
723 True if the parenthesized expression is true (parentheses are special to the
724 shell and must be escaped).
730 \fB2)\fB!\fR\fIexpression\fR\fR
734 The negation of a primary (\fB!\fR is the unary \fInot\fR operator).
740 \fB3) \fIexpression\fR\fB[\fR\fB-a\fR\fB]\fR \fIexpression\fR\fR
744 Concatenation of primaries (the \fIand\fR operation is implied by the
745 juxtaposition of two primaries).
751 \fB4) \fIexpression\fR\fB\fR\fB-o\fR\fIexpression\fR\fR
755 Alternation of primaries (\fB-o\fR is the \fIor\fR operator).
760 When you use \fBfind\fR in conjunction with \fBcpio\fR, if you use the \fB-L\fR
761 option with \fBcpio\fR, you must use the \fB-L\fR option or the \fB-follow\fR
762 primitive with \fBfind\fR and vice versa. Otherwise the results are
766 If no \fIexpression\fR is present, \fB-print\fR is used as the expression.
767 Otherwise, if the specified expression does not contain any of the primaries
768 \fB-exec\fR, \fB-ok\fR, \fB-ls\fR, or \fB-print\fR, the specified expression is
769 effectively replaced by:
772 (\fIspecified\fR) \fB-print\fR
775 The \fB-user\fR, \fB-group\fR, and \fB-newer\fR primaries each evaluate their
776 respective arguments only once. Invocation of \fIcommand\fR specified by
777 \fB-exec\fR or \fB-ok\fR does not affect subsequent primaries on the same file.
781 See \fBlargefile\fR(5) for the description of the behavior of \fBfind\fR when
782 encountering files greater than or equal to 2 Gbyte (2^31 bytes).
785 \fBExample 1 \fRWriting Out the Hierarchy Directory
788 The following commands are equivalent:
793 example% \fBfind .\fR
794 example% \fBfind . -print\fR
801 They both write out the entire directory hierarchy from the current directory.
804 \fBExample 2 \fRRemoving Files
807 The following comand removes all files in your home directory named \fBa.out\fR
808 or \fB*.o\fR that have not been accessed for a week:
813 example% \fBfind $HOME \e( -name a.out -o -name '*.o' \e) \e
814 -atime +7 -exec rm {} \e;\fR
820 \fBExample 3 \fRPrinting All File Names But Skipping SCCS Directories
823 The following command recursively print all file names in the current directory
824 and below, but skipping \fBSCCS\fR directories:
829 example% \fBfind . -name SCCS -prune -o -print\fR
835 \fBExample 4 \fRPrinting all file names and the SCCS directory name
838 Recursively print all file names in the current directory and below, skipping
839 the contents of \fBSCCS\fR directories, but printing out the \fBSCCS\fR
845 example% \fBfind . -print -name SCCS -prune\fR
851 \fBExample 5 \fRTesting for the Newer File
854 The following command is basically equivalent to the \fB-nt\fR extension to
860 example$ \fBif [ -n "$(find
861 file1 -prune -newer file2)" ]; then
863 printf %s\e\en "file1 is newer than file2"\fR
869 \fBExample 6 \fRSelecting a File Using 24-hour Mode
872 The descriptions of \fB-atime\fR, \fB-ctime\fR, and \fB-mtime\fR use the
873 terminology \fIn\fR ``24-hour periods''. For example, a file accessed at 23:59
879 example% \fBfind . -atime -1 -print\fR
886 at 00:01 the next day (less than 24 hours later, not more than one day ago).
887 The midnight boundary between days has no effect on the 24-hour calculation.
890 \fBExample 7 \fRPrinting Files Matching a User's Permission Mode
893 The following command recursively print all file names whose permission mode
894 exactly matches read, write, and execute access for user, and read and execute
895 access for group and other:
900 example% \fBfind . -perm u=rwx,g=rx,o=rx\fR
907 The above could alternatively be specified as follows:
912 example% \fBfind . -perm a=rwx,g-w,o-w\fR
918 \fBExample 8 \fRPrinting Files with Write Access for \fBother\fR
921 The following command recursively print all file names whose permission
922 includes, but is not limited to, write access for other:
927 example% \fBfind . -perm -o+w\fR
933 \fBExample 9 \fRPrinting Local Files without Descending Non-local Directories
937 example% \fBfind . ! -local -prune -o -print\fR
943 \fBExample 10 \fRPrinting the Files in the Name Space Possessing Extended
948 example% \fBfind . -xattr\fR
953 .SH ENVIRONMENT VARIABLES
956 See \fBenviron\fR(5) for descriptions of the following environment variables
957 that affect the execution of \fBfind\fR: \fBLANG\fR, \fBLC_ALL\fR,
958 \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
965 Determine the location of the \fIutility_name\fR for the \fB-exec\fR and
971 Affirmative responses are processed using the extended regular expression
972 defined for the \fByesexpr\fR keyword in the \fBLC_MESSAGES\fR category of the
973 user's locale. The locale specified in the \fBLC_COLLATE\fR category defines
974 the behavior of ranges, equivalence classes, and multi-character collating
975 elements used in the expression defined for \fByesexpr\fR. The locale specified
976 in \fBLC_CTYPE\fR determines the locale for interpretation of sequences of
977 bytes of text data a characters, the behavior of character classes used in the
978 expression defined for the \fByesexpr\fR. See \fBlocale\fR(5).
982 The following exit values are returned:
989 All \fIpath\fR operands were traversed successfully.
1005 \fB\fB/etc/passwd\fR\fR
1014 \fB\fB/etc/group\fR\fR
1023 \fB\fB/etc/dfs/fstypes\fR\fR
1026 File that registers distributed file system packages
1032 See \fBattributes\fR(5) for descriptions of the following attributes:
1040 ATTRIBUTE TYPE ATTRIBUTE VALUE
1044 Interface Stability Committed
1046 Standard See \fBstandards\fR(5).
1052 \fBchmod\fR(1), \fBcpio\fR(1), \fBsh\fR(1), \fBtest\fR(1), \fBls\fR(1B),
1053 \fBacl\fR(5), \fBregex\fR(5), \fBstat\fR(2), \fBumask\fR(2),
1054 \fBattributes\fR(5), \fBenviron\fR(5), \fBfsattr\fR(5), \fBlargefile\fR(5),
1055 \fBlocale\fR(5), \fBstandards\fR(5)
1059 The following options are obsolete and will not be supported in future
1064 \fB\fB-cpio\fR \fIdevice\fR\fR
1067 Always true. Writes the current file on \fIdevice\fR in \fBcpio\fR format
1068 (5120-byte records).
1074 \fB\fB-ncpio\fR \fIdevice\fR\fR
1077 Always true. Writes the current file on \fIdevice\fR in \fBcpio\fR \fB-c\fR
1078 format (5120-byte records).
1084 When using \fBfind\fR to determine files modified within a range of time, use
1085 the \fB-mtime\fR argument \fBbefore\fR the \fB-print\fR argument. Otherwise,
1086 \fBfind\fR gives all files.
1089 Some files that might be under the Solaris root file system are actually mount
1090 points for virtual file systems, such as \fBmntfs\fR or \fBnamefs\fR. When
1091 comparing against a \fBufs\fR file system, such files are not selected if
1092 \fB-mount\fR or \fB-xdev\fR is specified in the \fBfind\fR expression.
1095 Using the \fB-L\fR or \fB-follow\fR option is not recommended when descending a
1096 file-system hierarchy that is under the control of other users. In particular,
1097 when using \fB-exec\fR, symbolic links can lead the \fBfind\fR command out of
1098 the hierarchy in which it started. Using \fB-type\fR is not sufficient to
1099 restrict the type of files on which the \fB-exec\fR command operates, because
1100 there is an inherent race condition between the type-check performed by the
1101 \fBfind\fR command and the time the executed command operates on the file