=/^G show total bytes now; document may not always work
[unix-history] / usr / src / usr.bin / find / find.1
CommitLineData
3559318a
JL
1.\" Copyright (c) 1985 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
68243197 5.\" @(#)find.1 6.4 (Berkeley) %G%
910ee6b3 6.\"
17b268fb 7.TH FIND 1 ""
910ee6b3
KM
8.AT 3
9.SH NAME
10find \- find files
11.SH SYNOPSIS
12.B find
3559318a 13pathname-list expression
17b268fb
KM
14.br
15.B find
3559318a 16pattern
910ee6b3 17.SH DESCRIPTION
3559318a
JL
18In the first form above,
19.I find
910ee6b3
KM
20recursively descends
21the directory hierarchy for
22each pathname in the
23.I pathname-list
24(i.e., one or more pathnames)
25seeking files that match a boolean
26.I expression
27written in the primaries given below.
28In the descriptions, the argument
29.I n
30is used as a decimal integer
31where
32.I +n
33means more than
34.I n,
35.I \-n
36means less than
37.I n
38and
39.I n
40means exactly
41.IR n .
17b268fb 42.PP
3559318a
JL
43The second form rapidly searches a database for all pathnames
44which match
45.IR pattern .
46Usually the database is recomputed
47weekly and contains the pathnames
48of all files which are publicly accessible.
49If escaped, normal shell
50\*(lqglobbing\*(rq characters (`*', `?', `[', and ']')
51may be used in
52.IR pattern ,
53but the matching differs in that no characters
54.RI ( e.g. " `/')"
55have to be matched explicitly.
56As a special case, a simple
57.I pattern
58containing no globbing characters
59is matched as though it were
60.IR *pattern* ;
61if any globbing character appears
62there are no implicit globbing characters.
910ee6b3
KM
63.TP 10n
64.BR \-name " filename"
65True if the
66.I filename
67argument matches the current file name.
68Normal
3559318a 69shell
910ee6b3
KM
70argument syntax may be used if escaped (watch out for
71`[', `?' and `*').
72.TP
73.BR \-perm " onum"
74True if the file permission flags
75exactly
76match the
77octal number
78.I onum
79(see
80.IR chmod (1)).
81If
82.I onum
83is prefixed by a minus sign,
84more flag bits (017777, see
85.IR stat (2))
86become significant and
87the flags are compared:
88.IR (flags&onum)==onum .
89.TP
90.BR \-type " c"
91True if the type of the file
92is
93.I c,
94where
95.I c
96is
17b268fb 97.B "b, c, d, f, l"
910ee6b3 98or
17b268fb 99.B s
910ee6b3
KM
100for
101block special file, character special file,
17b268fb 102directory, plain file, symbolic link, or socket.
910ee6b3
KM
103.TP
104.BR \-links " n"
105True if the file has
106.I n
107links.
108.TP
109.BR \-user " uname"
110True if the file belongs to the user
111.I uname
112(login name or numeric user ID).
113.TP
239e9d73
S
114.B \-nouser
115True if the file belongs to a user
116.I not
117in the /etc/passwd database.
118.TP
910ee6b3
KM
119.BR \-group " gname"
120True if the file belongs to group
121.I gname
122(group name or numeric group ID).
123.TP
239e9d73
S
124.B \-nogroup
125True if the file belongs to a group
126.I not
127in the /etc/group database.
128.TP
910ee6b3
KM
129.BR \-size " n"
130True if the file is
131.I n
132blocks long (512 bytes per block).
133.TP
134.BR \-inum " n"
135True if the file has inode number
136.I n.
137.TP
138.BR \-atime " n"
139True if the file has been accessed in
140.I n
141days.
142.TP
143.BR \-mtime " n"
144True if the file has been modified in
145.I n
146days.
147.TP
148.BR \-exec " command"
149True if the executed command returns
150a zero value as exit status.
151The end of the command must be punctuated by an escaped
152semicolon.
153A command argument `{}' is replaced by the
154current pathname.
155.TP
156.BR \-ok " command"
157Like
158.B \-exec
159except that the generated command is written on
160the standard output, then the standard input is read
161and the command executed only upon response
162.BR y .
163.TP
164.B \-print
165Always true;
166causes the current pathname to be printed.
167.TP
239e9d73
S
168.B \-ls
169Always true;
170causes current pathname to be printed together
171with its associated statistics.
172These include (respectively) inode number,
173size in kilobytes (1024 bytes),
174protection mode,
175number of hard links,
176user,
177group,
178size in bytes,
179and modification time.
180If the file is a special file
181the size field will instead contain the major and minor
182device numbers.
183If the file is a symbolic link the
184pathname of the linked-to file is printed preceded by ``->''.
185The format is identical to that of ``ls -gilds''
186(note however that formatting is done internally,
187without executing the ls program).
188.TP
910ee6b3
KM
189.BR \-newer " file"
190True if
191the current file has been modified more recently than the argument
192.I file.
239e9d73 193.TP
3559318a
JL
194.BR \-cpio " file"
195Write the current file on the argument
196.I file
197in
198.I cpio
199format.
200.TP
239e9d73
S
201.B \-xdev
202Always true;
203causes find
204.I not
205to traverse down into a file system different
206from the one on which current
207.I argument
208pathname resides.
68243197
MT
209.TP
210.B \-follow
211Always true;
212causes find to traverse symbolic links to directories.
213Normally find does not traverse symbolic links.
910ee6b3
KM
214.PP
215The primaries may be combined using the following operators
216(in order of decreasing precedence):
217.TP 4
2181)
219A parenthesized group of primaries and operators
220(parentheses are special to the Shell and must be escaped).
221.TP 4
2222)
223The negation of a primary
224(`!' is the unary
225.I not
226operator).
227.TP 4
2283)
229Concatenation of primaries
230(the
231.I and
232operation
233is implied by the juxtaposition of two primaries).
234.TP 4
2354)
236Alternation of primaries
237.RB "(`" \-o "' is the"
238.I or
239operator).
17b268fb
KM
240.SH EXAMPLES
241.PP
3559318a
JL
242To find all accessible files whose pathname contains `find':
243.IP
244find find
245.PP
246To typeset all variants of manual pages for `ls':
17b268fb
KM
247.IP
248vtroff -man `find '*man*/ls.?'`
249.PP
910ee6b3
KM
250To remove all files named
251`a.out' or `*.o' that have not been accessed for a week:
252.IP "" .2i
3559318a 253find / \e( \-name a.out \-o \-name '*.o' \e) \-atime +7 \-exec rm {} \e\;
910ee6b3 254.SH FILES
3559318a
JL
255.nf
256.ta \w'/usr/lib/find/find.codes 'u
910ee6b3 257/etc/passwd
910ee6b3 258/etc/group
3559318a
JL
259/usr/lib/find/find.codes coded pathnames database
260.fi
910ee6b3 261.SH "SEE ALSO"
5710a779 262sh(1), test(1), fs(5)
17b268fb
KM
263.br
264Relevant paper in February, 1983 issue of
265.I ;login:.
910ee6b3 266.SH BUGS
3559318a
JL
267The first form's syntax is painful, and
268the second form's exact semantics is confusing and
269can vary from site to site.
270.PP
271More than one `-newer' option does not work properly.