2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
43 .\" Copyright 1989 AT&T
44 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
45 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
46 .\" Copyright 2011 Nexenta Systems, Inc. All rights reserved.
47 .\" Copyright (c) 2013 Andrew Stormont. All rights reserved.
49 .TH FIND 1 "Sep 5, 2011"
55 \fB/usr/bin/find\fR [\fB-E\fR] [\fB-H\fR | \fB-L\fR] \fIpath\fR... \fIexpression\fR
60 \fB/usr/xpg4/bin/find\fR [\fB-H\fR | \fB-L\fR] \fIpath\fR... \fIexpression\fR
66 The \fBfind\fR utility recursively descends the directory hierarchy for each
67 \fIpath\fR seeking files that match a Boolean \fIexpression\fR written in the
68 primaries specified below.
71 \fBfind\fR is able to descend to arbitrary depths in a file hierarchy and does
72 not fail due to path length limitations (unless a \fIpath\fR operand specified
73 by the application exceeds \fIPATH_MAX\fR requirements).
76 \fBfind\fR detects infinite loops; that is, entering a previously visited
77 directory that is an ancestor of the last file encountered.
81 The following options are supported:
88 Interpret regular expressions followed by \fB-regex\fR and \fB-iregex\fR
89 primaries as extended regular expressions.
98 Causes the file information and file type evaluated for each symbolic link
99 encountered on the command line to be those of the file referenced by the link,
100 and not the link itself. If the referenced file does not exist, the file
101 information and type is for the link itself. File information for all symbolic
102 links not on the command line is that of the link itself.
111 Causes the file information and file type evaluated for each symbolic link to
112 be those of the file referenced by the link, and not the link itself. See
118 Specifying more than one of the mutually-exclusive options \fB-H\fR and
119 \fB-L\fR is not considered an error. The last option specified determines the
120 behavior of the utility.
124 The following operands are supported:
131 A pathname of a starting point in the directory hierarchy.
137 \fB\fIexpression\fR\fR
140 The first argument that starts with a \fB\(mi\fR, or is a \fB!\fR or a \fB(\fR,
141 and all subsequent arguments are interpreted as an \fIexpression\fR made up of
142 the following primaries and operators. In the descriptions, wherever \fIn\fR is
143 used as a primary argument, it is interpreted as a decimal integer optionally
144 preceded by a plus (\fB+\fR) or minus (\fB\(mi\fR) sign, as follows:
177 Valid expressions are:
184 True if the file have additional ACLs defined.
190 \fB\fB-amin\fR \fIn\fR\fR
193 File was last accessed \fIn\fR minutes ago.
199 \fB\fB-atime\fR \fIn\fR\fR
202 True if the file was accessed \fIn\fR days ago. The access time of directories
203 in \fIpath\fR is changed by \fBfind\fR itself.
209 \fB\fB-cmin\fR \fIn\fR\fR
212 File's status was last changed \fIn\fR minutes ago.
218 \fB\fB-cpio\fR \fIdevice\fR\fR
221 Always true. Writes the current file on \fIdevice\fR in \fBcpio\fR format
228 \fB\fB-ctime\fR \fIn\fR\fR
231 True if the file's status was changed \fIn\fR days ago.
240 Always true. Causes descent of the directory hierarchy to be done so that all
241 entries in a directory are acted on before the directory itself. This can be
242 useful when \fBfind\fR is used with \fBcpio\fR(1) to transfer files that are
243 contained in directories without write permission.
249 \fB\fB-exec\fR \fIcommand\fR\fR
252 True if the executed command returns a zero value as exit status. The end of
253 command must be punctuated by an escaped semicolon (\fB;\fR). A command
254 argument \fB{}\fR is replaced by the current pathname. If the last argument to
255 \fB-exec\fR is \fB{}\fR and you specify \fB+\fR rather than the semicolon
256 (\fB;\fR), the command is invoked fewer times, with \fB{}\fR replaced by groups
257 of pathnames. If any invocation of the command returns a non-zero value as exit
258 status, find returns a non-zero exit status.
267 Always true and always evaluated no matter where it appears in
268 \fIexpression\fR. The behavior is unspecified if \fB-follow\fR is used when the
269 \fBfind\fR command is invoked with either the \fB-H\fR or the \fB-L\fR option.
270 Causes symbolic links to be followed. When following symbolic links, \fBfind\fR
271 keeps track of the directories visited so that it can detect infinite loops.
272 For example, such a loop would occur if a symbolic link pointed to an ancestor.
273 This expression should not be used with the find-type \fBl\fR expression. See
280 \fB\fB-fstype\fR \fItype\fR\fR
283 True if the filesystem to which the file belongs is of type \fItype\fR.
289 \fB\fB-group\fR \fIgname\fR\fR
292 True if the file belongs to the group \fIgname\fR. If \fIgname\fR is numeric
293 and there's no such group name, it is taken as a group \fBID\fR.
299 \fB\fB-groupacl\fR \fIgname\fR\fR
302 True if the file's ACL contains an entry for the group \fIgname\fR.
303 If \fIgname\fR is numeric and there's no such group name, it is taken
310 \fB\fB-iname\fR \fIpattern\fR\fR
313 Like \fB-name\fR, but the match is case insensitive.
319 \fB\fB-inum\fR \fIn\fR\fR
322 True if the file has inode number \fIn\fR.
328 \fB\fB-ipath\fR \fIpattern\fR\fR
331 Like \fB-path\fR, but the match is case insensitive.
337 \fB\fB-iregex\fR \fIpattern\fR\fR
340 Like \fB-regex\fR, but the match is case insensitive.
346 \fB\fB-links\fR \fIn\fR\fR
349 True if the file has \fIn\fR links.
358 True if the file system type is not a remote file system type as defined in the
359 \fB/etc/dfs/fstypes\fR file. \fBnfs\fR is used as the default remote filesystem
360 type if the \fB/etc/dfs/fstypes\fR file is not present. The \fB-local\fR option
361 descends the hierarchy of non-local directories. See \fBEXAMPLES\fR for an
362 example of how to search for local files without descending.
371 Always true. Prints current pathname together with its associated statistics.
372 These include (respectively):
383 size in kilobytes (1024 bytes)
421 If the file is a special file, the size field instead contains the major and
422 minor device numbers.
424 If the file is a symbolic link, the pathname of the linked-to file is printed
425 preceded by `\fB\(->\fR\&'. The format is identical to that of \fBls\fR
426 \fB-gilds\fR (see \fBls\fR(1B)).
428 Formatting is done internally, without executing the \fBls\fR program.
434 \fB\fB-maxdepth\fR \fIn\fR\fR
437 Always true; descend at most \fIn\fR directory levels below the command
438 line arguments. If any \fB-maxdepth\fR primary is specified, it
439 applies to the entire expression even if it would not normally be
440 evaluated. \fB-maxdepth 0\fR limits the whole search to
441 the command line arguments.
447 \fB\fB-mindepth\fR \fIn\fR\fR
450 Always true; do not apply any tests or actions at levels less
451 than \fIn\fR. If any \fB-mindepth\fR primary is specified, it applies to the
452 entire expression even if it would not normally be evaluated.
453 \fB-mindepth 1\fR processes all but the command line arguments.
459 \fB\fB-mmin\fR \fIn\fR\fR
462 File's data was last modified \fIn\fR minutes ago.
471 Always true. Restricts the search to the file system containing the directory
472 specified. Does not list mount points to other file systems.
478 \fB\fB-mtime\fR \fIn\fR\fR
481 True if the file's data was modified \fIn\fR days ago.
487 \fB\fB-name\fR \fIpattern\fR\fR
490 True if \fIpattern\fR matches the basename of the current file name. Normal
491 shell file name generation characters (see \fBsh\fR(1)) can be used. A
492 backslash (\fB\|\e\|\fR) is used as an escape character within the pattern. The
493 pattern should be escaped or quoted when \fBfind\fR is invoked from the shell.
495 Unless the character '\fB\&.\fR' is explicitly specified in the beginning of
496 \fIpattern\fR, a current file name beginning with '\fB\&.\fR' does not match
497 \fIpattern\fR when using \fB/usr/bin/find\fR. \fB/usr/xpg4/bin/find\fR does not
498 make this distinction; wildcard file name generation characters can match file
499 names beginning with '\fB\&.\fR'.
505 \fB\fB-ncpio\fR \fIdevice\fR\fR
508 Always true. Writes the current file on \fIdevice\fR in \fBcpio\fR \fB-c\fR
509 format (5120 byte records).
515 \fB\fB-newer\fR \fIfile\fR\fR
518 True if the current file has been modified more recently than the argument
528 True if the file belongs to non-existing group.
537 True if the file belongs to non-existing user.
543 \fB\fB-ok\fR \fIcommand\fR\fR
546 Like \fB-exec\fR, except that the generated command line is printed with a
547 question mark first, and is executed only if the response is affirmative.
556 Like \fB-name\fR, but matches the entire file path and not just basename.
562 \fB\fB-perm\fR [\fB-\fR]\fImode\fR\fR
565 The \fImode\fR argument is used to represent file mode bits. It is identical in
566 format to the symbolic mode operand, \fIsymbolic_mode_list\fR, described in
567 \fBchmod\fR(1), and is interpreted as follows. To start, a template is assumed
568 with all file mode bits cleared. An \fIop\fR symbol of:
575 Set the appropriate mode bits in the template
584 Clear the appropriate bits
593 Set the appropriate mode bits, without regard to the contents of the file mode
594 creation mask of the process
597 The \fIop\fR symbol of \fB\(mi\fR cannot be the first character of \fImode\fR,
598 to avoid ambiguity with the optional leading hyphen. Since the initial mode is
599 all bits off, there are no symbolic modes that need to use \fB\(mi\fR as the
602 If the hyphen is omitted, the primary evaluates as true when the file
603 permission bits exactly match the value of the resulting template.
605 Otherwise, if \fImode\fR is prefixed by a hyphen, the primary evaluates as true
606 if at least all the bits in the resulting template are set in the file
613 \fB\fB-perm\fR [\fB-\fR]\fIonum\fR\fR
616 True if the file permission flags exactly match the octal number \fIonum\fR
617 (see \fBchmod\fR(1)). If \fIonum\fR is prefixed by a minus sign (\fB\(mi\fR),
618 only the bits that are set in \fIonum\fR are compared with the file permission
619 flags, and the expression evaluates true if they match.
628 Always true. Causes the current pathname to be printed.
637 Always true. Causes the current pathname to be printed, terminated by an ASCII
638 NUL character (character code 0) instead of a newline.
647 Always yields true. Does not examine any directories or files in the directory
648 structure below the \fIpattern\fR just matched. (See EXAMPLES). If \fB-depth\fR
649 is specified, \fB-prune\fR has no effect.
655 \fB\fB-regex\fR \fIpattern\fR\fB
658 True if the full path of the file matches \fIpattern\fR using regular
665 \fB\fB-size\fR \fIn\fR[\fBc\fR]\fR
668 True if the file is \fIn\fR blocks long (512 bytes per block). If \fIn\fR is
669 followed by a \fBc\fR, the size is in bytes.
675 \fB\fB-type\fR \fIc\fR\fR
678 True if the type of the file is \fIc\fR, where \fIc\fR is \fBb\fR, \fBc\fR,
679 \fBd\fR, \fBD\fR, \fBf\fR, \fBl\fR, \fBp\fR, or \fBs\fR for block special file,
680 character special file, directory, door, plain file, symbolic link, fifo (named
681 pipe), or socket, respectively.
687 \fB\fB-user\fR \fIuname\fR\fR
690 True if the file belongs to the user \fIuname\fR. If \fIuname\fR is numeric and
691 there's no such user name, it is taken as a user \fBID\fR.
697 \fB\fB-useracl\fR \fIuname\fR\fR
700 True if the file's ACL contains an entry for the user \fIuname\fR.
701 If \fIuname\fR is numeric and there's no such user name, it is
702 taken as a user \fBID\fR.
711 Same as the \fB-mount\fR primary.
720 True if the file has extended attributes.
723 .SS "Complex Expressions"
726 The primaries can be combined using the following operators (in order of
727 decreasing precedence):
731 \fB1)\fB(\fR\fIexpression\fR\fB)\fR\fR
735 True if the parenthesized expression is true (parentheses are special to the
736 shell and must be escaped).
742 \fB2)\fB!\fR\fIexpression\fR\fR
746 The negation of a primary (\fB!\fR is the unary \fInot\fR operator).
752 \fB3) \fIexpression\fR\fB[\fR\fB-a\fR\fB]\fR \fIexpression\fR\fR
756 Concatenation of primaries (the \fIand\fR operation is implied by the
757 juxtaposition of two primaries).
763 \fB4) \fIexpression\fR\fB\fR\fB-o\fR\fIexpression\fR\fR
767 Alternation of primaries (\fB-o\fR is the \fIor\fR operator).
772 When you use \fBfind\fR in conjunction with \fBcpio\fR, if you use the \fB-L\fR
773 option with \fBcpio\fR, you must use the \fB-L\fR option or the \fB-follow\fR
774 primitive with \fBfind\fR and vice versa. Otherwise the results are
778 If no \fIexpression\fR is present, \fB-print\fR is used as the expression.
779 Otherwise, if the specified expression does not contain any of the primaries
780 \fB-exec\fR, \fB-ok\fR, \fB-ls\fR, or \fB-print\fR, the specified expression is
781 effectively replaced by:
784 (\fIspecified\fR) \fB-print\fR
787 The \fB-user\fR, \fB-group\fR, and \fB-newer\fR primaries each evaluate their
788 respective arguments only once. Invocation of \fIcommand\fR specified by
789 \fB-exec\fR or \fB-ok\fR does not affect subsequent primaries on the same file.
793 See \fBlargefile\fR(5) for the description of the behavior of \fBfind\fR when
794 encountering files greater than or equal to 2 Gbyte (2^31 bytes).
797 \fBExample 1 \fRWriting Out the Hierarchy Directory
800 The following commands are equivalent:
805 example% \fBfind .\fR
806 example% \fBfind . -print\fR
813 They both write out the entire directory hierarchy from the current directory.
816 \fBExample 2 \fRRemoving Files
819 The following comand removes all files in your home directory named \fBa.out\fR
820 or \fB*.o\fR that have not been accessed for a week:
825 example% \fBfind $HOME \e( -name a.out -o -name '*.o' \e) \e
826 -atime +7 -exec rm {} \e;\fR
832 \fBExample 3 \fRPrinting All File Names But Skipping SCCS Directories
835 The following command recursively print all file names in the current directory
836 and below, but skipping \fBSCCS\fR directories:
841 example% \fBfind . -name SCCS -prune -o -print\fR
847 \fBExample 4 \fRPrinting all file names and the SCCS directory name
850 Recursively print all file names in the current directory and below, skipping
851 the contents of \fBSCCS\fR directories, but printing out the \fBSCCS\fR
857 example% \fBfind . -print -name SCCS -prune\fR
863 \fBExample 5 \fRTesting for the Newer File
866 The following command is basically equivalent to the \fB-nt\fR extension to
872 example$ \fBif [ -n "$(find
873 file1 -prune -newer file2)" ]; then
875 printf %s\e\en "file1 is newer than file2"\fR
881 \fBExample 6 \fRSelecting a File Using 24-hour Mode
884 The descriptions of \fB-atime\fR, \fB-ctime\fR, and \fB-mtime\fR use the
885 terminology \fIn\fR ``24-hour periods''. For example, a file accessed at 23:59
891 example% \fBfind . -atime -1 -print\fR
898 at 00:01 the next day (less than 24 hours later, not more than one day ago).
899 The midnight boundary between days has no effect on the 24-hour calculation.
902 \fBExample 7 \fRPrinting Files Matching a User's Permission Mode
905 The following command recursively print all file names whose permission mode
906 exactly matches read, write, and execute access for user, and read and execute
907 access for group and other:
912 example% \fBfind . -perm u=rwx,g=rx,o=rx\fR
919 The above could alternatively be specified as follows:
924 example% \fBfind . -perm a=rwx,g-w,o-w\fR
930 \fBExample 8 \fRPrinting Files with Write Access for \fBother\fR
933 The following command recursively print all file names whose permission
934 includes, but is not limited to, write access for other:
939 example% \fBfind . -perm -o+w\fR
945 \fBExample 9 \fRPrinting Local Files without Descending Non-local Directories
949 example% \fBfind . ! -local -prune -o -print\fR
955 \fBExample 10 \fRPrinting the Files in the Name Space Possessing Extended
960 example% \fBfind . -xattr\fR
965 .SH ENVIRONMENT VARIABLES
968 See \fBenviron\fR(5) for descriptions of the following environment variables
969 that affect the execution of \fBfind\fR: \fBLANG\fR, \fBLC_ALL\fR,
970 \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
977 Determine the location of the \fIutility_name\fR for the \fB-exec\fR and
983 Affirmative responses are processed using the extended regular expression
984 defined for the \fByesexpr\fR keyword in the \fBLC_MESSAGES\fR category of the
985 user's locale. The locale specified in the \fBLC_COLLATE\fR category defines
986 the behavior of ranges, equivalence classes, and multi-character collating
987 elements used in the expression defined for \fByesexpr\fR. The locale specified
988 in \fBLC_CTYPE\fR determines the locale for interpretation of sequences of
989 bytes of text data a characters, the behavior of character classes used in the
990 expression defined for the \fByesexpr\fR. See \fBlocale\fR(5).
994 The following exit values are returned:
1001 All \fIpath\fR operands were traversed successfully.
1017 \fB\fB/etc/passwd\fR\fR
1026 \fB\fB/etc/group\fR\fR
1035 \fB\fB/etc/dfs/fstypes\fR\fR
1038 File that registers distributed file system packages
1044 See \fBattributes\fR(5) for descriptions of the following attributes:
1052 ATTRIBUTE TYPE ATTRIBUTE VALUE
1056 Interface Stability Committed
1058 Standard See \fBstandards\fR(5).
1064 \fBchmod\fR(1), \fBcpio\fR(1), \fBsh\fR(1), \fBtest\fR(1), \fBls\fR(1B),
1065 \fBacl\fR(5), \fBregex\fR(5), \fBstat\fR(2), \fBumask\fR(2),
1066 \fBattributes\fR(5), \fBenviron\fR(5), \fBfsattr\fR(5), \fBlargefile\fR(5),
1067 \fBlocale\fR(5), \fBstandards\fR(5)
1071 The following options are obsolete and will not be supported in future
1076 \fB\fB-cpio\fR \fIdevice\fR\fR
1079 Always true. Writes the current file on \fIdevice\fR in \fBcpio\fR format
1080 (5120-byte records).
1086 \fB\fB-ncpio\fR \fIdevice\fR\fR
1089 Always true. Writes the current file on \fIdevice\fR in \fBcpio\fR \fB-c\fR
1090 format (5120-byte records).
1096 When using \fBfind\fR to determine files modified within a range of time, use
1097 the \fB-mtime\fR argument \fBbefore\fR the \fB-print\fR argument. Otherwise,
1098 \fBfind\fR gives all files.
1101 Some files that might be under the Solaris root file system are actually mount
1102 points for virtual file systems, such as \fBmntfs\fR or \fBnamefs\fR. When
1103 comparing against a \fBufs\fR file system, such files are not selected if
1104 \fB-mount\fR or \fB-xdev\fR is specified in the \fBfind\fR expression.
1107 Using the \fB-L\fR or \fB-follow\fR option is not recommended when descending a
1108 file-system hierarchy that is under the control of other users. In particular,
1109 when using \fB-exec\fR, symbolic links can lead the \fBfind\fR command out of
1110 the hierarchy in which it started. Using \fB-type\fR is not sufficient to
1111 restrict the type of files on which the \fB-exec\fR command operates, because
1112 there is an inherent race condition between the type-check performed by the
1113 \fBfind\fR command and the time the executed command operates on the file