.\" @(#)find.1 1.35 95/10/09 SMI; from SVr4
.\" Copyright 1989 AT&T
.\" Copyright (c) 1995, Sun Microsystems, Inc.
.\" All Rights Reserved
.\" Portions Copyright (c) 1992, X/Open Company Limited
.\" All Rights Reserved
.TH find 1 "1 Feb 1995"
.SH NAME
find \- find files
.SH SYNOPSIS
.B find
.IR path \|.\|.\|.\| expression
.SH AVAILABILITY
.LP
SUNWcsu
.SH DESCRIPTION
.IX "find" "" "\fLfind\fP \(em find files"
.IX "files" "find" "" "\(em \fLfind\fP"
The
\f3find\fP
command recursively descends the directory hierarchy for each
.I path
seeking files that match a Boolean
.I expression
written in the primaries given below.
.LP
.B find
will be able to descend to arbitrary depths
in a file hierarchy and will not fail due to path length
limitations (unless a
.I path
operand specified by the application exceeds
.SB PATH_MAX
requirements).
.SH OPERANDS
The following operands are supported:
.TP 15
.I path
a path name of a starting point in the directory hierarchy.
.LP
The first argument that starts with a
.BR \(mi ,
or is a
.B !
or a
.BR ( ,
and all subsequent arguments will be interpreted as an
.I expression
made up of the following primaries and operators.  In the descriptions, wherever
.I n
is used as a primary argument, it
will be interpreted as a decimal integer optionally preceded by a plus
.RB ( + )
or minus
.RB ( \(mi )
sign, as follows:
.LP
.PD 0
.TP 15
.BI + n
more than
.I n
.TP
.I n
exactly
.I n
.TP
.BI \- n
less than
.IR n .
.PD
.SS Expressions
.LP
Valid expressions are:
.TP 15
\f3\-atime\f2 n\^\f1
True if the file was accessed
.I n
days ago.
The access time of directories in
.I path
is changed by
.B find
itself.
.TP
.BI "\-cpio " device
Always true; write the current file on
.I device
in
.B cpio
format (5120-byte records).
.TP
.BI \-ctime \0n
True if the file's status was changed
.I n
days ago.
.TP
.B \-depth
Always true; causes descent of the directory hierarchy to be done
so that all entries in a directory are acted on
before the directory itself.  This can be useful when
.B find
is used with
.BR cpio (1)
to transfer files that are contained in directories without write permission.
.TP
.BI "\-exec " command
True if the executed
.I command
returns a zero value as exit status.  The end of
.I command
must be punctuated by an escaped semicolon.  A command argument
.B {\|}
is replaced by the current path name.
.TP
.B \-follow
Always true; causes symbolic links to be followed.
When following symbolic links, \f3find\fP keeps track
of the directories visited so that it can detect infinite
loops; for example, such a loop would occur if a symbolic link pointed
to an ancestor.
This expression should not be used with the \f3\-type l\f1 expression.
.br
.ne 3
.TP
.BI "\-fstype " type
True if the filesystem to which the file belongs is of type
.IR type .
.TP
.BI "\-group " gname
True if the file belongs to the group
.IR gname .
If
.I gname
is numeric and does not appear in the
.B /etc/group
file, it is taken as a group \s-1ID\s0.
.TP
.BI "\-inum " n
True if the file has inode number
.IR n .
.TP
.BI "\-links " n
True if the file has
.I n
links.
.TP
.B \-local
True if the file system type is not a remote file system type
as defined in the
.B /etc/dfs/fstypes
file.
.ft 3
nfs
.ft
is used as the default remote filesystem type if the
.B /etc/dfs/fstypes
file is not present.
.TP
.if t .B \-ls
.if n .B -ls
Always true; prints current path name together with its associated statistics.
These include (respectively):
.sp 1n
.PD 0
.RS 15
.TP 2
\(bu
inode number
.TP
\(bu
size in kilobytes (1024 bytes)
.TP
\(bu
protection mode
.TP
\(bu
number of hard links
.TP
\(bu
user
.TP
\(bu
group
.TP
\(bu
size in bytes
.TP
\(bu
modification time.
.RE
.PD
.IP
If the file is a special file the size field will instead
contain the major and minor device numbers.
.IP
If the file is a symbolic link the pathname of the
linked-to file is printed preceded by
.RB ` \(-> '.
The format is identical to that of
.B "ls \-gilds"
(see
.BR ls (1)).
.sp 1n
Note: Formatting is done internally, without executing the
.B ls
program.
.TP
.B \-mount
Always true;
restricts the search to the file system containing the directory specified.
Does not list mount points to other file systems.
.TP
.BI \-mtime \0n
True if the file's data was modified
.I n
days ago.
.TP
.BI \-name " pattern"
True if
.I pattern
matches the current file name.  Normal shell file name generation characters
(see
.BR sh (1))
may be used.
A backslash (\f3\|\e\|\fP) is used as an escape character within the pattern.
The pattern should be escaped or quoted when
.B find
is invoked from the shell.
.TP
.BI "\-ncpio " device
Always true; write the current file on
.I device
in
.B cpio \-c
format (5120 byte records).
.TP
.BI "\-newer " file
True if the current file has been modified more recently than the argument
.IR file .
.TP
.B \-nogroup
True if the file belongs to a group not in the
.B /etc/group
file.
.TP
.B \-nouser
True if the file belongs to a user not in the
.B /etc/passwd
file.
.TP
.BI "\-ok " command
Like
\f3\-exec\f1
except that the generated command line is printed with a question mark first,
and is executed only if the user responds by typing
.BR y .
.TP
.BI "\-perm \f1[\f3\-\f1]" mode
The
.I mode
argument is used to represent file mode bits.
It will be identical in format to the
.RI < symbolic mode >
operand described in
.BR chmod (1),
and will be interpreted as follows.
To start, a template will be assumed with all file mode bits cleared.  An
.I op
symbol of:
.RS 15
.TP
.B +
will set the appropriate mode bits in the template;
.TP
.B \-
will clear the appropriate bits;
.TP
.B =
will set the appropriate mode bits, without regard
to the contents of process' file mode creation mask.
.RE
.IP
The
.I op
symbol of
.B \-
cannot be the first character of
.IR mode ;
this avoids ambiguity with the optional leading hyphen.
Since the initial mode is all bits off, there are not any
symbolic modes that need to use
.B \-
as the first character.
.IP
If the hyphen is omitted, the primary will evaluate as
true when the file permission bits exactly match
the value of the resulting template.
.IP
Otherwise, if
.I mode
is prefixed by a hyphen,
the primary will evaluate as true
if at least all the bits in
the resulting template are set
in the file permission bits.
.TP 15
.BI "\-perm \f1[\f3\-\f1]" onum
True if the file permission flags exactly match the octal number
.I onum
(see
.BR chmod (1)).
If
.I onum
is prefixed by a minus sign (\f3\-\f1), only the bits that are set in
.I onum
are compared with the file permission flags,
and the expression evaluates true if they match.
.TP
.B \-print
Always true; causes the current path name to be printed.
.TP
.B \-prune
Always yields true.
Do not examine any directories or files
in the directory structure below the \f2pattern\f1
just matched.
See the examples, below.
.TP
\f3\-size\f1 \f2n\fP[\f3c\f1]
True if the file is
.I n
blocks long (512 bytes per block).
If
.I n
is followed by a
\f3c\f1,
the size is in bytes.
.br
.ne 5
.TP
\f3\-type\f2 c\^\f1
True if the type of the file
is
.IR c ,
where
.I c
is
\f3b\f1,
\f3c\f1,
\f3d\f1,
\f3l\f1,
\f3p\f1,
or
\f3f\f1
for
block special file, character special file,
directory, symbolic link, fifo (named pipe), or plain file, respectively.
.TP
.BI "\-user " uname
True if the file belongs to the user
.IR uname .
If
.I uname
is numeric and does not appear as a login name in the
.B /etc/passwd
file, it is taken as a user \s-1ID\s0.
.TP
.B \-xdev
Same as the
.B \-mount
primary.
.br
.ne 10
.SS Complex Expressions
.LP
The primaries may be combined using the following operators
(in order of decreasing precedence):
.RS
.ta 5n
.TP 25
1)	\f3( \f2expression\f3 )\f1
True if the parenthesized expression is true
(parentheses are special to the shell and must be escaped).
.TP
2)	\f3! \f2expression\f1
The negation of a primary
.RB ( !
is the unary
.I not
operator).
.TP
3)	\f2expression \f3[\-a] \f2expression\f1
Concatenation of primaries
(the
.I and
operation
is implied by the juxtaposition of two primaries).
.TP
4)	\f2expression \f3\-o \f2expression\f1
Alternation of primaries
\f1(\f3\-o\f1 is the
.I or
operator).
.RE
.PP
Note:  When you use \f3find\fP in conjunction with \f3cpio\fP,
if you use the \f3\-L\f1 option with \f3cpio\fP
then you must use the \f3\-follow\f1 expression with \f3find\fP and vice versa.
Otherwise there will be undesirable results.
.LP
If no
.I expression
is present,
.B \-print
will be used as the expression.
Otherwise, if the given expression does not contain any of the primaries
.BR \-exec ,
.B \-ok
or
.BR \-print ,
the given expression will be effectively replaced by:
.LP
.RS
( \f2given_expression\fP ) \-print
.RE
.LP
The
.BR \-user ,
.BR \-group ,
and
.B \-newer
primaries each will evaluate their respective arguments only once.
.SH EXAMPLES
The following commands are equivalent:
.LP
.RS
.nf
.ft 3
example% find .
example% find . -print
.ft 1
.fi
.RE
.LP
They both write out the entire directory hierarchy from the current directory.
.LP
Remove all files in your home directory named \f3a.out\fP or \f3\(**.o\fP that
have not been accessed for a week:
.LP
.RS
.nf
.B "example% find \s-1$HOME\s+1 \e\|( \-name a.out \-o \-name \(fm\(**.o\(fm \e"
.B "	\-atime +7 \e \-exec rm {} \e\|;"
.fi
.RE
.LP
Recursively print all file names in the current directory and below,
but skipping
.SM SCCS
directories:
.LP
.RS
.B "example% find . \-name \s-1SCCS\s0 \-prune \-o \-print"
.RE
.LP
Recursively print all file names in the current directory and below,
skipping the contents of
.SM SCCS
directories, but printing out the
.SM SCCS
directory name:
.LP
.RS
.B "example% find . \-print \-name \s-1SCCS\s0 \-prune"
.RE
.LP
.br
.ne 6
The following command is roughly equivalent to the
.B \-nt
extension to
.BR test (1):
.LP
.RS
.ft 3
.nf
example$ if [ -n "$(find file1 -prune -newer file2)" ]; then
	printf %s\e\en "file1 is newer than file2"
fi
.ft 1
.fi
.RE
.LP
The descriptions of
.BR \-atime ,
.BR \-ctime ,
and
.B \-mtime
use the terminology
.I n
``24-hour periods''.
For example, a file accessed at
23:59 will be selected by:
.LP
.RS
.B "example% find . -atime -1 -print"
.RE
.LP
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.
.SH ENVIRONMENT
See
.BR environ (5)
for descriptions of the following environment variables that affect the
execution of
.BR find :
.BR \s-1LC_COLLATE\s0\f1 ,
.BR \s-1LC_CTYPE\s0\f1 ,
.BR \s-1LC_MESSAGES\s0\f1 ,
and
.BR \s-1NLSPATH\s0\f1 .
.SH "EXIT STATUS"
The following exit values are returned:
.PD 0
.TP 10
.B 0
All
.I path
operands were traversed successfully.
.TP
.B >0
An error occurred.
.PD
.SH FILES
.PD 0
.TP 20
.B /etc/passwd
password file
.TP
.B /etc/group
group file
.TP
.B /etc/dfs/fstypes
file that registers distributed file system packages
.PD
.SH "SEE ALSO"
.BR chmod (1),
.BR ls (1),
.BR sh (1),
.BR test (1),
.BR stat (2),
.BR umask (2),
.BR environ (5)
.\".BR fs (4).
.br
.ne 7
.SH WARNINGS
The following options are obsolete and will not be supported in
future releases:
.TP 15
\f3-cpio\f2 device\f1
Always true; write the current file on
.I device
in
.B cpio
format (5120-byte records).
.TP 15
\f3-ncpio\f2 device\f1
Always true; write the current file on
.I device
in
.B cpio -c
format (5120 byte records).
.SH NOTES
When using \f3find\fP
to determine files modified within a range of time,
one must use the
\f3\?time\f1
argument
.I before
the
\f3\-print\f1
argument otherwise \f3find\fP
will give all files.
