FIND(1) | User Commands | FIND(1) |
find - find files
/usr/bin/find [-E] [-H | -L] path... expression
/usr/xpg4/bin/find [-H | -L] path... expression
The find utility recursively descends the directory hierarchy for each path seeking files that match a Boolean expression written in the primaries specified below.
find is able to descend to arbitrary depths in a file hierarchy and does not fail due to path length limitations (unless a path operand specified by the application exceeds PATH_MAX requirements).
find detects infinite loops; that is, entering a previously visited directory that is an ancestor of the last file encountered.
The following options are supported:
-E
-H
-L
Specifying more than one of the mutually-exclusive options -H and -L is not considered an error. The last option specified determines the behavior of the utility.
The following operands are supported:
path
expression
+n
n
-n
Valid expressions are:
-acl
-amin n
-atime n
-cmin n
-cpio device
-ctime n
-delete
-depth
-exec command
-follow
-fstype type
-group gname
-groupacl gname
-iname pattern
-inum n
-ipath pattern
-iregex pattern
-links n
-local
-ls
If the file is a symbolic link, the pathname of the linked-to file is printed preceded by `→'. The format is identical to that of ls -gilds (see ls(1B)).
Formatting is done internally, without executing the ls program.
-maxdepth n
-mindepth n
-mmin n
-mount
-mtime n
-name pattern
Unless the character '.' is explicitly specified in the beginning of pattern, a current file name beginning with '.' does not match pattern when using /usr/bin/find. /usr/xpg4/bin/find does not make this distinction; wildcard file name generation characters can match file names beginning with '.'.
-ncpio device
-newer file
-nogroup
-nouser
-ok command
-path
-perm [-]mode
+
−
=
The op symbol of − cannot be the first character of mode, to avoid ambiguity with the optional leading hyphen. Since the initial mode is all bits off, there are no symbolic modes that need to use − as the first character.
If the hyphen is omitted, the primary evaluates as true when the file permission bits exactly match the value of the resulting template.
Otherwise, if mode is prefixed by a hyphen, the primary evaluates as true if at least all the bits in the resulting template are set in the file permission bits.
-perm [-]onum
-print0
-prune
-regex pattern
-size n[c]
-type c
-user uname
-useracl uname
-xdev
-xattr
The primaries can be combined using the following operators (in order of decreasing precedence):
1)(expression)
2)!expression
3) expression[-a] expression
4) expression-oexpression
When you use find in conjunction with cpio, if you use the -L option with cpio, you must use the -L option or the -follow primitive with find and vice versa. Otherwise the results are unspecified.
If no expression is present, -print is used as the expression. Otherwise, if the specified expression does not contain any of the primaries -exec, -ok, -ls, or -print, the specified expression is effectively replaced by:
(specified) -print
The -user, -group, and -newer primaries each evaluate their respective arguments only once. Invocation of command specified by -exec or -ok does not affect subsequent primaries on the same file.
See largefile(7) for the description of the behavior of find when encountering files greater than or equal to 2 Gbyte (2^31 bytes).
Example 1 Writing Out the Hierarchy Directory
The following commands are equivalent:
example% find . example% find . -print
They both write out the entire directory hierarchy from the current directory.
Example 2 Removing Files
The following command removes all files in your home directory named a.out or *.o that have not been accessed for a week:
example% find $HOME \( -name a.out -o -name '*.o' \) \
-atime +7 -exec rm {} \;
Example 3 Printing All File Names But Skipping SCCS Directories
The following command recursively print all file names in the current directory and below, but skipping SCCS directories:
example% find . -name SCCS -prune -o -print
Example 4 Printing all file names and the SCCS directory name
Recursively print all file names in the current directory and below, skipping the contents of SCCS directories, but printing out the SCCS directory name:
example% find . -print -name SCCS -prune
Example 5 Testing for the Newer File
The following command is basically equivalent to the -nt extension to test(1):
example$ if [ -n "$(find file1 -prune -newer file2)" ]; then printf %s\\n "file1 is newer than file2"
Example 6 Selecting a File Using 24-hour Mode
The descriptions of -atime, -ctime, and -mtime use the terminology n ``24-hour periods''. For example, a file accessed at 23:59 is selected by:
example% find . -atime -1 -print
at 00:01 the next day (less than 24 hours later, not more than one day ago). The midnight boundary between days has no effect on the 24-hour calculation.
Example 7 Printing Files Matching a User's Permission Mode
The following command recursively print all file names whose permission mode exactly matches read, write, and execute access for user, and read and execute access for group and other:
example% find . -perm u=rwx,g=rx,o=rx
The above could alternatively be specified as follows:
example% find . -perm a=rwx,g-w,o-w
Example 8 Printing Files with Write Access for other
The following command recursively print all file names whose permission includes, but is not limited to, write access for other:
example% find . -perm -o+w
Example 9 Printing Local Files without Descending Non-local Directories
example% find . ! -local -prune -o -print
Example 10 Printing the Files in the Name Space Possessing Extended Attributes
example% find . -xattr
See environ(7) for descriptions of the following environment variables that affect the execution of find: LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, and NLSPATH.
PATH
Affirmative responses are processed using the extended regular expression defined for the yesexpr keyword in the LC_MESSAGES category of the user's locale. The locale specified in the LC_COLLATE category defines the behavior of ranges, equivalence classes, and multi-character collating elements used in the expression defined for yesexpr. The locale specified in LC_CTYPE determines the locale for interpretation of sequences of bytes of text data a characters, the behavior of character classes used in the expression defined for the yesexpr. See locale(7).
The following exit values are returned:
0
>0
/etc/passwd
/etc/group
/etc/dfs/fstypes
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
CSI | Enabled |
Interface Stability | Committed |
Standard | See standards(7). |
chmod(1), cpio(1), sh(1), test(1), ls(1B), stat(2), umask(2), acl(7), attributes(7), environ(7), fsattr(7), largefile(7), locale(7), regex(7), standards(7)
The following options are obsolete and will not be supported in future releases:
-cpio device
-ncpio device
When using find to determine files modified within a range of time, use the -mtime argument before the -print argument. Otherwise, find gives all files.
Some files that might be under the Solaris root file system are actually mount points for virtual file systems, such as mntfs or namefs. When comparing against a ufs file system, such files are not selected if -mount or -xdev is specified in the find expression.
Using the -L or -follow option is not recommended when descending a file-system hierarchy that is under the control of other users. In particular, when using -exec, symbolic links can lead the find command out of the hierarchy in which it started. Using -type is not sufficient to restrict the type of files on which the -exec command operates, because there is an inherent race condition between the type-check performed by the find command and the time the executed command operates on the file argument.
August 23, 2020 | OmniOS |