Improved sicussion of the -print0 option of find and the -0 option of xargs
[findutils.git] / find / find.1
blob2629d5b2b27f0dffd9dad03dd3e93600a34c6be6
1 .TH FIND 1L \" -*- nroff -*-
2 .SH NAME
3 find \- search for files in a directory hierarchy
4 .SH SYNOPSIS
5 .B find
6 [path...] [expression]
7 .SH DESCRIPTION
8 This manual page
9 documents the GNU version of
10 .BR find .
11 .B find
12 searches the directory tree rooted at each given file name by
13 evaluating the given expression from left to right, according to the
14 rules of precedence (see section OPERATORS), until the outcome is
15 known (the left hand side is false for \fIand\fR operations, true for
16 \fIor\fR), at which point
17 .B find
18 moves on to the next file name.
19 .PP
20 The first argument that begins with `\-', `(', `)', `,', or `!' is taken
21 to be the beginning of the expression; any arguments before it are
22 paths to search, and any arguments after it are the rest of the
23 expression.  If no paths are given, the current directory is used.  If
24 no expression is given, the expression `\-print' is used (but you
25 should probably consider using `\-print0' instead, anyway).
27 .SH EXPRESSIONS
29 The expression is made up of options (which affect overall operation
30 rather than the processing of a specific file, and always return true),
31 tests (which return a true or false value), and actions (which have side
32 effects and return a true or false value), all separated by operators.
33 \-and is assumed where the operator is omitted.  If the expression contains
34 no actions other than \-prune, \-print is performed on all files
35 for which the expression is true.
36 .SS OPTIONS
38 All options always return true.  They always take effect, rather than
39 being processed only when their place in the expression is reached.
40 Therefore, for clarity, it is best to place them at the beginning of
41 the expression.
42 .IP \-daystart
43 Measure times (for \-amin, \-atime, \-cmin, \-ctime, \-mmin, and \-mtime)
44 from the beginning of today rather than from 24 hours ago.
45 .IP \-depth
46 Process each directory's contents before the directory itself.
47 .IP \-follow
48 Dereference symbolic links.  Implies \-noleaf.
49 .IP "\-help, \-\-help"
50 Print a summary of the command-line usage of
51 .B find
52 and exit.
53 .IP "\-maxdepth \fIlevels\fR"
54 Descend at most \fIlevels\fR (a non-negative integer) levels of
55 directories below the command line arguments.  `\-maxdepth 0' means
56 only apply the tests and actions to the command line arguments.
57 .IP "\-mindepth \fIlevels\fR"
58 Do not apply any tests or actions at levels less than \fIlevels\fR (a
59 non-negative integer).  `\-mindepth 1' means process all files except
60 the command line arguments.
61 .IP \-mount
62 Don't descend directories on other filesystems.  An alternate name for
63 \-xdev, for compatibility with some other versions of
64 .BR find .
65 .IP "\-noleaf"
66 Do not optimize by assuming that directories contain 2 fewer
67 subdirectories than their hard link count.  This option is needed when
68 searching filesystems that do not follow the Unix directory-link
69 convention, such as CD-ROM or MS-DOS filesystems or AFS volume mount
70 points.  Each directory on a normal Unix filesystem has at least 2
71 hard links: its name and its `.'  entry.  Additionally, its
72 subdirectories (if any) each have a `..'  entry linked to that
73 directory.  When
74 .B find
75 is examining a directory, after it has statted 2 fewer subdirectories
76 than the directory's link count, it knows that the rest of the entries
77 in the directory are non-directories (`leaf' files in the directory
78 tree).  If only the files' names need to be examined, there is no need
79 to stat them; this gives a significant increase in search speed.
80 .IP "\-version, \-\-version"
81 Print the \fBfind\fR version number and exit.
82 .IP \-xdev
83 Don't descend directories on other filesystems.
84 .SS TESTS
86 Numeric arguments can be specified as
87 .IP \fI+n\fP
88 for greater than
89 .IR n ,
90 .IP \fI\-n\fP
91 for less than
92 .IR n ,
93 .IP \fIn\fP
94 for exactly
95 .IR n .
96 .IP "\-amin \fIn\fR"
97 File was last accessed \fIn\fR minutes ago.
98 .IP "\-anewer \fIfile\fR"
99 File was last accessed more recently than \fIfile\fR was modified.
100 \-anewer is affected by \-follow only if \-follow comes before
101 \-anewer on the command line.
102 .IP "\-atime \fIn\fR"
103 File was last accessed \fIn\fR*24 hours ago.
104 .IP "\-cmin \fIn\fR"
105 File's status was last changed \fIn\fR minutes ago.
106 .IP "\-cnewer \fIfile\fR"
107 File's status was last changed more recently than \fIfile\fR was modified.
108 \-cnewer is affected by \-follow only if \-follow comes before
109 \-cnewer on the command line.
110 .IP "\-ctime \fIn\fR"
111 File's status was last changed \fIn\fR*24 hours ago.
112 .IP \-empty
113 File is empty and is either a regular file or a directory.
114 .IP \-false
115 Always false.
116 .IP "\-fstype \fItype\fR"
117 File is on a filesystem of type \fItype\fR.  The valid filesystem
118 types vary among different versions of Unix; an incomplete list of
119 filesystem types that are accepted on some version of Unix or another
120 is: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K.  You can use \-printf
121 with the %F directive to see the types of your filesystems.
122 .IP "\-gid \fIn\fR"
123 File's numeric group ID is \fIn\fR.
124 .IP "\-group \fIgname\fR"
125 File belongs to group \fIgname\fR (numeric group ID allowed).
126 .IP "\-ilname \fIpattern\fR"
127 Like \-lname, but the match is case insensitive.
128 .IP "\-iname \fIpattern\fR"
129 Like \-name, but the match is case insensitive.  For example, the
130 patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo',
131 `fOo', etc.
132 .IP "\-inum \fIn\fR"
133 File has inode number \fIn\fR.
134 .IP "\-ipath \fIpattern\fR"
135 Like \-path, but the match is case insensitive.
136 .IP "\-iregex \fIpattern\fR"
137 Like \-regex, but the match is case insensitive.
138 .IP "\-links \fIn\fR"
139 File has \fIn\fR links.
140 .IP "\-lname \fIpattern\fR"
141 File is a symbolic link whose contents match shell pattern
142 \fIpattern\fR.  The metacharacters do not treat `/' or `.' specially.
143 .IP "\-mmin \fIn\fR"
144 File's data was last modified \fIn\fR minutes ago.
145 .IP "\-mtime \fIn\fR"
146 File's data was last modified \fIn\fR*24 hours ago.
147 .IP "\-name \fIpattern\fR"
148 Base of file name (the path with the leading directories removed)
149 matches shell pattern \fIpattern\fR.  The metacharacters (`*', `?',
150 and `[]') do not match a `.' at the start of the base name.  To ignore
151 a directory and the files under it, use \-prune; see an example in the
152 description of \-path.
153 .IP "\-newer \fIfile\fR"
154 File was modified more recently than \fIfile\fR.
155 \-newer is affected by \-follow only if \-follow comes before
156 \-newer on the command line.
157 .IP \-nouser
158 No user corresponds to file's numeric user ID.
159 .IP \-nogroup
160 No group corresponds to file's numeric group ID.
161 .IP "\-path \fIpattern\fR"
162 File name matches shell pattern \fIpattern\fR.  The metacharacters do
163 not treat `/' or `.' specially; so, for example,
165 .in +1i
166 find . \-path './sr*sc'
168 .in -1i
169 will print an entry for a directory called './src/misc' (if one
170 exists).  To ignore a whole directory tree, use \-prune rather than
171 checking every file in the tree.  For example, to skip the
172 directory `src/emacs' and all files and directories under it, and
173 print the names of the other files found, do something like this:
175 .in +1i
176 find . \-path './src/emacs' -prune -o -print
178 .in -1i
179 .IP "\-perm \fImode\fR"
180 File's permission bits are exactly \fImode\fR (octal or symbolic).
181 Symbolic modes use mode 0 as a point of departure.
182 .IP "\-perm \-\fImode\fR"
183 All of the permission bits \fImode\fR are set for the file.
184 .IP "\-perm +\fImode\fR"
185 Any of the permission bits \fImode\fR are set for the file.
186 .IP "\-regex \fIpattern\fR"
187 File name matches regular expression \fIpattern\fR.  This is a match
188 on the whole path, not a search.  For example, to match a file named
189 `./fubar3', you can use the regular expression `.*bar.' or `.*b.*3',
190 but not `b.*r3'.
191 .IP "\-size \fIn\fR[bckw]"
192 File uses \fIn\fP units of space.  The units are 512-byte blocks by
193 default or if `b' follows \fIn\fP, bytes if `c' follows \fIn\fP,
194 kilobytes if `k' follows \fIn\fP, or 2-byte words if `w' follows \fIn\fP.
195 The size does not count indirect blocks, but it does count blocks in
196 sparse files that are not actually allocated.
197 .IP \-true
198 Always true.
199 .IP "\-type \fIc\fR"
200 File is of type \fIc\fR:
202 .IP b
203 block (buffered) special
204 .IP c
205 character (unbuffered) special
206 .IP d
207 directory
208 .IP p
209 named pipe (FIFO)
210 .IP f
211 regular file
212 .IP l
213 symbolic link
214 .IP s
215 socket
216 .IP D
217 door (Solaris)
219 .IP "\-uid \fIn\fR"
220 File's numeric user ID is \fIn\fR.
221 .IP "\-used \fIn\fR"
222 File was last accessed \fIn\fR days after its status was last changed.
223 .IP "\-user \fIuname\fR"
224 File is owned by user \fIuname\fR (numeric user ID allowed).
225 .IP "\-xtype \fIc\fR"
226 The same as \-type unless the file is a symbolic link.  For symbolic
227 links: if \-follow has not been given, true if the file is a link to a
228 file of type \fIc\fR; if \-follow has been given, true if \fIc\fR is
229 `l'.  In other words, for symbolic links, \-xtype checks the type of
230 the file that \-type does not check.
231 .SS ACTIONS
232 .IP "\-exec \fIcommand\fR ;"
233 Execute \fIcommand\fR; true if 0 status is returned.  All following
234 arguments to
235 .B find
236 are taken to be arguments to the command until an argument consisting
237 of `;' is encountered.  The string `{}' is replaced by the current
238 file name being processed everywhere it occurs in the arguments to the
239 command, not just in arguments where it is alone, as in some versions
241 .BR find .
242 Both of these constructions might need to be escaped (with a `\e') or
243 quoted to protect them from expansion by the shell.  The command is
244 executed in the starting directory.
245 .IP "\-fls \fIfile\fR"
246 True; like \-ls but write to \fIfile\fR like \-fprint.
247 The output file is always created, even if the predicate is never matched.
248 .IP "\-fprint \fIfile\fR"
249 True; print the full file name into file \fIfile\fR.  If \fIfile\fR
250 does not exist when \fBfind\fR is run, it is created; if it does
251 exist, it is truncated.  The file names ``/dev/stdout'' and
252 ``/dev/stderr'' are handled specially; they refer to the standard
253 output and standard error output, respectively.
254 The output file is always created, even if the predicate is never matched.
255 .IP "\-fprint0 \fIfile\fR"
256 True; like \-print0 but write to \fIfile\fR like \-fprint.
257 The output file is always created, even if the predicate is never matched.
258 .IP "\-fprintf \fIfile\fR \fIformat\fR"
259 True; like \-printf but write to \fIfile\fR like \-fprint.
260 The output file is always created, even if the predicate is never matched.
261 .IP "\-ok \fIcommand\fR ;"
262 Like \-exec but ask the user first (on the standard input); if the
263 response does not start with `y' or `Y', do not run the command, and
264 return false.
265 .IP \-print
266 True; print the full file name on the standard output, followed by a
267 newline.   If you are piping the output of 
268 .B find 
269 into another program and there is the faintest possibility that the files 
270 which you are searching for might contain a newline, then you should 
271 seriously consider using the `\-print0' option instead of `\-print'.
273 .IP \-print0
274 True; print the full file name on the standard output, followed by a
275 null character (instead of the newline character that `-print' uses).  
276 This allows file names that contain newlines to be
277 correctly interpreted by programs that process the \fBfind\fR output.
278 This option corresponds to the `\-0' option of
279 .BR xargs .
280 .IP "\-printf \fIformat\fR"
281 True; print \fIformat\fR on the standard output, interpreting `\e'
282 escapes and `%' directives.  Field widths and precisions can be
283 specified as with the `printf' C function.  Unlike \-print, \-printf
284 does not add a newline at the end of the string.  The escapes and
285 directives are:
287 .IP \ea
288 Alarm bell.
289 .IP \eb
290 Backspace.
291 .IP \ec
292 Stop printing from this format immediately and flush the output.
293 .IP \ef
294 Form feed.
295 .IP \en
296 Newline.
297 .IP \er
298 Carriage return.
299 .IP \et
300 Horizontal tab.
301 .IP \ev
302 Vertical tab.
303 .IP \e\e
304 A literal backslash (`\e').
305 .IP \eNNN
306 The character whose ASCII code is NNN (octal).
308 A `\e' character followed by any other character is treated as an
309 ordinary character, so they both are printed.
310 .IP %%
311 A literal percent sign.
312 .IP %a
313 File's last access time in the format returned by the C `ctime' function.
314 .IP %A\fIk\fP
315 File's last access time in the format specified by \fIk\fR, which is
316 either `@' or a directive for the C `strftime' function.  The possible
317 values for \fIk\fR are listed below; some of them might not be
318 available on all systems, due to differences in `strftime' between
319 systems.
321 .IP @
322 seconds since Jan. 1, 1970, 00:00 GMT.
324 Time fields:
325 .IP H
326 hour (00..23)
327 .IP I
328 hour (01..12)
329 .IP k
330 hour ( 0..23)
331 .IP l
332 hour ( 1..12)
333 .IP M
334 minute (00..59)
335 .IP p
336 locale's AM or PM
337 .IP r
338 time, 12-hour (hh:mm:ss [AP]M)
339 .IP S
340 second (00..61)
341 .IP T
342 time, 24-hour (hh:mm:ss)
343 .IP X
344 locale's time representation (H:M:S)
345 .IP Z
346 time zone (e.g., EDT), or nothing if no time zone is determinable
348 Date fields:
349 .IP a
350 locale's abbreviated weekday name (Sun..Sat)
351 .IP A
352 locale's full weekday name, variable length (Sunday..Saturday)
353 .IP b
354 locale's abbreviated month name (Jan..Dec)
355 .IP B
356 locale's full month name, variable length (January..December)
357 .IP c
358 locale's date and time (Sat Nov 04 12:02:33 EST 1989)
359 .IP d
360 day of month (01..31)
361 .IP D
362 date (mm/dd/yy)
363 .IP h
364 same as b
365 .IP j
366 day of year (001..366)
367 .IP m
368 month (01..12)
369 .IP U
370 week number of year with Sunday as first day of week (00..53)
371 .IP w
372 day of week (0..6)
373 .IP W
374 week number of year with Monday as first day of week (00..53)
375 .IP x
376 locale's date representation (mm/dd/yy)
377 .IP y
378 last two digits of year (00..99)
379 .IP Y
380 year (1970...)
382 .IP %b
383 File's size in 512-byte blocks (rounded up).
384 .IP %c
385 File's last status change time in the format returned by the C `ctime'
386 function.
387 .IP %C\fIk\fP
388 File's last status change time in the format specified by \fIk\fR,
389 which is the same as for %A.
390 .IP %d
391 File's depth in the directory tree; 0 means the file is a command line
392 argument.
393 .IP %f
394 File's name with any leading directories removed (only the last element).
395 .IP %F
396 Type of the filesystem the file is on; this value can be used for
397 \-fstype.
398 .IP %g
399 File's group name, or numeric group ID if the group has no name.
400 .IP %G
401 File's numeric group ID.
402 .IP %h
403 Leading directories of file's name (all but the last element).
404 .IP %H
405 Command line argument under which file was found.
406 .IP %i
407 File's inode number (in decimal).
408 .IP %k
409 File's size in 1K blocks (rounded up).
410 .IP %l
411 Object of symbolic link (empty string if file is not a symbolic link).
412 .IP %m
413 File's permission bits (in octal).
414 .IP %n
415 Number of hard links to file.
416 .IP %p
417 File's name.
418 .IP %P
419 File's name with the name of the command line argument under which
420 it was found removed.
421 .IP %s
422 File's size in bytes.
423 .IP %t
424 File's last modification time in the format returned by the C `ctime'
425 function.
426 .IP %T\fIk\fP
427 File's last modification time in the format specified by \fIk\fR, 
428 which is the same as for %A.
429 .IP %u
430 File's user name, or numeric user ID if the user has no name.
431 .IP %U
432 File's numeric user ID.
434 A `%' character followed by any other character is discarded (but the
435 other character is printed).
437 .IP \-prune
438 If \-depth is not given, true; do not descend the current directory.
440 If \-depth is given, false; no effect.
441 .IP \-ls
442 True; list current file in `ls \-dils' format on standard output.
443 The block counts are of 1K blocks, unless the environment variable
444 POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
445 .SS OPERATORS
447 Listed in order of decreasing precedence:
448 .IP "( \fIexpr\fR )"
449 Force precedence.
450 .IP "! \fIexpr\fR"
451 True if \fIexpr\fR is false.
452 .IP "\-not \fIexpr\fR"
453 Same as ! \fIexpr\fR.
454 .IP "\fIexpr1 expr2\fR"
455 And (implied); \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
456 .IP "\fIexpr1\fR \-a \fIexpr2\fR"
457 Same as \fIexpr1 expr2\fR.
458 .IP "\fIexpr1\fR \-and \fIexpr2\fR"
459 Same as \fIexpr1 expr2\fR.
460 .IP "\fIexpr1\fR \-o \fIexpr2\fR"
461 Or; \fIexpr2\fR is not evaluated if \fIexpr1\fR is true.
462 .IP "\fIexpr1\fR \-or \fIexpr2\fR"
463 Same as \fIexpr1\fR \-o \fIexpr2\fR.
464 .IP "\fIexpr1\fR , \fIexpr2\fR"
465 List; both \fIexpr1\fR and \fIexpr2\fR are always evaluated.
466 The value of \fIexpr1\fR is discarded; the value of the list is the
467 value of \fIexpr2\fR.
468 .SH "EXAMPLES"
470 .B find /tmp -name core -type f -print | xargs /bin/rm -f
473 Find files named 
474 .B core
475 in or below the directory 
476 .B /tmp 
477 and delete them.  Note that this will work incorrectly if there are 
478 any filenames containing newlines or spaces.
480 .B find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
483 Find files named 
484 .B core
485 in or below the directory 
486 .B /tmp 
487 and delete them, processing filenames in such a way that file or 
488 directory names containing spaces or newlines are correctly handled.
491 .B cut -d: -f1 < /etc/passwd | sort | xargs echo
494 Generates a compact listing of all the users on the system.
495 .SH EXIT STATUS
497 .B find
498 exits with status 0 if all files are processed successfully, greater
499 than 0 if errors occur.
500 .SH "SEE ALSO"
501 \fBlocate\fP(1L), \fBlocatedb\fP(5L), \fBupdatedb\fP(1L), \fBxargs\fP(1L)
502 \fBFinding Files\fP (on-line in Info, or printed)
503 .SH "BUGS"
504 .P 
505 The best way to report a bug is to use the form at
506 http://savannah.gnu.org/bugs/?group=findutils.  
507 The reason for this is that you will then be able to track progress in
508 fixing the problem.   Other comments about \fBfind\fP(1L) and about
509 the findutils package in general can be sent to the 
510 .I bug-findutils
511 mailing list.  To join the list, send email to 
512 .IR bug-findutils-request@gnu.org .