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