.TH find "" "" Command
.PC "Search for files satisfying a pattern"
\fBfind \fIdirectory ... \fB[\fIexpression ...\fB]\fR
.PP
.HS
.SH Expression:
.IC "\fB\-atime\fR \fIn\fR"
File has been accessed in \fIn\fR days
.IC "\fB\-ctime\fR \fIn\fR"
File's i-node has been changed in \fIn\fR days
.IC "\fB\-exec\fR \fIcmd\fR"
Command \fIcmd\fR is successful
.IC "\fB\-group\fR \fIgn\fR"
File belongs to group \fIgn\fR
.IC "\fB\-inum\fR \fIn\fR"
File has i-node \fIn\fR
.IC "\fB\-links\fR \fIn\fR"
File has \fIn\fR links to it
.IC "\fB\-mtime\fR \fIn\fR"
File has been modified within \fIn\fR days
.IC "\fB\-name\fR \fIpattern\fR"
File name matches \fIpattern\fR (shell conventions)
.IC "\fB\-newer\fR\fIfile\fR"
File has been modified since \fIfile\fR
.IC "\fB\-nop\fR"
Always true; does nothing
.IC "\fB\-ok\fR \fIcmd\fR"
Like \fB\-exec\fR, except it asks
.IC "\fB\-perm\fR \fIoctal\fR"
File permissions are \fIoctal\fR
.IC "\fB\-print\fR"
Always true; prints current path name
.IC "\fB\-size\fR \fIn\fR"
File is \fIn\fR blocks long
.IC "\fB\-type\fR \fIc\fR"
File matches type (\fIc\fR may be [bcdfmp])
.IC "\fB\-user\fR \fIuname\fR"
\fIuname\fR owns file
.IC "\fBexp \-a \fIexp exp\fR"
Both expressions are true
.IC "\fBexp \-o \fIexp exp\fR"
One of the expressions is true
.IC "\fB! \fIexp\fR"
Expression is false
.IC "\fB(\fIexp\fR\fB)\fR"
Parentheses for grouping
.Pp
If no expression is specified, \fB\-print\fR is assumed.
.HE
.B find
traverses each given
.IR directory ,
testing each file or subdirectory found with the
.I expression
part of the command line.
The test can be the basis for
deciding whether to process the file with a given command.
.PP
If the command line specifies no
.I expression
or specifies no execution or printing (\fB\-print\fR,
.BR \-exec ,
or
.BR \-ok ),
by default
.B find
prints the pathnames of the files found.
.PP
In the following,
.I file
means any file:
directory, special file, ordinary file, and so on.
Numbers represented by
.I n
may be optionally prefixed by a `+' or `\-' sign to signify values
greater than
.I n
or less than
.IR n ,
respectively.
.PP
.B find
recognizes the following
.I expression
primitives:
.IP "\-\fBatime\fI n\fR" 0.75i
Match if the file was accessed in the last
.I n
days.
.IP "\-\fBctime\fI n\fR"
Match if the i-node associated with the file was changed in the last
.I n
days, as by
.BR chmod .
.IP "\-\fBexec\fI command\fR"
Match if
.I command
executes successfully (has a zero exit status).
The
.I command
consists of the following arguments to
.BR find ,
terminated by a semicolon `;' (escaped to get past the shell).
.B find
substitutes the current pathname being tested
for any argument of the form `{}'.
.IP "\-\fBgroup\fI name\fR"
Match if the file is owned by group
.IR name .
If
.I name
is a number, the owner must have that group number.
.IP "\-\fBinum\fI n\fR"
Match if the file is associated with i-number
.I n.
.IP "\-\fBlinks\fI n\fR"
Match if the number of links to the file is
.I n.
.IP "\-\fBmtime\fI n\fR"
Match if the most recent modification to the file was
.I n
days ago.
.IP "\-\fBname\fI pattern\fR"
Match if the file name corresponds to
.I pattern,
which may include the special characters `*', `?', and `[...]'
recognized by the shell
.BR sh .
The
.I pattern
matches only the part of the file name after any slash (`/') characters.
.IP "\-\fBnewer\fI file\fR"
Match if the file is newer than
.I file.
.IP "\-\fBnop\fR"
Always match; does nothing.
.IP "\-\fBok\fI command\fR"
Same as
.B \-exec
above, except prompt interactively and only executes
.I command
if the user types response
.BR `y' .
.IP "\-\fBperm\fI octal\fR"
Match if owner, group, and other permissions of the file are the
.I octal
bit pattern,
as described in
.BR chmod .
When
.I octal
begins with a
.B `\-'
character,
more of the permission bits
(setuid, setgid, and sticky bit) become significant.
.IP "\-\fBprint\fR"
Always match; print the file name.
.IP "\-\fBsize\fI n\fR"
Match if the file is
.I n
blocks in length; a block is 512 bytes long.
.IP "\-\fBtype\fI c\fR"
Match if the type of the file is
.IR c ,
chosen from the set
.B bcdfmp
(for
block special, character special, directory, ordinary file,
multiplexed file, or pipe, respectively).
.IP "\-\fBuser\fI name\fR"
Match if the file is owned by user
.I name.
If
.I name
is a number, the owner must have that user number.
.IP "\fIexp1 exp2\fR"
Match if both expressions match.
.B find
evaluates
.I exp2
only if
.I exp1
matches.
.IP "\fIexp1 \fB-a \fIexp2\fR"
Match if both expressions match, as above.
.IP "\fIexp1 \fB-o \fIexp2\fR"
Match if either expression matches.
.B find
evaluates
.B exp2
only if
.B exp1
does not match.
.IP "! \fIexp\fR"
Match if the expression does
.I not
match.
.IP "( \fIexp\fR )"
Parentheses are available for expression grouping.
.SH Examples
A
.B find
command to print the names of
all files and directories in user
.BR fred 's
directory is:
.DM
	find /usr/fred
.DE
.PP
The following, more complicated
.B find
command prints out information on all
.B core
and object (\fB.o\fR)
files that have not been changed for a day.
Because some characters are special both to
.B find
and
.BR sh ,
they must be escaped with `\e' to avoid interpretation
by the shell.
.DM
	find / \e( \-name core \-o \-name \e*.o \e) \-mtime +1 \e
.br
	\-exec ls \-l {} \e;
.DE
.PP
Finally, the following example implements a simple tool for keeping
files on two \*(CO systems in synch with each other.
.B find
reads directory
.B src
and passes to \fBuucp\fR the names of all files that are newer than file
.BR last_upload .
It then uses the command
.B touch
to update the date on \fBlast_upload\fR, to use it as a marker of when
the last upload was performed.
.DM
	find $HOME/src -type f -newer last_upload | while read filename
	do
		uucp -r -nyou $filename yoursystem!~/
		echo Queued file $filename to yoursystem ...
	done | mail somebodyorother
	touch last_upload
.DE
.SH "See Also"
.Xr "chmod," chmod
.Xr "commands," commands
.Xr "ls," ls
.Xr "sh," sh
.Xr "srcpath," srcpath
.Xr "test" test
