summaryrefslogtreecommitdiff
path: root/usr.bin/find/find.1
blob: a12b4040517aad091e61ef28fb9b12a6bd42f49e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
'\" t
.\" Sccsid @(#)find.1	1.44 (gritter) 8/14/05
.\" Parts taken from find(1), Unix 7th edition:
.\" Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"   Redistributions of source code and documentation must retain the
.\"    above copyright notice, this list of conditions and the following
.\"    disclaimer.
.\"   Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"   All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"      This product includes software developed or owned by Caldera
.\"      International, Inc.
.\"   Neither the name of Caldera International, Inc. nor the names of
.\"    other contributors may be used to endorse or promote products
.\"    derived from this software without specific prior written permission.
.\"
.\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
.\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
.\" LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.TH FIND 1 "8/14/05" "Heirloom Toolchest" "User Commands"
.SH NAME
find \- find files
.SH SYNOPSIS
.B find
.I pathname-list expression
.SH DESCRIPTION
.I Find
recursively descends
the directory hierarchy for
each pathname in the
.I pathname-list
(i.\|e., one or more pathnames)
seeking files that match a boolean
.I expression
written in the primaries given below.
In the descriptions, the argument
.I n
is used as a decimal integer
where
.I +n
means more than
.I n,
.I \-n
means less than
.I n
and
.I n
means exactly
.IR n .
.TP 10n
.BR \-name " filename"
True if the
.I filename
argument matches the current file name.
Normal
Shell
argument syntax
as described in
.IR glob (7)
may be used if escaped (watch out for
`[', `?' and `*').
The internationalization constructs
`[[:class:]]', `[[=e=]]', and `[[.cs.]]'
are understood with
.BR /usr/5bin/s42/find ,
.BR /usr/5bin/posix/find ,
and
.BR /usr/5bin/posix2001/find ,
but not with
.BR /usr/5bin/find .
.TP
.BR \-perm " mode"
True if the file permission flags
exactly
match the
octal number
or symbolic
.I mode
(see
.IR  chmod (1)).
If
.I mode
is prefixed by a minus sign,
the flags are compared:
.IR (flags&mode)==mode .
.TP
.BR \-type " c"
True if the type of the file
is
.I c,
where
.I c
is
.sp
.TS
lfB l.
b	block special file;
c	character special file;
d	directory;
D	Solaris door;
f	plain file;
l	symbolic link;
n	HP-UX network special file;
p	named pipe;
s	socket.
.TE
.TP
.B \-follow
Always true;
causes find to follow symbolic links.
The `\fB\-type\fR l' condition never occurs in this case.
.TP
.BR \-links " n"
True if the file has
.I n
links.
.TP
.BR \-user " uname"
True if the file belongs to the user
.I uname
(login name or numeric user ID).
.TP
.BR \-group " gname"
True if the file belongs to group
.I gname
(group name or numeric group ID).
.TP
.BR \-size " n[" c ]
True if the file is
.I n
blocks long (512 bytes per block),
or, with
.BR c ,
.I n
bytes long.
.TP
.BR \-inum " n"
True if the file has inode number
.I n.
.TP
.BR \-atime " n"
True if the file has been accessed in
.I n
days.
.TP
.BR \-mtime " n"
True if the file has been modified in
.I n
days.
.TP
.BR \-ctime " n"
True if the file inode has been changed in
.I n
days.
.TP
.BR \-exec " command ... " ;
True if the executed command returns
a zero value as exit status.
The end of the command must be punctuated by an (escaped)
semicolon.
A command argument `{}' is replaced by the
current pathname.
.TP
.BR \-exec " command ... " "{} +"
Always true.
The
.B {}
argument is replaced by a set of aggregated pathnames.
Each pathname is passed to the command as a single argument.
Every time a limit of arguments is reached
by the pathnames found so far,
the command is executed,
and aggregating starts using a new set
beginning with the next pathname.
If any invocation of command
returns a non-zero exit status,
find will return a non-zero exit status
when its processing is done.
.TP
.BR \-ok " command ... " ;
Like
.B \-exec
except that the generated command is written on
the standard output, then the standard input is read
and the command executed only upon response
.BR y .
.TP
.B  \-print
Always true;
causes the current pathname to be printed.
If no expression is given,
.B \-print
is used per default
(as a change introduced by POSIX.2).
.TP
.BR \-newer " file"
True if
the current file has been modified more recently than the argument
.I file.
.TP
.BR \-anewer " file"
True if
the current file has been accessed more recently than the argument
.I file
was modified.
This primary is an extension.
.TP
.BR \-cnewer " file"
True if a status change
has occurred on the current file
more recently than the argument
.I file
was modified.
This primary is an extension.
.TP
.B \-depth
Always true;
causes the contents of each directory
to be examined before the directory itselves.
.TP
.BR \-fstype " type"
True if the current file
resides on a file system of the given type.
.TP
.B \-local
True if the file is on a local file system.
Are file system types except for
.I nfs
and
.I smbfs
are currently considered local.
.TP
.B \-mount
Always true;
restricts the search to directories
that have the same device id
as the currently examined path operand.
.TP
.B \-xdev
The same as
.BR \-mount .
This primary has been introduced by POSIX.
.TP
.B \-nouser
True if the file is owned by a user
that has no login name.
.TP
.B \-nogroup
True if the file is owned by a group
that lacks a group name.
.TP
.B \-prune
Always true.
Causes the search for the current path
to be stopped once the primary is evaluated.
When combined with
.BR \-depth ,
.B \-prune
has no effect.
.TP
.BR \-cpio " device"
Always true.
Writes the file on the named device
in binary cpio format (5120-byte records).
Implies
.BR \-depth .
.TP
.BR \-ncpio " device"
Always true.
Writes the file on the named device
in SVR4 ASCII cpio format (5120-byte records).
Implies
.BR \-depth .
.PP
The primaries may be combined using the following operators
(in order of decreasing precedence):
.TP 4
1)
A parenthesized group of primaries and operators
(parentheses are special to the Shell and must be escaped).
.TP 4
2)
The negation of a primary
(`!' is the unary
.I not
operator).
.TP 4
3)
Concatenation of primaries
(the
.I and
operation
is implied by the juxtaposition of two primaries
or by an explicit
.B \-a
operator).
.TP 4
4)
Alternation of primaries
.RB "(`" \-o "' is the"
.I or
operator).
.PP
Options have been introduced by POSIX.1-2001
in addition to the expression operators.
They must preceed the
.I pathname-list
one the command line
and have no effect on boolean expression processing.
.TP
.B \-H
Follow symbolic links given on the command line,
but do not follow symbolic links encountered during directory traversal.
.TP
.B \-L
Follow all symbolic links found,
like the
.I \-follow
primary.
.PP
With the
.I \-follow
primary or the
.I \-L
option, hierarchy loops caused by symbolic links are detected,
but only
.B /usr/5bin/posix2001/find
prints an error message.
The offending link is not followed,
and operation continues with the next directory entry found.
.SH EXAMPLES
To remove all files named
`a.out' or `*.o' that have not been accessed for a week:
.IP "" .2i
find / \\( \-name a.out \-o \-name \'*.o\' \\)
\-atime +7 \-exec rm {} \\;
.PP
The rm command is executed once for each file.
The form
.IP "" .2i
find / \\( \-name a.out \-o \-name \'*.o\' \\)
\-atime +7 \-exec rm {} +
.PP
is faster since the rm command is executed with a set of pathnames.
.PP
To find all files below the directory `documents'
that contain the regular expression `string':
.IP "" .2i
find documents \-type f \-exec grep string {} +
.PP
To find all files in the directory `home',
not descending into its subdirectories:
.IP "" .2i
find home ! \-name home \-prune
.PP
To check whether the file `diary'
has been updated within the last two days;
the name of the file is printed if true,
and is not printed otherwise:
.IP "" .2i
find diary \-prune \-mtime \-2
.SH FILES
/etc/passwd
.br
/etc/group
.SH "ENVIRONMENT VARIABLES"
.TP
.BR LANG ", " LC_ALL
See
.IR locale (7).
.TP
.B LC_COLLATE
Affects the collation order for range expressions,
equivalence classes, and collation symbols in patterns with
.BR /usr/5bin/s42/find ,
.BR /usr/5bin/posix/find ,
and
.BR /usr/5bin/posix2001/find .
.TP
.B LC_CTYPE
Determines the mapping of bytes to characters
and character class expressions
in patterns.
.TP
.B SYSV3
Causes the text of some diagnostic messages to be changed;
causes
.I \-ncpio
to create traditional ASCII cpio format archives.
.SH "SEE ALSO"
chmod(1),
cpio(1),
pax(1),
sh(1),
xargs(1),
stat(2),
glob(7),
locale(7)
.SH NOTES
Undesired effects can result if file names printed by
.I find
contain newline characters,
as shown by the following command sequence:
.RS
.sp
.nf
$ mkdir \-p \'dummy
> /etc\'
$ touch \'dummy
> /etc/passwd\'
$ find . \-print
\&.
\&./dummy
.sp
\&./dummy
/etc
\&./dummy
/etc/passwd
$\ 
.fi
.sp
.RE
Shell scripts or utilities unaware of this problem
will operate on
.I /etc/passwd
(or other arbitrary file names)
when reading such output;
a malicious user might create such files
to read or overwrite privileged information.
To circumvent this problem,
one of the following proposals should be taken
unless the file hierarchy traversed by the
.I find
command is definitively known not to contain such file names:
.IP \(en 2
If the output is read by the
.I xargs
utility to gain faster execution by aggregating command arguments as in
.in +2
.sp
find . \-print | xargs \fIcommand\fR
.sp
.in -2
a safe and equally fast substitute is the
.in +2
.sp
find . \-exec \fIcommand\fR {} +
.sp
.in -2
operand of
.IR find ;
it is not portably accepted by
.I find
implementations, though.
.IP \(en 2
A universal solution for submitting file names to the
.I xargs
utility is given in the
.I NOTES
section of
.IR xargs (1).
.IP \(en 2
The method employed by this script can be generalized as follows:
If the script or utility reading the output of
.I find
provides the necessary parsing capabilities,
special path prefixes can be given to the
.I find
command, such as
.in +2
.sp
find /.//. \-print
.sp
.in -2
for absolute path names or
.in +2
.sp
find .//. \-print
.sp
.in -2
for relative path names.
Since adjacent slash characters never appear
in relative file names found during directory traversal,
they can be taken as delimiters;
a line starts a new path name
only if the delimiter appears.
.IP \(en 2
The
.I \-name
operand can be used to exclude all path names
that contain newline characters, as in
.in +2
.sp
.nf
$ find . \-name \'* 
> *\' \-prune \-o ! \-name \'*
> *\' \-print
.sp
.fi
.in -2
Note that certain other implementations of
.I find
require a leading period in the pattern
to match file names with a leading period;
it may be necessary to exclude such patterns as well.
.IP \(en 2
The
.I \-depth
operand cannot be combined with the
.I \-prune
operand used in the previous example.
When the directory name must be printed
after file names below that directory,
as with the
.IR cpio
command,
file names that leave the specified path hierarchy
should be filtered out:
.in +2
.sp
find . \-depth | egrep \'^\e./\' | cpio \-oc \-O /dev/rmt/c0s0
.sp
.in -2
(note the escaped regular expression meta-character).
.IP \(en 2
The
.I \-cpio
and
.I \-ncpio
operands will automatically exclude file names
that contain newline characters
with this
.I find
implementation.
.PP
The
.I \-print0
operand supported by some other implementations
is considered a very limited work-around
since it does not allow the output to be processed
by utilities unaware of NUL characters;
it has therefore not been included here.