1 | .TH FIND 1 \" -*- nroff -*-
|
---|
2 | .SH NAME
|
---|
3 | find \- search for files in a directory hierarchy
|
---|
4 | .SH SYNOPSIS
|
---|
5 | .B find
|
---|
6 | [\-H] [\-L] [\-P] [-D debugopts] [-Olevel] [path...] [expression]
|
---|
7 | .SH DESCRIPTION
|
---|
8 | This manual page
|
---|
9 | documents the GNU version of
|
---|
10 | .BR find .
|
---|
11 | GNU
|
---|
12 | .B find
|
---|
13 | searches the directory tree rooted at each given file name by
|
---|
14 | evaluating the given expression from left to right, according to the
|
---|
15 | rules of precedence (see section OPERATORS), until the outcome is
|
---|
16 | known (the left hand side is false for \fIand\fR operations, true for
|
---|
17 | \fIor\fR), at which point
|
---|
18 | .B find
|
---|
19 | moves on to the next file name.
|
---|
20 | .PP
|
---|
21 | If you are using
|
---|
22 | .B find
|
---|
23 | in an environment where security is important (for example if you are
|
---|
24 | using it to seach directories that are writable by other users), you
|
---|
25 | should read the "Security Considerations" chapter of the findutils
|
---|
26 | documentation, which is called \fBFinding Files\fP and comes with
|
---|
27 | findutils. That document also includes a lot more detail
|
---|
28 | and discussion than this manual page, so you may find it a more useful
|
---|
29 | source of information.
|
---|
30 | .SH OPTIONS
|
---|
31 | The `\-H', `\-L' and `\-P' options control the treatment of symbolic
|
---|
32 | links. Command-line arguments following these are taken to be names
|
---|
33 | of files or directories to be examined, up to the first argument that
|
---|
34 | begins with `\-', or the argument `(' or `!'. That argument and any
|
---|
35 | following arguments are taken to be the expression describing what is
|
---|
36 | to be searched for. If no paths are given, the current directory is
|
---|
37 | used. If no expression is given, the expression `\-print' is used
|
---|
38 | (but you should probably consider using `\-print0' instead, anyway).
|
---|
39 | .PP
|
---|
40 | This manual page talks about `options' within the expression list.
|
---|
41 | These options control the behaviour of
|
---|
42 | .B find
|
---|
43 | but are specified immediately after the last path name. The three
|
---|
44 | `real' options `\-H', `\-L' and `\-P' must appear before the first
|
---|
45 | path name, if at all.
|
---|
46 | .IP \-P
|
---|
47 | Never follow symbolic links. This is the default behaviour. When
|
---|
48 | .B find
|
---|
49 | examines or prints information a file, and the file is a symbolic
|
---|
50 | link, the information used shall be taken from the properties of the
|
---|
51 | symbolic link itself.
|
---|
52 |
|
---|
53 | .IP \-L
|
---|
54 | Follow symbolic links. When
|
---|
55 | .B find
|
---|
56 | examines or prints information about files, the information used shall
|
---|
57 | be taken from the properties of the file to which the link points, not
|
---|
58 | from the link itself (unless it is a broken symbolic link or
|
---|
59 | .B find
|
---|
60 | is unable to examine the file to which the link points). Use of this
|
---|
61 | option implies \-noleaf. If you later use the \-P option, \-noleaf
|
---|
62 | will still be in effect. If \-L is in effect and
|
---|
63 | .B find
|
---|
64 | discovers a symbolic link to a subdirectory during its search,
|
---|
65 | the subdirectory pointed to by the symbolic link will be searched.
|
---|
66 | .IP
|
---|
67 | When the \-L option is in effect, the \-type predicate will always
|
---|
68 | match against the type of the file that a symbolic link points to
|
---|
69 | rather than the link itself (unless the symbolic link is broken).
|
---|
70 | Using \-L causes the \-lname and \-ilname predicates always to return
|
---|
71 | false.
|
---|
72 |
|
---|
73 | .IP \-H
|
---|
74 | Do not follow symbolic links, except while processing the command
|
---|
75 | line arguments. When
|
---|
76 | .B find
|
---|
77 | examines or prints information about files, the information used
|
---|
78 | shall be taken from the properties of the symbolic link itself. The
|
---|
79 | only exception to this behaviour is when a file specified on the
|
---|
80 | command line is a symbolic link, and the link can be resolved. For
|
---|
81 | that situation, the information used is taken from whatever the link
|
---|
82 | points to (that is, the link is followed). The information about the
|
---|
83 | link itself is used as a fallback if the file pointed to by the
|
---|
84 | symbolic link cannot be examined. If \-H is in effect and one of the
|
---|
85 | paths specified on the command line is a symbolic link to a directory,
|
---|
86 | the contents of that directory will be examined (though of course
|
---|
87 | \-maxdepth 0 would prevent this).
|
---|
88 | .P
|
---|
89 | If more than one of \-H, \-L and \-P is specified, each overrides the
|
---|
90 | others; the last one appearing on the command line takes effect.
|
---|
91 | Since it is the default, the \-P option should be considered to be in
|
---|
92 | effect unless either \-H or \-L is specified.
|
---|
93 |
|
---|
94 | GNU
|
---|
95 | .B find
|
---|
96 | frequently stats files during the processing of the command line
|
---|
97 | itself, before any searching has begun. These options also affect how
|
---|
98 | those arguments are processed. Specifically, there are a number of
|
---|
99 | tests that compare files listed on the command line against a file we
|
---|
100 | are currently considering. In each case, the file specified on the
|
---|
101 | command line will have been examined and some of its properties will
|
---|
102 | have been saved. If the named file is in fact a symbolic link, and
|
---|
103 | the \-P option is in effect (or if neither \-H nor \-L were
|
---|
104 | specified), the information used for the comparison will be taken from
|
---|
105 | the properties of the symbolic link. Otherwise, it will be taken from
|
---|
106 | the properties of the file the link points to. If
|
---|
107 | .B find
|
---|
108 | cannot follow the link (for example because it has insufficient
|
---|
109 | privileges or the link points to a nonexistent file) the properties of
|
---|
110 | the link itself will be used.
|
---|
111 | .P
|
---|
112 | When the \-H or \-L options are in effect, any symbolic links listed
|
---|
113 | as the argument of \-newer will be dereferenced, and the timestamp
|
---|
114 | will be taken from the file to which the symbolic link points. The
|
---|
115 | same consideration applies to \-anewer and \-cnewer.
|
---|
116 |
|
---|
117 | The \-follow option has a similar effect to \-L, though it takes
|
---|
118 | effect at the point where it appears (that is, if \-L is not used but
|
---|
119 | \-follow is, any symbolic links appearing after \-follow on the
|
---|
120 | command line will be dereferenced, and those before it will not).
|
---|
121 |
|
---|
122 | .IP "\-D debugoptions"
|
---|
123 | Print diagnostic information; this can be helpful to diagnose problems
|
---|
124 | with why
|
---|
125 | .B find
|
---|
126 | is not doing what you want. The list of debug options should be comma
|
---|
127 | separated. Compatibility of the debug options is not guaranteed
|
---|
128 | between releases of findutils. For a complete list of valid debug
|
---|
129 | options, see the output of
|
---|
130 | .B find \-D
|
---|
131 | .BR help .
|
---|
132 | Valid debug options include
|
---|
133 | .RS
|
---|
134 | .IP help
|
---|
135 | Explain the debugging options
|
---|
136 | .IP tree
|
---|
137 | Show the expression tree in its original and optimised form.
|
---|
138 | .IP stat
|
---|
139 | Print messages as files are examined with the
|
---|
140 | .B stat
|
---|
141 | and
|
---|
142 | .B lstat
|
---|
143 | system calls. The
|
---|
144 | .B find
|
---|
145 | program tries to minimise such calls.
|
---|
146 | .IP opt
|
---|
147 | Prints diagnostic information relating to the optimisation of the
|
---|
148 | expression tree; see the \-O option.
|
---|
149 | .RE
|
---|
150 | .IP \-Olevel
|
---|
151 | Enables query optimisation. The
|
---|
152 | .B find
|
---|
153 | program reorders tests to speed up execution while preserving the
|
---|
154 | overall effect; that is, predicates with side effects are not
|
---|
155 | reordered relative to each other. The optimisations performed at each
|
---|
156 | optimisation level are as follows.
|
---|
157 | .RS
|
---|
158 | .IP 0
|
---|
159 | Equivalent to optimisation level 1.
|
---|
160 | .IP 1
|
---|
161 | This is the default optimisation level and corresponds to the
|
---|
162 | traditional behaviour. Expressions are reordered so that tests based
|
---|
163 | only on the names of files (for example \-name
|
---|
164 | and \-regex) are performed first.
|
---|
165 | .IP 2
|
---|
166 | Any \-type
|
---|
167 | or \-xtype
|
---|
168 | tests are performed after any tests based only on the names of files,
|
---|
169 | but before any tests that require information from the inode. On many
|
---|
170 | modern versions of Unix, file types are returned by
|
---|
171 | .B readdir()
|
---|
172 | and so these predicates are faster to evaluate than predicates which
|
---|
173 | need to stat the file first.
|
---|
174 | .IP 3
|
---|
175 | At this optimisation level, the full cost-based query optimiser is
|
---|
176 | enabled. The order of tests is modified so that cheap (i.e. fast)
|
---|
177 | tests are performed first and more expensive ones are performed later,
|
---|
178 | if necessary. Within each cost band, predicates are evaluated earlier
|
---|
179 | or later according to whether they are likely to succeed or not. For \-o,
|
---|
180 | predicates which are likely to succeed are evaluated earlier, and for \-a,
|
---|
181 | predicates which are likely to fail are evaluated earlier.
|
---|
182 | .RE
|
---|
183 | .IP
|
---|
184 | The cost-based optimiser has a fixed idea of how likely any given test
|
---|
185 | is to succeed. In some cases the probability takes account of the
|
---|
186 | specific nature of the test (for example, \-type f
|
---|
187 | is assumed to be more likely to succeed than \-type c).
|
---|
188 | The cost-based optimiser is currently being evaluated. If it does
|
---|
189 | not actually improve the performance of
|
---|
190 | .BR find ,
|
---|
191 | it will be removed again. Conversely, optimisations that prove to be
|
---|
192 | reliable, robust and effective may be enabled at lower optimisation
|
---|
193 | levels over time. However, the default behaviour (i.e. optimisation
|
---|
194 | level 1) will not be changed in the 4.3.x release series. The
|
---|
195 | findutils test suite runs all the tests on
|
---|
196 | .B find
|
---|
197 | at each optimisation level and ensures that the result is the same.
|
---|
198 | .P
|
---|
199 | .SH EXPRESSIONS
|
---|
200 | The expression is made up of options (which affect overall operation
|
---|
201 | rather than the processing of a specific file, and always return
|
---|
202 | true), tests (which return a true or false value), and actions (which
|
---|
203 | have side effects and return a true or false value), all separated by
|
---|
204 | operators. \-and is assumed where the operator is omitted.
|
---|
205 |
|
---|
206 | If the expression contains no actions other than \-prune, \-print is
|
---|
207 | performed on all files for which the expression is true.
|
---|
208 |
|
---|
209 | .SS OPTIONS
|
---|
210 | .P
|
---|
211 | All options always return true. Except for \-follow and \-daystart,
|
---|
212 | the options affect all tests, including tests specified before the
|
---|
213 | option. This is because the options are processed when the command
|
---|
214 | line is parsed, while the tests don't do anything until files are
|
---|
215 | examined. The \-follow and \-daystart options are different in this
|
---|
216 | respect, and have an effect only on tests which appear later in the
|
---|
217 | command line. Therefore, for clarity, it is best to place them at the
|
---|
218 | beginning of the expression. A warning is issued if you don't do
|
---|
219 | this.
|
---|
220 | .IP \-daystart
|
---|
221 | Measure times (for \-amin, \-atime, \-cmin, \-ctime, \-mmin, and \-mtime)
|
---|
222 | from the beginning of today rather than from 24 hours ago. This
|
---|
223 | option only affects tests which appear later on the command line.
|
---|
224 | .IP \-depth
|
---|
225 | Process each directory's contents before the directory itself.
|
---|
226 | .IP \-d
|
---|
227 | A synonym for \-depth, for compatibility with FreeBSD, NetBSD, MacOS X and OpenBSD.
|
---|
228 | .IP \-follow
|
---|
229 | Deprecated; use the \-L option instead. Dereference symbolic links.
|
---|
230 | Implies \-noleaf. The \-follow option affects only those tests which
|
---|
231 | appear after it on the command line. Unless the \-H or \-L option has
|
---|
232 | been specified, the position of the \-follow option changes the
|
---|
233 | behaviour of the \-newer predicate; any files listed as the argument
|
---|
234 | of \-newer will be dereferenced if they are symbolic links. The same
|
---|
235 | consideration applies to \-anewer and \-cnewer. Similarly, the \-type
|
---|
236 | predicate will always match against the type of the file that a
|
---|
237 | symbolic link points to rather than the link itself. Using \-follow
|
---|
238 | causes the \-lname and \-ilname predicates always to return false.
|
---|
239 | .IP "\-help, \-\-help"
|
---|
240 | Print a summary of the command-line usage of
|
---|
241 | .B find
|
---|
242 | and exit.
|
---|
243 | .IP \-ignore_readdir_race
|
---|
244 | Normally, \fBfind\fR will emit an error message when it fails to stat a file.
|
---|
245 | If you give this option and a file is deleted between the time \fBfind\fR
|
---|
246 | reads the name of the file from the directory and the time it tries to stat
|
---|
247 | the file, no error message will be issued. This also applies to files
|
---|
248 | or directories whose names are given on the command line. This option takes
|
---|
249 | effect at the time the command line is read, which means that you cannot search
|
---|
250 | one part of the filesystem with this option on and part of it with this option
|
---|
251 | off (if you need to do that, you will need to issue two \fBfind\fR commands
|
---|
252 | instead, one with the option and one without it).
|
---|
253 | .IP "\-maxdepth \fIlevels\fR"
|
---|
254 | Descend at most \fIlevels\fR (a non-negative integer) levels of
|
---|
255 | directories below the command line arguments. `\-maxdepth 0' means
|
---|
256 | only apply the tests and actions to the command line arguments.
|
---|
257 | .IP "\-mindepth \fIlevels\fR"
|
---|
258 | Do not apply any tests or actions at levels less than \fIlevels\fR (a
|
---|
259 | non-negative integer). `\-mindepth 1' means process all files except
|
---|
260 | the command line arguments.
|
---|
261 | .IP \-mount
|
---|
262 | Don't descend directories on other filesystems. An alternate name for
|
---|
263 | \-xdev, for compatibility with some other versions of
|
---|
264 | .BR find .
|
---|
265 | .IP \-noignore_readdir_race
|
---|
266 | Turns off the effect of \-ignore_readdir_race.
|
---|
267 | .IP "\-noleaf"
|
---|
268 | Do not optimize by assuming that directories contain 2 fewer
|
---|
269 | subdirectories than their hard link count. This option is needed when
|
---|
270 | searching filesystems that do not follow the Unix directory-link
|
---|
271 | convention, such as CD-ROM or MS-DOS filesystems or AFS volume mount
|
---|
272 | points. Each directory on a normal Unix filesystem has at least 2
|
---|
273 | hard links: its name and its `.' entry. Additionally, its
|
---|
274 | subdirectories (if any) each have a `..' entry linked to that
|
---|
275 | directory. When
|
---|
276 | .B find
|
---|
277 | is examining a directory, after it has statted 2 fewer subdirectories
|
---|
278 | than the directory's link count, it knows that the rest of the entries
|
---|
279 | in the directory are non-directories (`leaf' files in the directory
|
---|
280 | tree). If only the files' names need to be examined, there is no need
|
---|
281 | to stat them; this gives a significant increase in search speed.
|
---|
282 | .IP "\-readable, \-writable, \-executable"
|
---|
283 | Matches files which are readable, writable and executable,
|
---|
284 | respectively. This takes into account access control lists and other
|
---|
285 | permissions artefacts which the \-perm test ignores. This test makes
|
---|
286 | use of the
|
---|
287 | .BR access (2)
|
---|
288 | system call, and so can be fooled by NFS servers which do UID
|
---|
289 | mapping (or root-squashing), since many systems implement
|
---|
290 | .BR access (2)
|
---|
291 | in the client's kernel and so cannot make use of the UID mapping
|
---|
292 | information held on the server.
|
---|
293 | .IP "\-regextype \fItype\fR"
|
---|
294 | Changes the regular expression syntax understood by
|
---|
295 | .B \-regex
|
---|
296 | and
|
---|
297 | .B \-iregex
|
---|
298 | tests which occur later on the command line. Currently-implemented
|
---|
299 | types are emacs (this is the default), posix-awk, posix-basic,
|
---|
300 | posix-egrep and posix-extended.
|
---|
301 |
|
---|
302 | .IP "\-version, \-\-version"
|
---|
303 | Print the \fBfind\fR version number and exit.
|
---|
304 | .IP "\-warn, \-nowarn"
|
---|
305 | Turn warning messages on or off. These warnings apply only to the
|
---|
306 | command line usage, not to any conditions that
|
---|
307 | .B find
|
---|
308 | might encounter when it searches directories. The default behaviour
|
---|
309 | corresponds to \-warn if standard input is a tty, and to \-nowarn
|
---|
310 | otherwise.
|
---|
311 | .IP \-xdev
|
---|
312 | Don't descend directories on other filesystems.
|
---|
313 |
|
---|
314 | .SS TESTS
|
---|
315 | .P
|
---|
316 | Numeric arguments can be specified as
|
---|
317 | .IP \fI+n\fP
|
---|
318 | for greater than
|
---|
319 | .IR n ,
|
---|
320 | .IP \fI\-n\fP
|
---|
321 | for less than
|
---|
322 | .IR n ,
|
---|
323 | .IP \fIn\fP
|
---|
324 | for exactly
|
---|
325 | .IR n .
|
---|
326 | .IP "\-amin \fIn\fR"
|
---|
327 | File was last accessed \fIn\fR minutes ago.
|
---|
328 | .IP "\-anewer \fIfile\fR"
|
---|
329 | File was last accessed more recently than \fIfile\fR was modified. If
|
---|
330 | \fIfile\fR is a symbolic link and the \-H option or the \-L option is
|
---|
331 | in effect, the access time of the file it points to is always
|
---|
332 | used.
|
---|
333 | .IP "\-atime \fIn\fR"
|
---|
334 | File was last accessed \fIn\fR*24 hours ago.
|
---|
335 | When find figures out how many 24-hour periods ago the file
|
---|
336 | was last accessed, any fractional part is ignored, so to match
|
---|
337 | .B \-atime
|
---|
338 | .BR +1 ,
|
---|
339 | a file has to have been accessed at least
|
---|
340 | .I two
|
---|
341 | days ago.
|
---|
342 | .IP "\-cmin \fIn\fR"
|
---|
343 | File's status was last changed \fIn\fR minutes ago.
|
---|
344 | .IP "\-cnewer \fIfile\fR"
|
---|
345 | File's status was last changed more recently than \fIfile\fR was
|
---|
346 | modified. If \fIfile\fR is a symbolic link and the \-H option or the
|
---|
347 | \-L option is in effect, the status-change time of the file it points
|
---|
348 | to is always used.
|
---|
349 |
|
---|
350 | .IP "\-ctime \fIn\fR"
|
---|
351 | File's status was last changed \fIn\fR*24 hours ago.
|
---|
352 | See the comments for
|
---|
353 | .B \-atime
|
---|
354 | to understand how rounding affects the interpretation of file status
|
---|
355 | change times.
|
---|
356 | .IP \-empty
|
---|
357 | File is empty and is either a regular file or a directory.
|
---|
358 | .IP \-false
|
---|
359 | Always false.
|
---|
360 | .IP "\-fstype \fItype\fR"
|
---|
361 | File is on a filesystem of type \fItype\fR. The valid filesystem
|
---|
362 | types vary among different versions of Unix; an incomplete list of
|
---|
363 | filesystem types that are accepted on some version of Unix or another
|
---|
364 | is: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K. You can use \-printf
|
---|
365 | with the %F directive to see the types of your filesystems.
|
---|
366 | .IP "\-gid \fIn\fR"
|
---|
367 | File's numeric group ID is \fIn\fR.
|
---|
368 | .IP "\-group \fIgname\fR"
|
---|
369 | File belongs to group \fIgname\fR (numeric group ID allowed).
|
---|
370 | .IP "\-ilname \fIpattern\fR"
|
---|
371 | Like \-lname, but the match is case insensitive.
|
---|
372 | If the \-L option or the \-follow option is in effect, this test
|
---|
373 | returns false unless the symbolic link is broken.
|
---|
374 | .IP "\-iname \fIpattern\fR"
|
---|
375 | Like \-name, but the match is case insensitive. For example, the
|
---|
376 | patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo',
|
---|
377 | `fOo', etc. In these patterns, unlike filename expansion by the
|
---|
378 | shell, an initial '.' can be matched by '*'. That is,
|
---|
379 | .B find \-name *bar
|
---|
380 | will match the file `.foobar'. Please note that you should quote
|
---|
381 | patterns as a matter of course, otherwise the shell will expand any
|
---|
382 | wildcard characters in them.
|
---|
383 |
|
---|
384 | .IP "\-inum \fIn\fR"
|
---|
385 | File has inode number \fIn\fR. It is normally easier to use the
|
---|
386 | .B \-samefile
|
---|
387 | test instead.
|
---|
388 | .IP "\-ipath \fIpattern\fR"
|
---|
389 | Behaves in the same way as \-iwholename. This option is deprecated,
|
---|
390 | so please do not use it.
|
---|
391 | .IP "\-iregex \fIpattern\fR"
|
---|
392 | Like \-regex, but the match is case insensitive.
|
---|
393 | .IP "\-iwholename \fIpattern\fR"
|
---|
394 | Like \-wholename, but the match is case insensitive.
|
---|
395 | .IP "\-links \fIn\fR"
|
---|
396 | File has \fIn\fR links.
|
---|
397 | .IP "\-lname \fIpattern\fR"
|
---|
398 | File is a symbolic link whose contents match shell pattern
|
---|
399 | \fIpattern\fR. The metacharacters do not treat `/' or `.' specially.
|
---|
400 | If the \-L option or the \-follow option is in effect, this test
|
---|
401 | returns false unless the symbolic link is broken.
|
---|
402 | .IP "\-mmin \fIn\fR"
|
---|
403 | File's data was last modified \fIn\fR minutes ago.
|
---|
404 | .IP "\-mtime \fIn\fR"
|
---|
405 | File's data was last modified \fIn\fR*24 hours ago.
|
---|
406 | See the comments for
|
---|
407 | .B \-atime
|
---|
408 | to understand how rounding affects the interpretation of file
|
---|
409 | modification times.
|
---|
410 | .IP "\-name \fIpattern\fR"
|
---|
411 | Base of file name (the path with the leading directories removed)
|
---|
412 | matches shell pattern \fIpattern\fR. The metacharacters (`*', `?',
|
---|
413 | and `[]') match a `.' at the start of the base name (this is a change
|
---|
414 | in findutils-4.2.2; see section STANDARDS CONFORMANCE below). To ignore a
|
---|
415 | directory and the files under it, use \-prune; see an example in the
|
---|
416 | description of \-wholename. Braces are not recognised as being
|
---|
417 | special, despite the fact that some shells including Bash imbue braces
|
---|
418 | with a special meaning in shell patterns. The filename matching is
|
---|
419 | performed with the use of the
|
---|
420 | .BR fnmatch (3)
|
---|
421 | library function. Don't forget to enclose the pattern in quotes
|
---|
422 | in order to protect it from expansion by the shell.
|
---|
423 |
|
---|
424 | .IP "\-newer \fIfile\fR"
|
---|
425 | File was modified more recently than \fIfile\fR. If \fIfile\fR is a
|
---|
426 | symbolic link and the \-H option or the \-L option is in effect, the
|
---|
427 | modification time of the file it points to is always used.
|
---|
428 | .IP \-nouser
|
---|
429 | No user corresponds to file's numeric user ID.
|
---|
430 | .IP \-nogroup
|
---|
431 | No group corresponds to file's numeric group ID.
|
---|
432 | .IP "\-path \fIpattern\fR"
|
---|
433 | See \-wholename. The predicate \-path is also supported by HP-UX
|
---|
434 | .BR find .
|
---|
435 | .IP "\-perm \fImode\fR"
|
---|
436 | File's permission bits are exactly \fImode\fR (octal or symbolic).
|
---|
437 | Since an exact match is required, if you want to use this form for
|
---|
438 | symbolic modes, you may have to specify a rather complex mode string.
|
---|
439 | For example '\-perm g=w' will only match files which have mode 0020
|
---|
440 | (that is, ones for which group write permission is the only permission
|
---|
441 | set). It is more likely that you will want to use the '/' or '-'
|
---|
442 | forms, for example '\-perm \-g=w', which matches any file with group
|
---|
443 | write permission. See the
|
---|
444 | .B EXAMPLES
|
---|
445 | section for some illustrative examples.
|
---|
446 | .IP "\-perm \-\fImode\fR"
|
---|
447 | All of the permission bits \fImode\fR are set for the file.
|
---|
448 | Symbolic modes are accepted in this form, and this is usually the way
|
---|
449 | in which would want to use them. You must specify 'u', 'g' or 'o' if
|
---|
450 | you use a symbolic mode. See the
|
---|
451 | .B EXAMPLES
|
---|
452 | section for some illustrative examples.
|
---|
453 | .IP "\-perm /\fImode\fR"
|
---|
454 | Any of the permission bits \fImode\fR are set for the file. Symbolic
|
---|
455 | modes are accepted in this form. You must specify 'u', 'g' or 'o' if
|
---|
456 | you use a symbolic mode. See the
|
---|
457 | .B EXAMPLES
|
---|
458 | section for some illustrative examples. If no permission bits in
|
---|
459 | .I mode
|
---|
460 | are set, this test currently matches no files. However, it will soon
|
---|
461 | be changed to match any file (the idea is to be more consistent with
|
---|
462 | the behaviour of
|
---|
463 | .B perm
|
---|
464 | .BR \-000 ).
|
---|
465 | .IP "\-perm +\fImode\fR"
|
---|
466 | Deprecated, old way of searching for files with any of the permission
|
---|
467 | bits in \fImode\fR set. You should use
|
---|
468 | .B \-perm \fI/mode\fR
|
---|
469 | instead. Trying to use the '+' syntax with symbolic modes will yield
|
---|
470 | surprising results. For example, '+u+x' is a valid symbolic mode
|
---|
471 | (equivalent to +u,+x, i.e. 0111) and will therefore not be evaluated
|
---|
472 | as
|
---|
473 | .B \-perm +\fImode\fR
|
---|
474 | but instead as the exact mode specifier
|
---|
475 | .B \-perm \fImode\fR
|
---|
476 | and so it matches files with exact permissions 0111 instead of files with any
|
---|
477 | execute bit set. If you found this paragraph confusing, you're not
|
---|
478 | alone - just use
|
---|
479 | .B \-perm /\fImode\fR.
|
---|
480 | This form of the
|
---|
481 | .B \-perm
|
---|
482 | test is deprecated because the POSIX specification requires the
|
---|
483 | interpretation of a leading '+' as being part of a symbolic mode, and
|
---|
484 | so we switched to using '/' instead.
|
---|
485 |
|
---|
486 | .IP "\-regex \fIpattern\fR"
|
---|
487 | File name matches regular expression \fIpattern\fR. This is a match
|
---|
488 | on the whole path, not a search. For example, to match a file named
|
---|
489 | `./fubar3', you can use the regular expression `.*bar.' or `.*b.*3',
|
---|
490 | but not `f.*r3'. The regular expressions understood by
|
---|
491 | .B find
|
---|
492 | are by default Emacs Regular Expressions, but this can be
|
---|
493 | changed with the
|
---|
494 | .B \-regextype
|
---|
495 | option.
|
---|
496 | .IP "\-samefile \fIname\fR"
|
---|
497 | File refers to the same inode as \fIname\fR. When \-L is in effect,
|
---|
498 | this can include symbolic links.
|
---|
499 | .IP "\-size \fIn\fR[cwbkMG]"
|
---|
500 | File uses \fIn\fP units of space. The following suffixes
|
---|
501 | can be used:
|
---|
502 | .RS
|
---|
503 | .IP `b'
|
---|
504 | for 512-byte blocks (this is the default if no suffix is used)
|
---|
505 | .IP `c'
|
---|
506 | for bytes
|
---|
507 | .IP `w'
|
---|
508 | for two-byte words
|
---|
509 | .IP `k'
|
---|
510 | for Kilobytes (units of 1024 bytes)
|
---|
511 | .IP `M'
|
---|
512 | for Megabytes (units of 1048576 bytes)
|
---|
513 | .IP `G'
|
---|
514 | for Gigabytes (units of 1073741824 bytes)
|
---|
515 | .RE
|
---|
516 | .IP
|
---|
517 | The size does not count indirect blocks, but it does count blocks in
|
---|
518 | sparse files that are not actually allocated. Bear in mind that the
|
---|
519 | `%k' and `%b' format specifiers of \-printf handle sparse files
|
---|
520 | differently. The `b' suffix always denotes 512-byte blocks and never
|
---|
521 | 1 Kilobyte blocks, which is different to the behaviour of \-ls.
|
---|
522 |
|
---|
523 | .IP \-true
|
---|
524 | Always true.
|
---|
525 | .IP "\-type \fIc\fR"
|
---|
526 | File is of type \fIc\fR:
|
---|
527 | .RS
|
---|
528 | .IP b
|
---|
529 | block (buffered) special
|
---|
530 | .IP c
|
---|
531 | character (unbuffered) special
|
---|
532 | .IP d
|
---|
533 | directory
|
---|
534 | .IP p
|
---|
535 | named pipe (FIFO)
|
---|
536 | .IP f
|
---|
537 | regular file
|
---|
538 | .IP l
|
---|
539 | symbolic link; this is never true if the \-L option or the \-follow
|
---|
540 | option is in effect, unless the symbolic link is broken. If you want
|
---|
541 | to search for symbolic links when \-L is in effect, use \-xtype.
|
---|
542 | .IP s
|
---|
543 | socket
|
---|
544 | .IP D
|
---|
545 | door (Solaris)
|
---|
546 | .RE
|
---|
547 | .IP "\-uid \fIn\fR"
|
---|
548 | File's numeric user ID is \fIn\fR.
|
---|
549 | .IP "\-used \fIn\fR"
|
---|
550 | File was last accessed \fIn\fR days after its status was last changed.
|
---|
551 | .IP "\-user \fIuname\fR"
|
---|
552 | File is owned by user \fIuname\fR (numeric user ID allowed).
|
---|
553 | .IP "\-wholename \fIpattern\fR"
|
---|
554 | File name matches shell pattern \fIpattern\fR. The metacharacters do
|
---|
555 | not treat `/' or `.' specially; so, for example,
|
---|
556 | .br
|
---|
557 | .in +1i
|
---|
558 | find . \-wholename './sr*sc'
|
---|
559 | .br
|
---|
560 | .in -1i
|
---|
561 | will print an entry for a directory called './src/misc' (if one
|
---|
562 | exists). To ignore a whole directory tree, use \-prune rather than
|
---|
563 | checking every file in the tree. For example, to skip the
|
---|
564 | directory `src/emacs' and all files and directories under it, and
|
---|
565 | print the names of the other files found, do something like this:
|
---|
566 | .br
|
---|
567 | .in +1i
|
---|
568 | find . \-wholename './src/emacs' \-prune \-o \-print
|
---|
569 | .br
|
---|
570 | .in -1i
|
---|
571 | .IP "\-xtype \fIc\fR"
|
---|
572 | The same as \-type unless the file is a symbolic link. For symbolic
|
---|
573 | links: if the \-H or \-P option was specified, true if the file is a
|
---|
574 | link to a file of type \fIc\fR; if the \-L option has been given, true
|
---|
575 | if \fIc\fR is `l'. In other words, for symbolic links, \-xtype checks
|
---|
576 | the type of the file that \-type does not check.
|
---|
577 |
|
---|
578 | .SS ACTIONS
|
---|
579 | .IP "\-delete\fR"
|
---|
580 | Delete files; true if removal succeeded. If the removal failed, an
|
---|
581 | error message is issued. Use of this action automatically turns on
|
---|
582 | the '\-depth' option.
|
---|
583 |
|
---|
584 | .IP "\-exec \fIcommand\fR ;"
|
---|
585 | Execute \fIcommand\fR; true if 0 status is returned. All following
|
---|
586 | arguments to
|
---|
587 | .B find
|
---|
588 | are taken to be arguments to the command until an argument consisting
|
---|
589 | of `;' is encountered. The string `{}' is replaced by the current
|
---|
590 | file name being processed everywhere it occurs in the arguments to the
|
---|
591 | command, not just in arguments where it is alone, as in some versions
|
---|
592 | of
|
---|
593 | .BR find .
|
---|
594 | Both of these constructions might need to be escaped (with a `\e') or
|
---|
595 | quoted to protect them from expansion by the shell. See the
|
---|
596 | .B EXAMPLES
|
---|
597 | section for examples of the use of the `\-exec' option. The specified
|
---|
598 | command is run once for each matched file.
|
---|
599 | The command is executed in the starting directory. There are
|
---|
600 | unavoidable security problems surrounding use of the \-exec option;
|
---|
601 | you should use the \-execdir option instead.
|
---|
602 |
|
---|
603 | .IP "\-exec \fIcommand\fR {} +"
|
---|
604 | This variant of the \-exec option runs the specified command on the
|
---|
605 | selected files, but the command line is built by appending each
|
---|
606 | selected file name at the end; the total number of invocations of the
|
---|
607 | command will be much less than the number of matched files. The
|
---|
608 | command line is built in much the same way that
|
---|
609 | .B xargs
|
---|
610 | builds its command lines. Only one instance of '{}' is allowed within
|
---|
611 | the command. The command is executed in the starting directory.
|
---|
612 |
|
---|
613 | .IP "\-execdir \fIcommand\fR ;"
|
---|
614 | .IP "\-execdir \fIcommand\fR {} +"
|
---|
615 | Like \-exec, but the specified command is run from the subdirectory
|
---|
616 | containing the matched file, which is not normally the directory in
|
---|
617 | which you started
|
---|
618 | .BR find .
|
---|
619 | This a much more secure method for invoking commands, as it avoids
|
---|
620 | race conditions during resolution of the paths to the matched files.
|
---|
621 | As with the \-exec option, the '+' form of \-execdir will build a
|
---|
622 | command line to process more than one matched file, but any given
|
---|
623 | invocation of
|
---|
624 | .I command
|
---|
625 | will only list files that exist in the same subdirectory. If you use
|
---|
626 | this option, you must ensure that your
|
---|
627 | .B $PATH
|
---|
628 | environment variable does not reference the current directory;
|
---|
629 | otherwise, an attacker can run any commands they like by leaving an
|
---|
630 | appropriately-named file in a directory in which you will run
|
---|
631 | \-execdir.
|
---|
632 |
|
---|
633 | .IP "\-fls \fIfile\fR"
|
---|
634 | True; like \-ls but write to \fIfile\fR like \-fprint.
|
---|
635 | The output file is always created, even if the predicate is never
|
---|
636 | matched.
|
---|
637 | See the
|
---|
638 | .B UNUSUAL FILENAMES
|
---|
639 | section for information about how unusual characters in filenames are handled.
|
---|
640 |
|
---|
641 | .IP "\-fprint \fIfile\fR"
|
---|
642 | True; print the full file name into file \fIfile\fR. If \fIfile\fR
|
---|
643 | does not exist when \fBfind\fR is run, it is created; if it does
|
---|
644 | exist, it is truncated. The file names ``/dev/stdout'' and
|
---|
645 | ``/dev/stderr'' are handled specially; they refer to the standard
|
---|
646 | output and standard error output, respectively.
|
---|
647 | The output file is always created, even if the predicate is never matched.
|
---|
648 | See the
|
---|
649 | .B UNUSUAL FILENAMES
|
---|
650 | section for information about how unusual characters in filenames are handled.
|
---|
651 | .IP "\-fprint0 \fIfile\fR"
|
---|
652 | True; like \-print0 but write to \fIfile\fR like \-fprint.
|
---|
653 | The output file is always created, even if the predicate is never matched.
|
---|
654 | See the
|
---|
655 | .B UNUSUAL FILENAMES
|
---|
656 | section for information about how unusual characters in filenames are handled.
|
---|
657 | .IP "\-fprintf \fIfile\fR \fIformat\fR"
|
---|
658 | True; like \-printf but write to \fIfile\fR like \-fprint.
|
---|
659 | The output file is always created, even if the predicate is never matched.
|
---|
660 | See the
|
---|
661 | .B UNUSUAL FILENAMES
|
---|
662 | section for information about how unusual characters in filenames are handled.
|
---|
663 | .IP "\-ok \fIcommand\fR ;"
|
---|
664 | Like \-exec but ask the user first (on the standard input); if the
|
---|
665 | response does not start with `y' or `Y', do not run the command, and
|
---|
666 | return false. If the command is run, its standard input is redirected
|
---|
667 | from
|
---|
668 | .BR /dev/null .
|
---|
669 |
|
---|
670 | .IP \-print
|
---|
671 | True; print the full file name on the standard output, followed by a
|
---|
672 | newline. If you are piping the output of
|
---|
673 | .B find
|
---|
674 | into another program and there is the faintest possibility that the files
|
---|
675 | which you are searching for might contain a newline, then you should
|
---|
676 | seriously consider using the `\-print0' option instead of `\-print'.
|
---|
677 | See the
|
---|
678 | .B UNUSUAL FILENAMES
|
---|
679 | section for information about how unusual characters in filenames are handled.
|
---|
680 | .IP "\-okdir \fIcommand\fR ;"
|
---|
681 | Like \-execdir but ask the user first (on the standard input); if the
|
---|
682 | response does not start with `y' or `Y', do not run the command, and
|
---|
683 | return false. If the command is run, its standard input is redirected
|
---|
684 | from
|
---|
685 | .BR /dev/null .
|
---|
686 | .IP \-print0
|
---|
687 | True; print the full file name on the standard output, followed by a
|
---|
688 | null character (instead of the newline character that `\-print' uses).
|
---|
689 | This allows file names that contain newlines or other types of white
|
---|
690 | space to be correctly interpreted by programs that process the
|
---|
691 | \fBfind\fR output. This option corresponds to the `\-0' option of
|
---|
692 | .BR xargs .
|
---|
693 | .IP "\-printf \fIformat\fR"
|
---|
694 | True; print \fIformat\fR on the standard output, interpreting `\e'
|
---|
695 | escapes and `%' directives. Field widths and precisions can be
|
---|
696 | specified as with the `printf' C function. Please note that many of
|
---|
697 | the fields are printed as %s rather than %d, and this may mean that
|
---|
698 | flags don't work as you might expect. This also means that the `\-'
|
---|
699 | flag does work (it forces fields to be left-aligned). Unlike \-print,
|
---|
700 | \-printf does not add a newline at the end of the string. The escapes
|
---|
701 | and directives are:
|
---|
702 | .RS
|
---|
703 | .IP \ea
|
---|
704 | Alarm bell.
|
---|
705 | .IP \eb
|
---|
706 | Backspace.
|
---|
707 | .IP \ec
|
---|
708 | Stop printing from this format immediately and flush the output.
|
---|
709 | .IP \ef
|
---|
710 | Form feed.
|
---|
711 | .IP \en
|
---|
712 | Newline.
|
---|
713 | .IP \er
|
---|
714 | Carriage return.
|
---|
715 | .IP \et
|
---|
716 | Horizontal tab.
|
---|
717 | .IP \ev
|
---|
718 | Vertical tab.
|
---|
719 | .IP \e\0
|
---|
720 | ASCII NUL.
|
---|
721 | .IP \e\e
|
---|
722 | A literal backslash (`\e').
|
---|
723 | .IP \eNNN
|
---|
724 | The character whose ASCII code is NNN (octal).
|
---|
725 | .PP
|
---|
726 | A `\e' character followed by any other character is treated as an
|
---|
727 | ordinary character, so they both are printed.
|
---|
728 | .IP %%
|
---|
729 | A literal percent sign.
|
---|
730 | .IP %a
|
---|
731 | File's last access time in the format returned by the C `ctime' function.
|
---|
732 | .IP %A\fIk\fP
|
---|
733 | File's last access time in the format specified by \fIk\fR, which is
|
---|
734 | either `@' or a directive for the C `strftime' function. The possible
|
---|
735 | values for \fIk\fR are listed below; some of them might not be
|
---|
736 | available on all systems, due to differences in `strftime' between
|
---|
737 | systems.
|
---|
738 | .RS
|
---|
739 | .IP @
|
---|
740 | seconds since Jan. 1, 1970, 00:00 GMT.
|
---|
741 | .PP
|
---|
742 | Time fields:
|
---|
743 | .IP H
|
---|
744 | hour (00..23)
|
---|
745 | .IP I
|
---|
746 | hour (01..12)
|
---|
747 | .IP k
|
---|
748 | hour ( 0..23)
|
---|
749 | .IP l
|
---|
750 | hour ( 1..12)
|
---|
751 | .IP M
|
---|
752 | minute (00..59)
|
---|
753 | .IP p
|
---|
754 | locale's AM or PM
|
---|
755 | .IP r
|
---|
756 | time, 12-hour (hh:mm:ss [AP]M)
|
---|
757 | .IP S
|
---|
758 | second (00..61)
|
---|
759 | .IP T
|
---|
760 | time, 24-hour (hh:mm:ss)
|
---|
761 | .IP +
|
---|
762 | Date and time, separated by '+', for example `2004\-04\-28+22:22:05'.
|
---|
763 | The time is given in the current timezone (which may be affected by
|
---|
764 | setting the TZ environment variable). This is a GNU extension.
|
---|
765 | .IP X
|
---|
766 | locale's time representation (H:M:S)
|
---|
767 | .IP Z
|
---|
768 | time zone (e.g., EDT), or nothing if no time zone is determinable
|
---|
769 | .PP
|
---|
770 | Date fields:
|
---|
771 | .IP a
|
---|
772 | locale's abbreviated weekday name (Sun..Sat)
|
---|
773 | .IP A
|
---|
774 | locale's full weekday name, variable length (Sunday..Saturday)
|
---|
775 | .IP b
|
---|
776 | locale's abbreviated month name (Jan..Dec)
|
---|
777 | .IP B
|
---|
778 | locale's full month name, variable length (January..December)
|
---|
779 | .IP c
|
---|
780 | locale's date and time (Sat Nov 04 12:02:33 EST 1989)
|
---|
781 | .IP d
|
---|
782 | day of month (01..31)
|
---|
783 | .IP D
|
---|
784 | date (mm/dd/yy)
|
---|
785 | .IP h
|
---|
786 | same as b
|
---|
787 | .IP j
|
---|
788 | day of year (001..366)
|
---|
789 | .IP m
|
---|
790 | month (01..12)
|
---|
791 | .IP U
|
---|
792 | week number of year with Sunday as first day of week (00..53)
|
---|
793 | .IP w
|
---|
794 | day of week (0..6)
|
---|
795 | .IP W
|
---|
796 | week number of year with Monday as first day of week (00..53)
|
---|
797 | .IP x
|
---|
798 | locale's date representation (mm/dd/yy)
|
---|
799 | .IP y
|
---|
800 | last two digits of year (00..99)
|
---|
801 | .IP Y
|
---|
802 | year (1970...)
|
---|
803 | .RE
|
---|
804 | .IP %b
|
---|
805 | The amount of disk space used for this file in 512-byte blocks. Since disk
|
---|
806 | space is allocated in multiples of the filesystem block size this is usually
|
---|
807 | greater than %s/1024, but it can also be smaller if the file is a sparse file.
|
---|
808 | .IP %c
|
---|
809 | File's last status change time in the format returned by the C `ctime'
|
---|
810 | function.
|
---|
811 | .IP %C\fIk\fP
|
---|
812 | File's last status change time in the format specified by \fIk\fR,
|
---|
813 | which is the same as for %A.
|
---|
814 | .IP %d
|
---|
815 | File's depth in the directory tree; 0 means the file is a command line
|
---|
816 | argument.
|
---|
817 | .IP %D
|
---|
818 | The device number on which the file exists (the st_dev field of struct
|
---|
819 | stat), in decimal.
|
---|
820 | .IP %f
|
---|
821 | File's name with any leading directories removed (only the last element).
|
---|
822 | .IP %F
|
---|
823 | Type of the filesystem the file is on; this value can be used for
|
---|
824 | \-fstype.
|
---|
825 | .IP %g
|
---|
826 | File's group name, or numeric group ID if the group has no name.
|
---|
827 | .IP %G
|
---|
828 | File's numeric group ID.
|
---|
829 | .IP %h
|
---|
830 | Leading directories of file's name (all but the last element).
|
---|
831 | If the file name contains no slashes (since it is in the current
|
---|
832 | directory) the %h specifier expands to ".".
|
---|
833 | .IP %H
|
---|
834 | Command line argument under which file was found.
|
---|
835 | .IP %i
|
---|
836 | File's inode number (in decimal).
|
---|
837 | .IP %k
|
---|
838 | The amount of disk space used for this file in 1K blocks. Since disk space is
|
---|
839 | allocated in multiples of the filesystem block size this is usually greater
|
---|
840 | than %s/1024, but it can also be smaller if the file is a sparse file.
|
---|
841 | .IP %l
|
---|
842 | Object of symbolic link (empty string if file is not a symbolic link).
|
---|
843 | .IP %m
|
---|
844 | File's permission bits (in octal). This option uses the 'traditional'
|
---|
845 | numbers which most Unix implementations use, but if your particular
|
---|
846 | implementation uses an unusual ordering of octal permissions bits, you
|
---|
847 | will see a difference between the actual value of the file's mode and
|
---|
848 | the output of %m. Normally you will want to have a leading
|
---|
849 | zero on this number, and to do this, you should use the
|
---|
850 | .B #
|
---|
851 | flag (as in, for example, '%#m').
|
---|
852 | .IP %M
|
---|
853 | File's permissions (in symbolic form, as for
|
---|
854 | .BR ls ).
|
---|
855 | This directive is supported in findutils 4.2.5 and later.
|
---|
856 | .IP %n
|
---|
857 | Number of hard links to file.
|
---|
858 | .IP %p
|
---|
859 | File's name.
|
---|
860 | .IP %P
|
---|
861 | File's name with the name of the command line argument under which
|
---|
862 | it was found removed.
|
---|
863 | .IP %s
|
---|
864 | File's size in bytes.
|
---|
865 | .IP %t
|
---|
866 | File's last modification time in the format returned by the C `ctime'
|
---|
867 | function.
|
---|
868 | .IP %T\fIk\fP
|
---|
869 | File's last modification time in the format specified by \fIk\fR,
|
---|
870 | which is the same as for %A.
|
---|
871 | .IP %u
|
---|
872 | File's user name, or numeric user ID if the user has no name.
|
---|
873 | .IP %U
|
---|
874 | File's numeric user ID.
|
---|
875 | .IP %y
|
---|
876 | File's type (like in ls \-l), U=unknown type (shouldn't happen)
|
---|
877 | .IP %Y
|
---|
878 | File's type (like %y), plus follow symlinks: L=loop, N=nonexistent
|
---|
879 | .PP
|
---|
880 | A `%' character followed by any other character is discarded, but the
|
---|
881 | other character is printed (don't rely on this, as further format
|
---|
882 | characters may be introduced). A `%' at the end of the format
|
---|
883 | argument causes undefined behaviour since there is no following
|
---|
884 | character. In some locales, it may hide your door keys, while in
|
---|
885 | others it may remove the final page from the novel you are reading.
|
---|
886 |
|
---|
887 | The %m and %d directives support the
|
---|
888 | .B #
|
---|
889 | ,
|
---|
890 | .B 0
|
---|
891 | and
|
---|
892 | .B +
|
---|
893 | flags, but the other directives do not, even if they
|
---|
894 | print numbers. Numeric directives that do not support these flags
|
---|
895 | include
|
---|
896 | .BR G ,
|
---|
897 | .BR U ,
|
---|
898 | .BR b ,
|
---|
899 | .BR D ,
|
---|
900 | .B k
|
---|
901 | and
|
---|
902 | .BR n .
|
---|
903 | The `\-' format flag is supported and changes the alignment of a field
|
---|
904 | from right-justified (which is the default) to left-justified.
|
---|
905 | .PP
|
---|
906 | See the
|
---|
907 | .B UNUSUAL FILENAMES
|
---|
908 | section for information about how unusual characters in filenames are handled.
|
---|
909 |
|
---|
910 |
|
---|
911 | .RE
|
---|
912 | .IP \-prune
|
---|
913 | If \-depth is not given, true; if the file is a directory, do not descend
|
---|
914 | into it.
|
---|
915 | .br
|
---|
916 | If \-depth is given, false; no effect.
|
---|
917 |
|
---|
918 | .IP "\-quit"
|
---|
919 | Exit immediately. No child processes will be left running, but no more
|
---|
920 | paths specified on the command line will be processed. For example,
|
---|
921 | .B find /tmp/foo /tmp/bar \-print \-quit
|
---|
922 | will print only
|
---|
923 | .BR /tmp/foo .
|
---|
924 | Any command lines which have been built up with
|
---|
925 | .B \-execdir ... {} +
|
---|
926 | will be invoked before
|
---|
927 | .B find
|
---|
928 | exits. The exit status may or may not be zero, depending on whether
|
---|
929 | an error has already occurred.
|
---|
930 |
|
---|
931 | .IP \-ls
|
---|
932 | True; list current file in `ls \-dils' format on standard output.
|
---|
933 | The block counts are of 1K blocks, unless the environment variable
|
---|
934 | POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
|
---|
935 | See the
|
---|
936 | .B UNUSUAL FILENAMES
|
---|
937 | section for information about how unusual characters in filenames are handled.
|
---|
938 |
|
---|
939 |
|
---|
940 | .SS UNUSUAL FILENAMES
|
---|
941 | Many of the actions of
|
---|
942 | .B find
|
---|
943 | result in the printing of data which is under the control of other
|
---|
944 | users. This includes file names, sizes, modification times and so
|
---|
945 | forth. File names are a potential problem since they can contain any
|
---|
946 | character except '\\0' and '/'. Unusual characters in file names can
|
---|
947 | do unexpected and often undesirable things to your terminal (for
|
---|
948 | example, changing the settings of your function keys on some
|
---|
949 | terminals). Unusual characters are handled differently by various
|
---|
950 | actions, as described below.
|
---|
951 | .IP "\-print0, \-fprint0\"
|
---|
952 | Always print the exact filename, unchanged, even if the output is
|
---|
953 | going to a terminal.
|
---|
954 | .IP "\-ls, \-fls"
|
---|
955 | Unusual characters are always escaped. White space, backslash, and
|
---|
956 | double quote characters are printed using C-style escaping (for
|
---|
957 | example '\\f', '\\"'). Other unusual characters are printed using an
|
---|
958 | octal escape. Other printable characters (for \-ls and \-fls these are
|
---|
959 | the characters between octal 041 and 0176) are printed as-is.
|
---|
960 | .IP "\-printf, \-fprintf"
|
---|
961 | If the output is not going to a terminal, it is printed as-is.
|
---|
962 | Otherwise, the result depends on which directive is in use. The
|
---|
963 | directives %D, %F, %g, %G, %H, %Y, and %y expand to values which are
|
---|
964 | not under control of files' owners, and so are printed as-is. The
|
---|
965 | directives %a, %b, %c, %d, %i, %k, %m, %M, %n, %s, %t, %u and %U have
|
---|
966 | values which are under the control of files' owners but which cannot
|
---|
967 | be used to send arbitrary data to the terminal, and so these are
|
---|
968 | printed as-is. The directives %f, %h, %l, %p and %P are quoted. This
|
---|
969 | quoting is performed in the same way as for GNU
|
---|
970 | .BR ls .
|
---|
971 | This is not the same quoting mechanism as the one used for \-ls and
|
---|
972 | \-fls. If you are able to decide what format to use for the output
|
---|
973 | of
|
---|
974 | .B find
|
---|
975 | then it is normally better to use '\\0' as a terminator
|
---|
976 | than to use newline, as file names can contain white space and newline
|
---|
977 | characters.
|
---|
978 | .IP "\-print, \-fprint"
|
---|
979 | Quoting is handled in the same way as for \-printf and \-fprintf.
|
---|
980 | If you are using
|
---|
981 | .B find
|
---|
982 | in a script or in a situation where the matched files might have
|
---|
983 | arbitrary names, you should consider using \-print0 instead of
|
---|
984 | \-print.
|
---|
985 | .P
|
---|
986 | The \-ok and \-okdir actions print the current filename as-is. This
|
---|
987 | may change in a future release.
|
---|
988 | .SS OPERATORS
|
---|
989 | .P
|
---|
990 | Listed in order of decreasing precedence:
|
---|
991 | .IP "( \fIexpr\fR )"
|
---|
992 | Force precedence.
|
---|
993 | .IP "! \fIexpr\fR"
|
---|
994 | True if \fIexpr\fR is false.
|
---|
995 | .IP "\-not \fIexpr\fR"
|
---|
996 | Same as ! \fIexpr\fR, but not POSIX compliant.
|
---|
997 | .IP "\fIexpr1 expr2\fR"
|
---|
998 | Two expressions in a row are taken to be joined with an
|
---|
999 | implied "and"; \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
|
---|
1000 | .IP "\fIexpr1\fR \-a \fIexpr2\fR"
|
---|
1001 | Same as \fIexpr1 expr2\fR.
|
---|
1002 | .IP "\fIexpr1\fR \-and \fIexpr2\fR"
|
---|
1003 | Same as \fIexpr1 expr2\fR, but not POSIX compliant.
|
---|
1004 | .IP "\fIexpr1\fR \-o \fIexpr2\fR"
|
---|
1005 | Or; \fIexpr2\fR is not evaluated if \fIexpr1\fR is true.
|
---|
1006 | .IP "\fIexpr1\fR \-or \fIexpr2\fR"
|
---|
1007 | Same as \fIexpr1\fR \-o \fIexpr2\fR, but not POSIX compliant.
|
---|
1008 | .IP "\fIexpr1\fR , \fIexpr2\fR"
|
---|
1009 | List; both \fIexpr1\fR and \fIexpr2\fR are always evaluated.
|
---|
1010 | The value of \fIexpr1\fR is discarded; the value of the list is the
|
---|
1011 | value of \fIexpr2\fR.
|
---|
1012 | The comma operator can be useful for searching for several
|
---|
1013 | different types of thing, but traversing the filesystem hierarchy only
|
---|
1014 | once. The
|
---|
1015 | .B \-fprintf
|
---|
1016 | action can be used to list the various matched items into several
|
---|
1017 | different output files.
|
---|
1018 |
|
---|
1019 |
|
---|
1020 | .SH "STANDARDS CONFORMANCE"
|
---|
1021 | The following options are specified in the POSIX standard
|
---|
1022 | (IEEE Std 1003.1, 2003 Edition):
|
---|
1023 | .IP "\-H"
|
---|
1024 | This option is supported.
|
---|
1025 | .IP "\-L"
|
---|
1026 | This option is supported.
|
---|
1027 | .IP "\-name"
|
---|
1028 | This option is supported, but POSIX conformance depends on the
|
---|
1029 | POSIX conformance of the system's
|
---|
1030 | .BR fnmatch (3)
|
---|
1031 | library function. As of findutils-4.2.2, shell metacharacters
|
---|
1032 | ('*'. '?' or '[]' for example) will match a leading '.', because
|
---|
1033 | IEEE PASC interpretation 126 requires this. This is a change from
|
---|
1034 | previous versions of findutils.
|
---|
1035 | .IP "\-type"
|
---|
1036 | Supported. POSIX specifies `b', `c', `d', `l', `p', `f' and `s'.
|
---|
1037 | GNU find also supports `D', representing a Door, where the OS provides these.
|
---|
1038 |
|
---|
1039 | .IP "\-ok"
|
---|
1040 | Supported. Interpretation of the response is not locale-dependent
|
---|
1041 | (see ENVIRONMENT VARIABLES).
|
---|
1042 |
|
---|
1043 | .IP "\-newer"
|
---|
1044 | Supported. If the file specified is a symbolic link, it is always
|
---|
1045 | dereferenced. This is a change from previous behaviour, which used to
|
---|
1046 | take the relevant time from the symbolic link; see the HISTORY section
|
---|
1047 | below.
|
---|
1048 |
|
---|
1049 | .IP "Other predicates"
|
---|
1050 | The predicates
|
---|
1051 | `\-atime',
|
---|
1052 | `\-ctime',
|
---|
1053 | `\-depth',
|
---|
1054 | `\-group',
|
---|
1055 | `\-links',
|
---|
1056 | `\-mtime',
|
---|
1057 | `\-nogroup',
|
---|
1058 | `\-nouser',
|
---|
1059 | `\-perm',
|
---|
1060 | `\-print',
|
---|
1061 | `\-prune',
|
---|
1062 | `\-size',
|
---|
1063 | `\-user' and
|
---|
1064 | `\-xdev',
|
---|
1065 | are all supported.
|
---|
1066 |
|
---|
1067 | .P
|
---|
1068 | The POSIX standard specifies parentheses `(', `)', negation `!' and the
|
---|
1069 | `and' and `or' operators (`\-a', `\-o').
|
---|
1070 | .P
|
---|
1071 | All other options, predicates, expressions and so forth are extensions
|
---|
1072 | beyond the POSIX standard. Many of these extensions are not unique to
|
---|
1073 | GNU find, however.
|
---|
1074 | .P
|
---|
1075 | The POSIX standard requires that
|
---|
1076 | .IP
|
---|
1077 | The
|
---|
1078 | .B find
|
---|
1079 | utility shall detect infinite loops; that is, entering a
|
---|
1080 | previously visited directory that is an ancestor of the last file
|
---|
1081 | encountered. When it detects an infinite loop, find shall write a
|
---|
1082 | diagnostic message to standard error and shall either recover its
|
---|
1083 | position in the hierarchy or terminate.
|
---|
1084 | .P
|
---|
1085 | The link count of directories which contain entries which are hard
|
---|
1086 | links to an ancestor will often be lower than they otherwise should
|
---|
1087 | be. This can mean that GNU find will sometimes optimise away the
|
---|
1088 | visiting of a subdirectory which is actually a link to an ancestor.
|
---|
1089 | Since
|
---|
1090 | .B find
|
---|
1091 | does not actually enter such a subdirectory, it is allowed to avoid
|
---|
1092 | emitting a diagnostic message. Although this behaviour may be
|
---|
1093 | somewhat confusing, it is unlikely that anybody actually depends on
|
---|
1094 | this behaviour. If the leaf optimisation has been turned off with
|
---|
1095 | .BR \-noleaf ,
|
---|
1096 | the directory entry will always be examined and the diagnostic message
|
---|
1097 | will be issued where it is appropriate. Symbolic links cannot be used
|
---|
1098 | to create filesystem cycles as such, but if the \-L option or the
|
---|
1099 | \-follow option is in use, a diagnostic message is issued when
|
---|
1100 | .B find
|
---|
1101 | encounters a loop of symbolic links. As with loops containing hard
|
---|
1102 | links, the leaf optimisation will often mean that
|
---|
1103 | .B find
|
---|
1104 | knows that it doesn't need to call
|
---|
1105 | .I stat()
|
---|
1106 | or
|
---|
1107 | .I chdir()
|
---|
1108 | on the symbolic link, so this diagnostic is frequently not necessary.
|
---|
1109 | .P
|
---|
1110 | The \-d option is supported for compatibility with various BSD systems,
|
---|
1111 | but you should use the POSIX-compliant option \-depth instead.
|
---|
1112 | .P
|
---|
1113 | The POSIXLY_CORRECT environment variable does not affect the behaviour
|
---|
1114 | of the \-regex or \-iregex tests because those tests aren't specified in
|
---|
1115 | the POSIX standard.
|
---|
1116 | .SH "ENVIRONMENT VARIABLES"
|
---|
1117 | .IP LANG
|
---|
1118 | Provides a default value for the internationalization variables that
|
---|
1119 | are unset or null.
|
---|
1120 | .IP LC_ALL
|
---|
1121 | If set to a non-empty string value, override the values of all the
|
---|
1122 | other internationalization variables.
|
---|
1123 | .IP LC_COLLATE
|
---|
1124 | The POSIX standard specifies that this variable affects the pattern
|
---|
1125 | matching to be used for the `\-name' option. GNU find uses the
|
---|
1126 | .BR fnmatch (3)
|
---|
1127 | library function, and so support for `LC_COLLATE' depends on the
|
---|
1128 | system library.
|
---|
1129 | .IP
|
---|
1130 | POSIX also specifies that the `LC_COLLATE' environment
|
---|
1131 | variable affects the interpretation of the user's response to the
|
---|
1132 | query issued by `\-ok', but this is not the case for GNU find.
|
---|
1133 | .IP LC_CTYPE
|
---|
1134 | This variable affects the treatment of character classes used with
|
---|
1135 | the `\-name' test, if the system's
|
---|
1136 | .BR fnmatch (3)
|
---|
1137 | library function supports this. It has no effect on the behaviour
|
---|
1138 | of the `\-ok' expression.
|
---|
1139 | .IP LC_MESSAGES
|
---|
1140 | Determines the locale to be used for internationalised messages.
|
---|
1141 | .IP NLSPATH
|
---|
1142 | Determines the location of the internationalisation message catalogues.
|
---|
1143 | .IP PATH
|
---|
1144 | Affects the directories which are searched to find the executables
|
---|
1145 | invoked by `\-exec', `\-execdir', `\-ok' and `\-okdir'.
|
---|
1146 | .IP POSIXLY_CORRECT
|
---|
1147 | Determines the block size used by `\-ls' and `\-fls'.
|
---|
1148 | If `POSIXLY_CORRECT' is set, blocks are units of 512 bytes. Otherwise
|
---|
1149 | they are units of 1024 bytes.
|
---|
1150 | .IP TZ
|
---|
1151 | Affects the time zone used for some of the time-related format
|
---|
1152 | directives of \-printf and \-fprintf.
|
---|
1153 | .SH "EXAMPLES"
|
---|
1154 | .nf
|
---|
1155 | .B find /tmp \-name core \-type f \-print | xargs /bin/rm \-f
|
---|
1156 |
|
---|
1157 | .fi
|
---|
1158 | Find files named
|
---|
1159 | .B core
|
---|
1160 | in or below the directory
|
---|
1161 | .B /tmp
|
---|
1162 | and delete them. Note that this will work incorrectly if there are
|
---|
1163 | any filenames containing newlines, single or double quotes, or spaces.
|
---|
1164 | .P
|
---|
1165 | .B find /tmp \-name core \-type f \-print0 | xargs \-0 /bin/rm \-f
|
---|
1166 |
|
---|
1167 | .fi
|
---|
1168 | Find files named
|
---|
1169 | .B core
|
---|
1170 | in or below the directory
|
---|
1171 | .B /tmp
|
---|
1172 | and delete them, processing filenames in such a way that file or
|
---|
1173 | directory names containing single or double quotes, spaces or newlines
|
---|
1174 | are correctly handled. The
|
---|
1175 | .B \-name
|
---|
1176 | test comes before the
|
---|
1177 | .B \-type
|
---|
1178 | test in order to avoid having to call
|
---|
1179 | .B stat(2)
|
---|
1180 | on every file.
|
---|
1181 |
|
---|
1182 | .P
|
---|
1183 | .nf
|
---|
1184 | .B find . \-type f \-exec file '{}' \e\;
|
---|
1185 |
|
---|
1186 | .fi
|
---|
1187 | Runs `file' on every file in or below the current directory. Notice
|
---|
1188 | that the braces are enclosed in single quote marks to protect them
|
---|
1189 | from interpretation as shell script punctuation. The semicolon is
|
---|
1190 | similarly protected by the use of a backslash, though ';' could have
|
---|
1191 | been used in that case also.
|
---|
1192 |
|
---|
1193 | .P
|
---|
1194 | .nf
|
---|
1195 | .B find / \t\e( \-perm \-4000 \-fprintf /root/suid.txt '%#m %u %p\en' \e) , \e
|
---|
1196 | .B \t\t\e( \-size +100M \-fprintf /root/big.txt '%\-10s %p\en' \e)
|
---|
1197 |
|
---|
1198 | .fi
|
---|
1199 | Traverse the filesystem just once, listing setuid files and
|
---|
1200 | directories into
|
---|
1201 | .B /root/suid.txt
|
---|
1202 | and large files into
|
---|
1203 | .BR /root/big.txt .
|
---|
1204 |
|
---|
1205 | .P
|
---|
1206 | .nf
|
---|
1207 | .B find $HOME \-mtime 0
|
---|
1208 |
|
---|
1209 | .fi
|
---|
1210 | Search for files in your home directory which have been modified in
|
---|
1211 | the last twenty-four hours. This command works this way because the
|
---|
1212 | time since each file was last modified is divided by 24 hours and any
|
---|
1213 | remainder is discarded. That means that to match
|
---|
1214 | .B \-mtime
|
---|
1215 | .BR 0 ,
|
---|
1216 | a file will have to have a modification in the past which is less than
|
---|
1217 | 24 hours ago.
|
---|
1218 |
|
---|
1219 | .P
|
---|
1220 | .nf
|
---|
1221 | .B find /sbin /usr/sbin -executable \e! -readable \-print
|
---|
1222 |
|
---|
1223 | .fi
|
---|
1224 | Search for files which are executable but not readable.
|
---|
1225 |
|
---|
1226 | .P
|
---|
1227 | .nf
|
---|
1228 | .B find . \-perm 664
|
---|
1229 |
|
---|
1230 | .fi
|
---|
1231 | Search for files which have read and write permission for their owner,
|
---|
1232 | and group, but which other users can read but not write to. Files
|
---|
1233 | which meet these criteria but have other permissions bits set (for
|
---|
1234 | example if someone can execute the file) will not be matched.
|
---|
1235 |
|
---|
1236 | .P
|
---|
1237 | .nf
|
---|
1238 | .B find . \-perm -664
|
---|
1239 |
|
---|
1240 | .fi
|
---|
1241 | Search for files which have read and write permission for their owner
|
---|
1242 | and group, and which other users can read, without regard to the
|
---|
1243 | presence of any extra permission bits (for example the executable
|
---|
1244 | bit). This will match a file which has mode 0777, for example.
|
---|
1245 |
|
---|
1246 | .P
|
---|
1247 | .nf
|
---|
1248 | .B find . \-perm /222
|
---|
1249 |
|
---|
1250 | .fi
|
---|
1251 | Search for files which are writable by somebody (their owner, or
|
---|
1252 | their group, or anybody else).
|
---|
1253 |
|
---|
1254 | .P
|
---|
1255 | .nf
|
---|
1256 | .B find . \-perm /220
|
---|
1257 | .B find . \-perm /u+w,g+w
|
---|
1258 | .B find . \-perm /u=w,g=w
|
---|
1259 |
|
---|
1260 | .fi
|
---|
1261 | All three of these commands do the same thing, but the first one uses
|
---|
1262 | the octal representation of the file mode, and the other two use the
|
---|
1263 | symbolic form. These commands all search for files which are
|
---|
1264 | writable by either their owner or their group. The files don't have
|
---|
1265 | to be writable by both the owner and group to be matched; either will
|
---|
1266 | do.
|
---|
1267 |
|
---|
1268 | .P
|
---|
1269 | .nf
|
---|
1270 | .B find . \-perm -220
|
---|
1271 | .B find . \-perm \-g+w,u+w
|
---|
1272 |
|
---|
1273 | .fi
|
---|
1274 | Both these commands do the same thing; search for files which are
|
---|
1275 | writable by both their owner and their group.
|
---|
1276 |
|
---|
1277 | .P
|
---|
1278 | .nf
|
---|
1279 | .B find . \-perm \-444 \-perm /222 ! \-perm /111
|
---|
1280 | .B find . \-perm \-a+r \-perm /a+w ! \-perm /a+x
|
---|
1281 |
|
---|
1282 | .fi
|
---|
1283 | These two commands both search for files that are readable for
|
---|
1284 | everybody (\-perm \-444 or \-perm \-a+r), have at least on write bit
|
---|
1285 | set (\-perm /222 or \-perm /a+w) but are not executable for anybody (!
|
---|
1286 | \-perm /111 and ! \-perm /a+x respectively)
|
---|
1287 |
|
---|
1288 | .SH EXIT STATUS
|
---|
1289 | .PP
|
---|
1290 | .B find
|
---|
1291 | exits with status 0 if all files are processed successfully, greater
|
---|
1292 | than 0 if errors occur. This is deliberately a very broad
|
---|
1293 | description, but if the return value is non-zero, you should not rely
|
---|
1294 | on the correctness of the results of
|
---|
1295 | .BR find .
|
---|
1296 |
|
---|
1297 | .SH "SEE ALSO"
|
---|
1298 | \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1), \fBxargs\fP(1),
|
---|
1299 | \fBchmod\fP(1), \fBfnmatch\fP(3), \fBregex\fP(7), \fBstat\fP(2),
|
---|
1300 | \fBlstat\fP(2), \fBls\fP(1), \fBprintf\fP(3), \fBstrftime\fP(3),
|
---|
1301 | \fBctime\fP(3), \fBFinding Files\fP (on-line in Info, or printed).
|
---|
1302 | .SH "HISTORY"
|
---|
1303 | As of findutils-4.2.2, shell metacharacters ('*'. '?' or '[]' for
|
---|
1304 | example) used in filename patterns will match a leading '.', because
|
---|
1305 | IEEE POSIX interpretation 126 requires this.
|
---|
1306 | .SH "NON-BUGS"
|
---|
1307 | .nf
|
---|
1308 | .B $ find . \-name *.c \-print
|
---|
1309 | find: paths must precede expression
|
---|
1310 | Usage: find [-H] [-L] [-P] [path...] [expression]
|
---|
1311 | .fi
|
---|
1312 | .P
|
---|
1313 | This happens because
|
---|
1314 | .I *.c
|
---|
1315 | has been expanded by the shell
|
---|
1316 | resulting in
|
---|
1317 | .B find
|
---|
1318 | actually receiving a command line like this:
|
---|
1319 | .nf
|
---|
1320 |
|
---|
1321 | .B find . \-name bigram.c code.c frcode.c locate.c \-print
|
---|
1322 |
|
---|
1323 | .fi
|
---|
1324 | That command is of course not going to work. Instead of doing things
|
---|
1325 | this way, you should enclose the pattern in quotes or escape the wildcard:
|
---|
1326 | .nf
|
---|
1327 | .B $ find . \-name \e*.c \-print
|
---|
1328 | .fi
|
---|
1329 |
|
---|
1330 | .SH "BUGS"
|
---|
1331 | .P
|
---|
1332 | The test
|
---|
1333 | .B \-perm /000
|
---|
1334 | currently matches no files, but for greater consistency with
|
---|
1335 | .B \-perm
|
---|
1336 | .BR \-000 ,
|
---|
1337 | this will be changed to match all files; this change will probably be
|
---|
1338 | made in early 2006. Meanwhile, a warning message is given if you do this.
|
---|
1339 | .P
|
---|
1340 | There are security problems inherent in the behaviour that the POSIX
|
---|
1341 | standard specifies for
|
---|
1342 | .BR find ,
|
---|
1343 | which therefore cannot be fixed. For example, the \-exec action is
|
---|
1344 | inherently insecure, and \-execdir should be used instead.
|
---|
1345 | Please see \fBFinding Files\fP for more information.
|
---|
1346 | .P
|
---|
1347 | The best way to report a bug is to use the form at
|
---|
1348 | http://savannah.gnu.org/bugs/?group=findutils.
|
---|
1349 | The reason for this is that you will then be able to track progress in
|
---|
1350 | fixing the problem. Other comments about \fBfind\fP(1) and about
|
---|
1351 | the findutils package in general can be sent to the
|
---|
1352 | .I bug\-findutils
|
---|
1353 | mailing list. To join the list, send email to
|
---|
1354 | .IR bug\-findutils\-request@gnu.org .
|
---|