1 | This is ../../findutils/doc/find.info, produced by makeinfo version 4.8
|
---|
2 | from ../../findutils/doc/find.texi.
|
---|
3 |
|
---|
4 | INFO-DIR-SECTION Basics
|
---|
5 | START-INFO-DIR-ENTRY
|
---|
6 | * Finding files: (find). Operating on files matching certain criteria.
|
---|
7 | END-INFO-DIR-ENTRY
|
---|
8 |
|
---|
9 | INFO-DIR-SECTION Individual utilities
|
---|
10 | START-INFO-DIR-ENTRY
|
---|
11 | * find: (find)Invoking find. Finding and acting on files.
|
---|
12 | * locate: (find)Invoking locate. Finding files in a database.
|
---|
13 | * updatedb: (find)Invoking updatedb. Building the locate database.
|
---|
14 | * xargs: (find)Invoking xargs. Operating on many files.
|
---|
15 | END-INFO-DIR-ENTRY
|
---|
16 |
|
---|
17 | This file documents the GNU utilities for finding files that match
|
---|
18 | certain criteria and performing various operations on them.
|
---|
19 |
|
---|
20 | Copyright (C) 1994, 1996, 1998, 2000, 2001, 2003, 2004, 2005 Free
|
---|
21 | Software Foundation, Inc.
|
---|
22 |
|
---|
23 | Permission is granted to make and distribute verbatim copies of this
|
---|
24 | manual provided the copyright notice and this permission notice are
|
---|
25 | preserved on all copies.
|
---|
26 |
|
---|
27 | Permission is granted to copy and distribute modified versions of
|
---|
28 | this manual under the conditions for verbatim copying, provided that the
|
---|
29 | entire resulting derived work is distributed under the terms of a
|
---|
30 | permission notice identical to this one.
|
---|
31 |
|
---|
32 | Permission is granted to copy and distribute translations of this
|
---|
33 | manual into another language, under the above conditions for modified
|
---|
34 | versions, except that this permission notice may be stated in a
|
---|
35 | translation approved by the Foundation.
|
---|
36 |
|
---|
37 |
|
---|
38 | File: find.info, Node: Top, Next: Introduction, Up: (dir)
|
---|
39 |
|
---|
40 | This file documents the GNU utilities for finding files that match
|
---|
41 | certain criteria and performing various actions on them.
|
---|
42 |
|
---|
43 | This is edition 4.3.2, for `find' version 4.3.2.
|
---|
44 |
|
---|
45 | * Menu:
|
---|
46 |
|
---|
47 | * Introduction:: Summary of the tasks this manual describes.
|
---|
48 | * Finding Files:: Finding files that match certain criteria.
|
---|
49 | * Actions:: Doing things to files you have found.
|
---|
50 | * Databases:: Maintaining file name databases.
|
---|
51 | * File Permissions:: How to control access to files.
|
---|
52 | * Reference:: Summary of how to invoke the programs.
|
---|
53 | * Common Tasks:: Solutions to common real-world problems.
|
---|
54 | * Worked Examples:: Examples demonstrating more complex points.
|
---|
55 | * Security Considerations:: Security issues relating to findutils.
|
---|
56 | * Error Messages:: Explanations of some messages you might see.
|
---|
57 | * Primary Index:: The components of `find' expressions.
|
---|
58 |
|
---|
59 |
|
---|
60 | File: find.info, Node: Introduction, Next: Finding Files, Prev: Top, Up: Top
|
---|
61 |
|
---|
62 | 1 Introduction
|
---|
63 | **************
|
---|
64 |
|
---|
65 | This manual shows how to find files that meet criteria you specify, and
|
---|
66 | how to perform various actions on the files that you find. The
|
---|
67 | principal programs that you use to perform these tasks are `find',
|
---|
68 | `locate', and `xargs'. Some of the examples in this manual use
|
---|
69 | capabilities specific to the GNU versions of those programs.
|
---|
70 |
|
---|
71 | GNU `find' was originally written by Eric Decker, with enhancements
|
---|
72 | by David MacKenzie, Jay Plett, and Tim Wood. GNU `xargs' was
|
---|
73 | originally written by Mike Rendell, with enhancements by David
|
---|
74 | MacKenzie. GNU `locate' and its associated utilities were originally
|
---|
75 | written by James Woods, with enhancements by David MacKenzie. The idea
|
---|
76 | for `find -print0' and `xargs -0' came from Dan Bernstein. The current
|
---|
77 | maintainer of GNU findutils (and this manual) is James Youngman. Many
|
---|
78 | other people have contributed bug fixes, small improvements, and
|
---|
79 | helpful suggestions. Thanks!
|
---|
80 |
|
---|
81 | To report a bug in GNU findutils, please use the form on the Savannah
|
---|
82 | web site at `http://savannah.gnu.org/bugs/?group=findutils'. Reporting
|
---|
83 | bugs this way means that you will then be able to track progress in
|
---|
84 | fixing the problem.
|
---|
85 |
|
---|
86 | If you don't have web access, you can also just send mail to the
|
---|
87 | mailing list. The mailing list <bug-findutils@gnu.org> carries
|
---|
88 | discussion of bugs in findutils, questions and answers about the
|
---|
89 | software and discussion of the development of the programs. To join
|
---|
90 | the list, send email to <bug-findutils-request@gnu.org>.
|
---|
91 |
|
---|
92 | Please read any relevant sections of this manual before asking for
|
---|
93 | help on the mailing list. You may also find it helpful to read the
|
---|
94 | NON-BUGS section of the `find' manual page.
|
---|
95 |
|
---|
96 | If you ask for help on the mailing list, people will be able to help
|
---|
97 | you much more effectively if you include the following things:
|
---|
98 |
|
---|
99 | * The version of the software you are running. You can find this
|
---|
100 | out by running `locate --version'.
|
---|
101 |
|
---|
102 | * What you were trying to do
|
---|
103 |
|
---|
104 | * The _exact_ command line you used
|
---|
105 |
|
---|
106 | * The _exact_ output you got (if this is very long, try to find a
|
---|
107 | smaller example which exhibits the same problem)
|
---|
108 |
|
---|
109 | * The output you expected to get
|
---|
110 |
|
---|
111 | * Menu:
|
---|
112 |
|
---|
113 | * Scope::
|
---|
114 | * Overview::
|
---|
115 | * find Expressions::
|
---|
116 |
|
---|
117 |
|
---|
118 | File: find.info, Node: Scope, Next: Overview, Up: Introduction
|
---|
119 |
|
---|
120 | 1.1 Scope
|
---|
121 | =========
|
---|
122 |
|
---|
123 | For brevity, the word "file" in this manual means a regular file, a
|
---|
124 | directory, a symbolic link, or any other kind of node that has a
|
---|
125 | directory entry. A directory entry is also called a "file name". A
|
---|
126 | file name may contain some, all, or none of the directories in a path
|
---|
127 | that leads to the file. These are all examples of what this manual
|
---|
128 | calls "file names":
|
---|
129 |
|
---|
130 | parser.c
|
---|
131 | README
|
---|
132 | ./budget/may-94.sc
|
---|
133 | fred/.cshrc
|
---|
134 | /usr/local/include/termcap.h
|
---|
135 |
|
---|
136 | A "directory tree" is a directory and the files it contains, all of
|
---|
137 | its subdirectories and the files they contain, etc. It can also be a
|
---|
138 | single non-directory file.
|
---|
139 |
|
---|
140 | These programs enable you to find the files in one or more directory
|
---|
141 | trees that:
|
---|
142 |
|
---|
143 | * have names that contain certain text or match a certain pattern;
|
---|
144 |
|
---|
145 | * are links to certain files;
|
---|
146 |
|
---|
147 | * were last used during a certain period of time;
|
---|
148 |
|
---|
149 | * are within a certain size range;
|
---|
150 |
|
---|
151 | * are of a certain type (regular file, directory, symbolic link,
|
---|
152 | etc.);
|
---|
153 |
|
---|
154 | * are owned by a certain user or group;
|
---|
155 |
|
---|
156 | * have certain access permissions or special mode bits;
|
---|
157 |
|
---|
158 | * contain text that matches a certain pattern;
|
---|
159 |
|
---|
160 | * are within a certain depth in the directory tree;
|
---|
161 |
|
---|
162 | * or some combination of the above.
|
---|
163 |
|
---|
164 | Once you have found the files you're looking for (or files that are
|
---|
165 | potentially the ones you're looking for), you can do more to them than
|
---|
166 | simply list their names. You can get any combination of the files'
|
---|
167 | attributes, or process the files in many ways, either individually or
|
---|
168 | in groups of various sizes. Actions that you might want to perform on
|
---|
169 | the files you have found include, but are not limited to:
|
---|
170 |
|
---|
171 | * view or edit
|
---|
172 |
|
---|
173 | * store in an archive
|
---|
174 |
|
---|
175 | * remove or rename
|
---|
176 |
|
---|
177 | * change access permissions
|
---|
178 |
|
---|
179 | * classify into groups
|
---|
180 |
|
---|
181 | This manual describes how to perform each of those tasks, and more.
|
---|
182 |
|
---|
183 |
|
---|
184 | File: find.info, Node: Overview, Next: find Expressions, Prev: Scope, Up: Introduction
|
---|
185 |
|
---|
186 | 1.2 Overview
|
---|
187 | ============
|
---|
188 |
|
---|
189 | The principal programs used for making lists of files that match given
|
---|
190 | criteria and running commands on them are `find', `locate', and
|
---|
191 | `xargs'. An additional command, `updatedb', is used by system
|
---|
192 | administrators to create databases for `locate' to use.
|
---|
193 |
|
---|
194 | `find' searches for files in a directory hierarchy and prints
|
---|
195 | information about the files it found. It is run like this:
|
---|
196 |
|
---|
197 | find [FILE...] [EXPRESSION]
|
---|
198 |
|
---|
199 | Here is a typical use of `find'. This example prints the names of all
|
---|
200 | files in the directory tree rooted in `/usr/src' whose name ends with
|
---|
201 | `.c' and that are larger than 100 Kilobytes.
|
---|
202 | find /usr/src -name '*.c' -size +100k -print
|
---|
203 |
|
---|
204 | Notice that the wildcard must be enclosed in quotes in order to
|
---|
205 | protect it from expansion by the shell.
|
---|
206 |
|
---|
207 | `locate' searches special file name databases for file names that
|
---|
208 | match patterns. The system administrator runs the `updatedb' program
|
---|
209 | to create the databases. `locate' is run like this:
|
---|
210 |
|
---|
211 | locate [OPTION...] PATTERN...
|
---|
212 |
|
---|
213 | This example prints the names of all files in the default file name
|
---|
214 | database whose name ends with `Makefile' or `makefile'. Which file
|
---|
215 | names are stored in the database depends on how the system
|
---|
216 | administrator ran `updatedb'.
|
---|
217 | locate '*[Mm]akefile'
|
---|
218 |
|
---|
219 | The name `xargs', pronounced EX-args, means "combine arguments."
|
---|
220 | `xargs' builds and executes command lines by gathering together
|
---|
221 | arguments it reads on the standard input. Most often, these arguments
|
---|
222 | are lists of file names generated by `find'. `xargs' is run like this:
|
---|
223 |
|
---|
224 | xargs [OPTION...] [COMMAND [INITIAL-ARGUMENTS]]
|
---|
225 |
|
---|
226 | The following command searches the files listed in the file `file-list'
|
---|
227 | and prints all of the lines in them that contain the word `typedef'.
|
---|
228 | xargs grep typedef < file-list
|
---|
229 |
|
---|
230 |
|
---|
231 | File: find.info, Node: find Expressions, Prev: Overview, Up: Introduction
|
---|
232 |
|
---|
233 | 1.3 `find' Expressions
|
---|
234 | ======================
|
---|
235 |
|
---|
236 | The expression that `find' uses to select files consists of one or more
|
---|
237 | "primaries", each of which is a separate command line argument to
|
---|
238 | `find'. `find' evaluates the expression each time it processes a file.
|
---|
239 | An expression can contain any of the following types of primaries:
|
---|
240 |
|
---|
241 | "options"
|
---|
242 | affect overall operation rather than the processing of a specific
|
---|
243 | file;
|
---|
244 |
|
---|
245 | "tests"
|
---|
246 | return a true or false value, depending on the file's attributes;
|
---|
247 |
|
---|
248 | "actions"
|
---|
249 | have side effects and return a true or false value; and
|
---|
250 |
|
---|
251 | "operators"
|
---|
252 | connect the other arguments and affect when and whether they are
|
---|
253 | evaluated.
|
---|
254 |
|
---|
255 | You can omit the operator between two primaries; it defaults to
|
---|
256 | `-and'. *Note Combining Primaries With Operators::, for ways to
|
---|
257 | connect primaries into more complex expressions. If the expression
|
---|
258 | contains no actions other than `-prune', `-print' is performed on all
|
---|
259 | files for which the entire expression is true (*note Print File Name::).
|
---|
260 |
|
---|
261 | Options take effect immediately, rather than being evaluated for each
|
---|
262 | file when their place in the expression is reached. Therefore, for
|
---|
263 | clarity, it is best to place them at the beginning of the expression.
|
---|
264 | There are two exceptions to this; `-daystart' and `-follow' have
|
---|
265 | different effects depending on where in the command line they appear.
|
---|
266 | This can be confusing, so it's best to keep them at the beginning, too.
|
---|
267 |
|
---|
268 | Many of the primaries take arguments, which immediately follow them
|
---|
269 | in the next command line argument to `find'. Some arguments are file
|
---|
270 | names, patterns, or other strings; others are numbers. Numeric
|
---|
271 | arguments can be specified as
|
---|
272 |
|
---|
273 | `+N'
|
---|
274 | for greater than N,
|
---|
275 |
|
---|
276 | `-N'
|
---|
277 | for less than N,
|
---|
278 |
|
---|
279 | `N'
|
---|
280 | for exactly N.
|
---|
281 |
|
---|
282 |
|
---|
283 | File: find.info, Node: Finding Files, Next: Actions, Prev: Introduction, Up: Top
|
---|
284 |
|
---|
285 | 2 Finding Files
|
---|
286 | ***************
|
---|
287 |
|
---|
288 | By default, `find' prints to the standard output the names of the files
|
---|
289 | that match the given criteria. *Note Actions::, for how to get more
|
---|
290 | information about the matching files.
|
---|
291 |
|
---|
292 | * Menu:
|
---|
293 |
|
---|
294 | * Name::
|
---|
295 | * Links::
|
---|
296 | * Time::
|
---|
297 | * Size::
|
---|
298 | * Type::
|
---|
299 | * Owner::
|
---|
300 | * Mode Bits::
|
---|
301 | * Contents::
|
---|
302 | * Directories::
|
---|
303 | * Filesystems::
|
---|
304 | * Combining Primaries With Operators::
|
---|
305 |
|
---|
306 |
|
---|
307 | File: find.info, Node: Name, Next: Links, Up: Finding Files
|
---|
308 |
|
---|
309 | 2.1 Name
|
---|
310 | ========
|
---|
311 |
|
---|
312 | Here are ways to search for files whose name matches a certain pattern.
|
---|
313 | *Note Shell Pattern Matching::, for a description of the PATTERN
|
---|
314 | arguments to these tests.
|
---|
315 |
|
---|
316 | Each of these tests has a case-sensitive version and a
|
---|
317 | case-insensitive version, whose name begins with `i'. In a
|
---|
318 | case-insensitive comparison, the patterns `fo*' and `F??' match the
|
---|
319 | file names `Foo', `FOO', `foo', `fOo', etc.
|
---|
320 |
|
---|
321 | * Menu:
|
---|
322 |
|
---|
323 | * Base Name Patterns::
|
---|
324 | * Full Name Patterns::
|
---|
325 | * Fast Full Name Search::
|
---|
326 | * Shell Pattern Matching:: Wildcards used by these programs.
|
---|
327 |
|
---|
328 |
|
---|
329 | File: find.info, Node: Base Name Patterns, Next: Full Name Patterns, Up: Name
|
---|
330 |
|
---|
331 | 2.1.1 Base Name Patterns
|
---|
332 | ------------------------
|
---|
333 |
|
---|
334 | -- Test: -name pattern
|
---|
335 | -- Test: -iname pattern
|
---|
336 | True if the base of the file name (the path with the leading
|
---|
337 | directories removed) matches shell pattern PATTERN. For `-iname',
|
---|
338 | the match is case-insensitive.(1) To ignore a whole directory
|
---|
339 | tree, use `-prune' (*note Directories::). As an example, to find
|
---|
340 | Texinfo source files in `/usr/local/doc':
|
---|
341 |
|
---|
342 | find /usr/local/doc -name '*.texi'
|
---|
343 |
|
---|
344 | Notice that the wildcard must be enclosed in quotes in order to
|
---|
345 | protect it from expansion by the shell.
|
---|
346 |
|
---|
347 | As of findutils version 4.2.2, patterns for `-name' and `-iname'
|
---|
348 | will match a file name with a leading `.'. For example the
|
---|
349 | command `find /tmp -name \*bar' will match the file
|
---|
350 | `/tmp/.foobar'. Braces within the pattern (`{}') are not
|
---|
351 | considered to be special (that is, `find . -name 'foo{1,2}''
|
---|
352 | matches a file named `foo{1,2}', not the files `foo1' and `foo2'.
|
---|
353 |
|
---|
354 | ---------- Footnotes ----------
|
---|
355 |
|
---|
356 | (1) Because we need to perform case-insensitive matching, the GNU
|
---|
357 | fnmatch implementation is always used; if the C library includes the GNU
|
---|
358 | implementation, we use that and otherwise we use the one from gnulib
|
---|
359 |
|
---|
360 |
|
---|
361 | File: find.info, Node: Full Name Patterns, Next: Fast Full Name Search, Prev: Base Name Patterns, Up: Name
|
---|
362 |
|
---|
363 | 2.1.2 Full Name Patterns
|
---|
364 | ------------------------
|
---|
365 |
|
---|
366 | -- Test: -wholename pattern
|
---|
367 | -- Test: -iwholename pattern
|
---|
368 | True if the entire file name, starting with the command line
|
---|
369 | argument under which the file was found, matches shell pattern
|
---|
370 | PATTERN. For `-iwholename', the match is case-insensitive. To
|
---|
371 | ignore a whole directory tree, use `-prune' rather than checking
|
---|
372 | every file in the tree (*note Directories::). The "entire file
|
---|
373 | name" as used by `find' starts with the starting-point specified
|
---|
374 | on the command line, and is not converted to an absolute pathname,
|
---|
375 | so for example `cd /; find tmp -wholename /tmp' will never match
|
---|
376 | anything.
|
---|
377 |
|
---|
378 | -- Test: -path pattern
|
---|
379 | -- Test: -ipath pattern
|
---|
380 | These tests are deprecated, but work as for `-wholename' and
|
---|
381 | `-iwholename', respectively. The `-ipath' test is a GNU
|
---|
382 | extension, but `-path' is also provided by HP-UX `find'.
|
---|
383 |
|
---|
384 | -- Test: -regex expr
|
---|
385 | -- Test: -iregex expr
|
---|
386 | True if the entire file name matches regular expression EXPR.
|
---|
387 | This is a match on the whole path, not a search. For example, to
|
---|
388 | match a file named `./fubar3', you can use the regular expression
|
---|
389 | `.*bar.' or `.*b.*3', but not `f.*r3'. *Note Syntax of Regular
|
---|
390 | Expressions: (emacs)Regexps, for a description of the syntax of
|
---|
391 | regular expressions. For `-iregex', the match is
|
---|
392 | case-insensitive. There are several varieties of regular
|
---|
393 | expressions; by default this test uses POSIX basic regular
|
---|
394 | expressions, but this can be changed with the option `-regextype'.
|
---|
395 |
|
---|
396 | -- Option: -regextype name
|
---|
397 | This option controls the variety of regular expression syntax
|
---|
398 | understood by the `-regex' and `-iregex' tests. This option is
|
---|
399 | positional; that is, it only affects regular expressions which
|
---|
400 | occur later in the command line. If this option is not given, GNU
|
---|
401 | Emacs regular expressions are assumed. Currently-implemented types
|
---|
402 | are
|
---|
403 |
|
---|
404 | `emacs'
|
---|
405 | Regular expressions compatible with GNU Emacs; this is also
|
---|
406 | the default behaviour if this option is not used.
|
---|
407 |
|
---|
408 | `posix-awk'
|
---|
409 | Regular expressions compatible with the POSIX awk command
|
---|
410 | (not GNU awk)
|
---|
411 |
|
---|
412 | `posix-basic'
|
---|
413 | POSIX Basic Regular Expressions.
|
---|
414 |
|
---|
415 | `posix-egrep'
|
---|
416 | Regular expressions compatible with the POSIX egrep command
|
---|
417 |
|
---|
418 | `posix-extended'
|
---|
419 | POSIX Extended Regular Expressions
|
---|
420 |
|
---|
421 | *Note Regular Expressions:: for more information on the regular
|
---|
422 | expression dialects understood by GNU findutils.
|
---|
423 |
|
---|
424 |
|
---|
425 |
|
---|
426 | File: find.info, Node: Fast Full Name Search, Next: Shell Pattern Matching, Prev: Full Name Patterns, Up: Name
|
---|
427 |
|
---|
428 | 2.1.3 Fast Full Name Search
|
---|
429 | ---------------------------
|
---|
430 |
|
---|
431 | To search for files by name without having to actually scan the
|
---|
432 | directories on the disk (which can be slow), you can use the `locate'
|
---|
433 | program. For each shell pattern you give it, `locate' searches one or
|
---|
434 | more databases of file names and displays the file names that contain
|
---|
435 | the pattern. *Note Shell Pattern Matching::, for details about shell
|
---|
436 | patterns.
|
---|
437 |
|
---|
438 | If a pattern is a plain string--it contains no
|
---|
439 | metacharacters--`locate' displays all file names in the database that
|
---|
440 | contain that string. If a pattern contains metacharacters, `locate'
|
---|
441 | only displays file names that match the pattern exactly. As a result,
|
---|
442 | patterns that contain metacharacters should usually begin with a `*',
|
---|
443 | and will most often end with one as well. The exceptions are patterns
|
---|
444 | that are intended to explicitly match the beginning or end of a file
|
---|
445 | name.
|
---|
446 |
|
---|
447 | If you only want `locate' to match against the last component of the
|
---|
448 | file names (the "base name" of the files) you can use the `--basename'
|
---|
449 | option. The opposite behaviour is the default, but can be selected
|
---|
450 | explicitly by using the option `--wholename'.
|
---|
451 |
|
---|
452 | The command
|
---|
453 | locate PATTERN
|
---|
454 |
|
---|
455 | is almost equivalent to
|
---|
456 | find DIRECTORIES -name PATTERN
|
---|
457 |
|
---|
458 | where DIRECTORIES are the directories for which the file name
|
---|
459 | databases contain information. The differences are that the `locate'
|
---|
460 | information might be out of date, and that `locate' handles wildcards
|
---|
461 | in the pattern slightly differently than `find' (*note Shell Pattern
|
---|
462 | Matching::).
|
---|
463 |
|
---|
464 | The file name databases contain lists of files that were on the
|
---|
465 | system when the databases were last updated. The system administrator
|
---|
466 | can choose the file name of the default database, the frequency with
|
---|
467 | which the databases are updated, and the directories for which they
|
---|
468 | contain entries.
|
---|
469 |
|
---|
470 | Here is how to select which file name databases `locate' searches.
|
---|
471 | The default is system-dependent.
|
---|
472 |
|
---|
473 | `--database=PATH'
|
---|
474 | `-d PATH'
|
---|
475 | Instead of searching the default file name database, search the
|
---|
476 | file name databases in PATH, which is a colon-separated list of
|
---|
477 | database file names. You can also use the environment variable
|
---|
478 | `LOCATE_PATH' to set the list of database files to search. The
|
---|
479 | option overrides the environment variable if both are used.
|
---|
480 |
|
---|
481 |
|
---|
482 | File: find.info, Node: Shell Pattern Matching, Prev: Fast Full Name Search, Up: Name
|
---|
483 |
|
---|
484 | 2.1.4 Shell Pattern Matching
|
---|
485 | ----------------------------
|
---|
486 |
|
---|
487 | `find' and `locate' can compare file names, or parts of file names, to
|
---|
488 | shell patterns. A "shell pattern" is a string that may contain the
|
---|
489 | following special characters, which are known as "wildcards" or
|
---|
490 | "metacharacters".
|
---|
491 |
|
---|
492 | You must quote patterns that contain metacharacters to prevent the
|
---|
493 | shell from expanding them itself. Double and single quotes both work;
|
---|
494 | so does escaping with a backslash.
|
---|
495 |
|
---|
496 | `*'
|
---|
497 | Matches any zero or more characters.
|
---|
498 |
|
---|
499 | `?'
|
---|
500 | Matches any one character.
|
---|
501 |
|
---|
502 | `[STRING]'
|
---|
503 | Matches exactly one character that is a member of the string
|
---|
504 | STRING. This is called a "character class". As a shorthand,
|
---|
505 | STRING may contain ranges, which consist of two characters with a
|
---|
506 | dash between them. For example, the class `[a-z0-9_]' matches a
|
---|
507 | lowercase letter, a number, or an underscore. You can negate a
|
---|
508 | class by placing a `!' or `^' immediately after the opening
|
---|
509 | bracket. Thus, `[^A-Z@]' matches any character except an
|
---|
510 | uppercase letter or an at sign.
|
---|
511 |
|
---|
512 | `\'
|
---|
513 | Removes the special meaning of the character that follows it. This
|
---|
514 | works even in character classes.
|
---|
515 |
|
---|
516 | In the `find' tests that do shell pattern matching (`-name',
|
---|
517 | `-wholename', etc.), wildcards in the pattern will match a `.' at the
|
---|
518 | beginning of a file name. This is also the case for `locate'. Thus,
|
---|
519 | `find -name '*macs'' will match a file named `.emacs', as will `locate
|
---|
520 | '*macs''.
|
---|
521 |
|
---|
522 | Slash characters have no special significance in the shell pattern
|
---|
523 | matching that `find' and `locate' do, unlike in the shell, in which
|
---|
524 | wildcards do not match them. Therefore, a pattern `foo*bar' can match
|
---|
525 | a file name `foo3/bar', and a pattern `./sr*sc' can match a file name
|
---|
526 | `./src/misc'.
|
---|
527 |
|
---|
528 | If you want to locate some files with the `locate' command but don't
|
---|
529 | need to see the full list you can use the `--limit' option to see just
|
---|
530 | a small number of results, or the `--count' option to display only the
|
---|
531 | total number of matches.
|
---|
532 |
|
---|
533 |
|
---|
534 | File: find.info, Node: Links, Next: Time, Prev: Name, Up: Finding Files
|
---|
535 |
|
---|
536 | 2.2 Links
|
---|
537 | =========
|
---|
538 |
|
---|
539 | There are two ways that files can be linked together. "Symbolic links"
|
---|
540 | are a special type of file whose contents are a portion of the name of
|
---|
541 | another file. "Hard links" are multiple directory entries for one
|
---|
542 | file; the file names all have the same index node ("inode") number on
|
---|
543 | the disk.
|
---|
544 |
|
---|
545 | * Menu:
|
---|
546 |
|
---|
547 | * Symbolic Links::
|
---|
548 | * Hard Links::
|
---|
549 |
|
---|
550 |
|
---|
551 | File: find.info, Node: Symbolic Links, Next: Hard Links, Up: Links
|
---|
552 |
|
---|
553 | 2.2.1 Symbolic Links
|
---|
554 | --------------------
|
---|
555 |
|
---|
556 | Symbolic links are names that reference other files. GNU `find' will
|
---|
557 | handle symbolic links in one of two ways; firstly, it can dereference
|
---|
558 | the links for you - this means that if it comes across a symbolic link,
|
---|
559 | it examines the file that the link points to, in order to see if it
|
---|
560 | matches the criteria you have specified. Secondly, it can check the
|
---|
561 | link itself in case you might be looking for the actual link. If the
|
---|
562 | file that the symbolic link points to is also within the directory
|
---|
563 | hierarchy you are searching with the `find' command, you may not see a
|
---|
564 | great deal of difference between these two alternatives.
|
---|
565 |
|
---|
566 | By default, `find' examines symbolic links themselves when it finds
|
---|
567 | them (and, if it later comes across the linked-to file, it will examine
|
---|
568 | that, too). If you would prefer `find' to dereference the links and
|
---|
569 | examine the file that each link points to, specify the `-L' option to
|
---|
570 | `find'. You can explicitly specify the default behaviour by using the
|
---|
571 | `-P' option. The `-H' option is a half-way-between option which
|
---|
572 | ensures that any symbolic links listed on the command line are
|
---|
573 | dereferenced, but other symbolic links are not.
|
---|
574 |
|
---|
575 | Symbolic links are different to "hard links" in the sense that you
|
---|
576 | need permission to search the directories in the the linked-to file
|
---|
577 | name to dereference the link. This can mean that even if you specify
|
---|
578 | the `-L' option, `find' may not be able to determine the properties of
|
---|
579 | the file that the link points to (because you don't have sufficient
|
---|
580 | permission). In this situation, `find' uses the properties of the link
|
---|
581 | itself. This also occurs if a symbolic link exists but points to a
|
---|
582 | file that is missing.
|
---|
583 |
|
---|
584 | The options controlling the behaviour of `find' with respect to
|
---|
585 | links are as follows :-
|
---|
586 |
|
---|
587 | `-P'
|
---|
588 | `find' does not dereference symbolic links at all. This is the
|
---|
589 | default behaviour. This option must be specified before any of the
|
---|
590 | file names on the command line.
|
---|
591 |
|
---|
592 | `-H'
|
---|
593 | `find' does not dereference symbolic links (except in the case of
|
---|
594 | file names on the command line, which are dereferenced). If a
|
---|
595 | symbolic link cannot be dereferenced, the information for the
|
---|
596 | symbolic link itself is used. This option must be specified
|
---|
597 | before any of the file names on the command line.
|
---|
598 |
|
---|
599 | `-L'
|
---|
600 | `find' dereferences symbolic links where possible, and where this
|
---|
601 | is not possible it uses the properties of the symbolic link itself.
|
---|
602 | This option must be specified before any of the file names on the
|
---|
603 | command line. Use of this option also implies the same behaviour
|
---|
604 | as the `-noleaf' option. If you later use the `-H' or `-P'
|
---|
605 | options, this does not turn off `-noleaf'.
|
---|
606 |
|
---|
607 | `-follow'
|
---|
608 | This option forms part of the "expression" and must be specified
|
---|
609 | after the file names, but it is otherwise equivalent to `-L'. The
|
---|
610 | `-follow' option affects only those tests which appear after it on
|
---|
611 | the command line. This option is deprecated. Where possible, you
|
---|
612 | should use `-L' instead.
|
---|
613 |
|
---|
614 | The following differences in behavior occur when the `-L' option is
|
---|
615 | used:
|
---|
616 |
|
---|
617 | * `find' follows symbolic links to directories when searching
|
---|
618 | directory trees.
|
---|
619 |
|
---|
620 | * `-lname' and `-ilname' always return false (unless they happen to
|
---|
621 | match broken symbolic links).
|
---|
622 |
|
---|
623 | * `-type' reports the types of the files that symbolic links point
|
---|
624 | to. This means that in combination with `-L', `-type l' will be
|
---|
625 | true only for broken symbolic links. To check for symbolic links
|
---|
626 | when `-L' has been specified, use `-xtype l'.
|
---|
627 |
|
---|
628 | * Implies `-noleaf' (*note Directories::).
|
---|
629 |
|
---|
630 | If the `-L' option or the `-H' option is used, the file names used
|
---|
631 | as arguments to `-newer', `-anewer', and `-cnewer' are dereferenced and
|
---|
632 | the timestamp from the pointed-to file is used instead (if possible -
|
---|
633 | otherwise the timestamp from the symbolic link is used).
|
---|
634 |
|
---|
635 | -- Test: -lname pattern
|
---|
636 | -- Test: -ilname pattern
|
---|
637 | True if the file is a symbolic link whose contents match shell
|
---|
638 | pattern PATTERN. For `-ilname', the match is case-insensitive.
|
---|
639 | *Note Shell Pattern Matching::, for details about the PATTERN
|
---|
640 | argument. If the `-L' option is in effect, this test will always
|
---|
641 | return false for symbolic links unless they are broken. So, to
|
---|
642 | list any symbolic links to `sysdep.c' in the current directory and
|
---|
643 | its subdirectories, you can do:
|
---|
644 |
|
---|
645 | find . -lname '*sysdep.c'
|
---|
646 |
|
---|
647 |
|
---|
648 | File: find.info, Node: Hard Links, Prev: Symbolic Links, Up: Links
|
---|
649 |
|
---|
650 | 2.2.2 Hard Links
|
---|
651 | ----------------
|
---|
652 |
|
---|
653 | Hard links allow more than one name to refer to the same file. To find
|
---|
654 | all the names which refer to the same file as NAME, use `-samefile
|
---|
655 | NAME'. If you are not using the `-L' option, you can confine your
|
---|
656 | search to one filesystem using the `-xdev' option. This is useful
|
---|
657 | because hard links cannot point outside a single filesystem, so this
|
---|
658 | can cut down on needless searching.
|
---|
659 |
|
---|
660 | If the `-L' option is in effect, and NAME is in fact a symbolic
|
---|
661 | link, the symbolic link will be dereferenced. Hence you are searching
|
---|
662 | for other links (hard or symbolic) to the file pointed to by NAME. If
|
---|
663 | `-L' is in effect but NAME is not itself a symbolic link, other
|
---|
664 | symbolic links to the file NAME will be matched.
|
---|
665 |
|
---|
666 | You can also search for files by inode number. This can occasionally
|
---|
667 | be useful in diagnosing problems with filesystems for example, because
|
---|
668 | `fsck' tends to print inode numbers. Inode numbers also occasionally
|
---|
669 | turn up in log messages for some types of software, and are used to
|
---|
670 | support the `ftok()' library function.
|
---|
671 |
|
---|
672 | You can learn a file's inode number and the number of links to it by
|
---|
673 | running `ls -li' or `find -ls'.
|
---|
674 |
|
---|
675 | You can search for hard links to inode number NUM by using `-inum
|
---|
676 | NUM'. If there are any filesystem mount points below the directory
|
---|
677 | where you are starting the search, use the `-xdev' option unless you
|
---|
678 | are also using the `-L' option. Using `-xdev' this saves needless
|
---|
679 | searching, since hard links to a file must be on the same filesystem.
|
---|
680 | *Note Filesystems::.
|
---|
681 |
|
---|
682 | -- Test: -samefile NAME
|
---|
683 | File is a hard link to the same inode as NAME. If the `-L' option
|
---|
684 | is in effect, symbolic links to the same file as NAME points to
|
---|
685 | are also matched.
|
---|
686 |
|
---|
687 | -- Test: -inum n
|
---|
688 | File has inode number N. The `+' and `-' qualifiers also work,
|
---|
689 | though these are rarely useful. Much of the time it is easier to
|
---|
690 | use `-samefile' rather than this option.
|
---|
691 |
|
---|
692 | You can also search for files that have a certain number of links,
|
---|
693 | with `-links'. Directories normally have at least two hard links;
|
---|
694 | their `.' entry is the second one. If they have subdirectories, each
|
---|
695 | of those also has a hard link called `..' to its parent directory. The
|
---|
696 | `.' and `..' directory entries are not normally searched unless they
|
---|
697 | are mentioned on the `find' command line.
|
---|
698 |
|
---|
699 | -- Test: -links n
|
---|
700 | File has N hard links.
|
---|
701 |
|
---|
702 | -- Test: -links +n
|
---|
703 | File has more than N hard links.
|
---|
704 |
|
---|
705 | -- Test: -links -n
|
---|
706 | File has fewer than N hard links.
|
---|
707 |
|
---|
708 |
|
---|
709 | File: find.info, Node: Time, Next: Size, Prev: Links, Up: Finding Files
|
---|
710 |
|
---|
711 | 2.3 Time
|
---|
712 | ========
|
---|
713 |
|
---|
714 | Each file has three time stamps, which record the last time that
|
---|
715 | certain operations were performed on the file:
|
---|
716 |
|
---|
717 | 1. access (read the file's contents)
|
---|
718 |
|
---|
719 | 2. change the status (modify the file or its attributes)
|
---|
720 |
|
---|
721 | 3. modify (change the file's contents)
|
---|
722 |
|
---|
723 | There is no timestamp that indicates when a file was _created_.
|
---|
724 |
|
---|
725 | You can search for files whose time stamps are within a certain age
|
---|
726 | range, or compare them to other time stamps.
|
---|
727 |
|
---|
728 | * Menu:
|
---|
729 |
|
---|
730 | * Age Ranges::
|
---|
731 | * Comparing Timestamps::
|
---|
732 |
|
---|
733 |
|
---|
734 | File: find.info, Node: Age Ranges, Next: Comparing Timestamps, Up: Time
|
---|
735 |
|
---|
736 | 2.3.1 Age Ranges
|
---|
737 | ----------------
|
---|
738 |
|
---|
739 | These tests are mainly useful with ranges (`+N' and `-N').
|
---|
740 |
|
---|
741 | -- Test: -atime n
|
---|
742 | -- Test: -ctime n
|
---|
743 | -- Test: -mtime n
|
---|
744 | True if the file was last accessed (or its status changed, or it
|
---|
745 | was modified) N*24 hours ago. The number of 24-hour periods since
|
---|
746 | the file's timestamp is always rounded down; therefore 0 means
|
---|
747 | "less than 24 hours ago", 1 means "between 24 and 48 hours ago",
|
---|
748 | and so forth.
|
---|
749 |
|
---|
750 | -- Test: -amin n
|
---|
751 | -- Test: -cmin n
|
---|
752 | -- Test: -mmin n
|
---|
753 | True if the file was last accessed (or its status changed, or it
|
---|
754 | was modified) N minutes ago. These tests provide finer granularity
|
---|
755 | of measurement than `-atime' et al., but rounding is done in a
|
---|
756 | similar way. For example, to list files in `/u/bill' that were
|
---|
757 | last read from 2 to 6 minutes ago:
|
---|
758 |
|
---|
759 | find /u/bill -amin +2 -amin -6
|
---|
760 |
|
---|
761 | -- Option: -daystart
|
---|
762 | Measure times from the beginning of today rather than from 24 hours
|
---|
763 | ago. So, to list the regular files in your home directory that
|
---|
764 | were modified yesterday, do
|
---|
765 |
|
---|
766 | find ~ -daystart -type f -mtime 1
|
---|
767 |
|
---|
768 | The `-daystart' option is unlike most other options in that it has
|
---|
769 | an effect on the way that other tests are performed. The affected
|
---|
770 | tests are `-amin', `-cmin', `-mmin', `-atime', `-ctime' and
|
---|
771 | `-mtime'. The `-daystart' option only affects the behaviour of
|
---|
772 | any tests which appear after it on the command line.
|
---|
773 |
|
---|
774 |
|
---|
775 | File: find.info, Node: Comparing Timestamps, Prev: Age Ranges, Up: Time
|
---|
776 |
|
---|
777 | 2.3.2 Comparing Timestamps
|
---|
778 | --------------------------
|
---|
779 |
|
---|
780 | As an alternative to comparing timestamps to the current time, you can
|
---|
781 | compare them to another file's timestamp. That file's timestamp could
|
---|
782 | be updated by another program when some event occurs. Or you could set
|
---|
783 | it to a particular fixed date using the `touch' command. For example,
|
---|
784 | to list files in `/usr' modified after February 1 of the current year:
|
---|
785 |
|
---|
786 | touch -t 02010000 /tmp/stamp$$
|
---|
787 | find /usr -newer /tmp/stamp$$
|
---|
788 | rm -f /tmp/stamp$$
|
---|
789 |
|
---|
790 | -- Test: -anewer file
|
---|
791 | -- Test: -cnewer file
|
---|
792 | -- Test: -newer file
|
---|
793 | True if the file was last accessed (or its status changed, or it
|
---|
794 | was modified) more recently than FILE was modified. These tests
|
---|
795 | are affected by `-follow' only if `-follow' comes before them on
|
---|
796 | the command line. *Note Symbolic Links::, for more information on
|
---|
797 | `-follow'. As an example, to list any files modified since
|
---|
798 | `/bin/sh' was last modified:
|
---|
799 |
|
---|
800 | find . -newer /bin/sh
|
---|
801 |
|
---|
802 | -- Test: -used n
|
---|
803 | True if the file was last accessed N days after its status was
|
---|
804 | last changed. Useful for finding files that are not being used,
|
---|
805 | and could perhaps be archived or removed to save disk space.
|
---|
806 |
|
---|
807 |
|
---|
808 | File: find.info, Node: Size, Next: Type, Prev: Time, Up: Finding Files
|
---|
809 |
|
---|
810 | 2.4 Size
|
---|
811 | ========
|
---|
812 |
|
---|
813 | -- Test: -size n[bckwMG]
|
---|
814 | True if the file uses N units of space, rounding up. The units
|
---|
815 | are 512-byte blocks by default, but they can be changed by adding a
|
---|
816 | one-character suffix to N:
|
---|
817 |
|
---|
818 | `b'
|
---|
819 | 512-byte blocks (never 1024)
|
---|
820 |
|
---|
821 | `c'
|
---|
822 | bytes
|
---|
823 |
|
---|
824 | `k'
|
---|
825 | kilobytes (1024 bytes)
|
---|
826 |
|
---|
827 | `w'
|
---|
828 | 2-byte words
|
---|
829 |
|
---|
830 | `M'
|
---|
831 | Megabytes (units of 1048576 bytes)
|
---|
832 |
|
---|
833 | `G'
|
---|
834 | Gigabytes (units of 1073741824 bytes)
|
---|
835 |
|
---|
836 | The `b' suffix always considers blocks to be 512 bytes. This is
|
---|
837 | not affected by the setting (or non-setting) of the POSIXLY_CORRECT
|
---|
838 | environment variable. This behaviour is different to the
|
---|
839 | behaviour of the `-ls' action). If you want to use 1024-byte
|
---|
840 | units, use the `k' suffix instead.
|
---|
841 |
|
---|
842 | The number can be prefixed with a `+' or a `-'. A plus sign
|
---|
843 | indicates that the test should succeed if the file uses at least N
|
---|
844 | units of storage (a common use of this test) and a minus sign
|
---|
845 | indicates that the test should succeed if the file uses less than
|
---|
846 | N units of storage. There is no `=' prefix, because that's the
|
---|
847 | default anyway.
|
---|
848 |
|
---|
849 | The size does not count indirect blocks, but it does count blocks
|
---|
850 | in sparse files that are not actually allocated. In other words,
|
---|
851 | it's consistent with the result you get for `ls -l' or `wc -c'.
|
---|
852 | This handling of sparse files differs from the output of the `%k'
|
---|
853 | and `%b' format specifiers for the `-printf' predicate.
|
---|
854 |
|
---|
855 |
|
---|
856 | -- Test: -empty
|
---|
857 | True if the file is empty and is either a regular file or a
|
---|
858 | directory. This might help determine good candidates for
|
---|
859 | deletion. This test is useful with `-depth' (*note Directories::)
|
---|
860 | and `-delete' (*note Single File::).
|
---|
861 |
|
---|
862 |
|
---|
863 | File: find.info, Node: Type, Next: Owner, Prev: Size, Up: Finding Files
|
---|
864 |
|
---|
865 | 2.5 Type
|
---|
866 | ========
|
---|
867 |
|
---|
868 | -- Test: -type c
|
---|
869 | True if the file is of type C:
|
---|
870 |
|
---|
871 | `b'
|
---|
872 | block (buffered) special
|
---|
873 |
|
---|
874 | `c'
|
---|
875 | character (unbuffered) special
|
---|
876 |
|
---|
877 | `d'
|
---|
878 | directory
|
---|
879 |
|
---|
880 | `p'
|
---|
881 | named pipe (FIFO)
|
---|
882 |
|
---|
883 | `f'
|
---|
884 | regular file
|
---|
885 |
|
---|
886 | `l'
|
---|
887 | symbolic link; if `-L' is in effect, this is true only for
|
---|
888 | broken symbolic links. If you want to search for symbolic
|
---|
889 | links when `-L' is in effect, use `-xtype' instead of `-type'.
|
---|
890 |
|
---|
891 | `s'
|
---|
892 | socket
|
---|
893 |
|
---|
894 | `D'
|
---|
895 | door (Solaris)
|
---|
896 |
|
---|
897 | -- Test: -xtype c
|
---|
898 | This test behaves the same as `-type' unless the file is a
|
---|
899 | symbolic link. If the file is a symbolic link, the result is as
|
---|
900 | follows (in the table below, `X' should be understood to represent
|
---|
901 | any letter except `l'):
|
---|
902 |
|
---|
903 | ``-P -xtype l''
|
---|
904 | True if the symbolic link is broken
|
---|
905 |
|
---|
906 | ``-P -xtype X''
|
---|
907 | True if the (ultimate) target file is of type `X'.
|
---|
908 |
|
---|
909 | ``-L -xtype l''
|
---|
910 | Always true
|
---|
911 |
|
---|
912 | ``-L -xtype X''
|
---|
913 | False unless the symbolic link is broken
|
---|
914 |
|
---|
915 | In other words, for symbolic links, `-xtype' checks the type of
|
---|
916 | the file that `-type' does not check.
|
---|
917 |
|
---|
918 | The `-H' option also affects the behaviour of `-xtype'. When `-H'
|
---|
919 | is in effect, `-xtype' behaves as if `-L' had been specified when
|
---|
920 | examining files listed on the command line, and as if `-P' had
|
---|
921 | been specified otherwise. If neither `-H' nor `-L' was specified,
|
---|
922 | `-xtype' behaves as if `-P' had been specified.
|
---|
923 |
|
---|
924 | *Note Symbolic Links::, for more information on `-follow' and `-L'.
|
---|
925 |
|
---|
926 |
|
---|
927 | File: find.info, Node: Owner, Next: Mode Bits, Prev: Type, Up: Finding Files
|
---|
928 |
|
---|
929 | 2.6 Owner
|
---|
930 | =========
|
---|
931 |
|
---|
932 | -- Test: -user uname
|
---|
933 | -- Test: -group gname
|
---|
934 | True if the file is owned by user UNAME (belongs to group GNAME).
|
---|
935 | A numeric ID is allowed.
|
---|
936 |
|
---|
937 | -- Test: -uid n
|
---|
938 | -- Test: -gid n
|
---|
939 | True if the file's numeric user ID (group ID) is N. These tests
|
---|
940 | support ranges (`+N' and `-N'), unlike `-user' and `-group'.
|
---|
941 |
|
---|
942 | -- Test: -nouser
|
---|
943 | -- Test: -nogroup
|
---|
944 | True if no user corresponds to the file's numeric user ID (no group
|
---|
945 | corresponds to the numeric group ID). These cases usually mean
|
---|
946 | that the files belonged to users who have since been removed from
|
---|
947 | the system. You probably should change the ownership of such
|
---|
948 | files to an existing user or group, using the `chown' or `chgrp'
|
---|
949 | program.
|
---|
950 |
|
---|
951 |
|
---|
952 | File: find.info, Node: Mode Bits, Next: Contents, Prev: Owner, Up: Finding Files
|
---|
953 |
|
---|
954 | 2.7 File Mode Bits
|
---|
955 | ==================
|
---|
956 |
|
---|
957 | *Note File Permissions::, for information on how file mode bits are
|
---|
958 | structured and how to specify them.
|
---|
959 |
|
---|
960 | Four tests determine what users can do with files. These are
|
---|
961 | `-readable', `-writable', `-executable' and `-perm'. The first three
|
---|
962 | tests ask the operating system if the current user can perform the
|
---|
963 | relevant operation on a file, while `-perm' just examines the file's
|
---|
964 | mode. The file mode may give a misleading impression of what the user
|
---|
965 | can actually do, because the file may have an access control list, or
|
---|
966 | exist on a read-only filesystem, for example. Of these four tests
|
---|
967 | though, only `-perm' is specified by the POSIX standard.
|
---|
968 |
|
---|
969 | The `-readable', `-writable' and `-executable' tests are implemented
|
---|
970 | via the `access' system call. This is implemented within the operating
|
---|
971 | system itself. If the file being considered is on an NFS filesystem,
|
---|
972 | the remote system may allow or forbid read or write operations for
|
---|
973 | reasons of which the NFS client cannot take account. This includes
|
---|
974 | user-ID mapping, either in the general sense or the more restricted
|
---|
975 | sense in which remote superusers are treated by the NFS server as if
|
---|
976 | they are the local user `nobody' on the NFS server.
|
---|
977 |
|
---|
978 | None of the tests in this section should be used to verify that a
|
---|
979 | user is authorised to perform any operation (on the file being tested or
|
---|
980 | any other file) because of the possibility of a race condition. That
|
---|
981 | is, the situation may change between the test and an action being taken
|
---|
982 | on the basis of the result of that test.
|
---|
983 |
|
---|
984 | -- Test: -readable
|
---|
985 | True if the file can be read by the invoking user.
|
---|
986 |
|
---|
987 | -- Test: -writable
|
---|
988 | True if the file can be written by the invoking user. This is an
|
---|
989 | in-principle check, and other things may prevent a successful write
|
---|
990 | operation; for example, the filesystem might be full.
|
---|
991 |
|
---|
992 | -- Test: -executable
|
---|
993 | True if the file can be executed/searched by the invoking user.
|
---|
994 |
|
---|
995 | -- Test: -perm pmode
|
---|
996 | True if the file's mode bits match PMODE, which can be either a
|
---|
997 | symbolic or numeric MODE (*note File Permissions::) optionally
|
---|
998 | prefixed by `-' or `/'.
|
---|
999 |
|
---|
1000 | A PMODE that starts with neither `-' nor `/' matches if MODE
|
---|
1001 | exactly matches the file mode bits.
|
---|
1002 |
|
---|
1003 | A PMODE that starts with `-' matches if _all_ the file mode bits
|
---|
1004 | set in MODE are set for the file; bits not set in MODE are ignored.
|
---|
1005 |
|
---|
1006 | A PMODE that starts with `/' matches if _any_ of the file mode
|
---|
1007 | bits set in MODE are set for the file; bits not set in MODE are
|
---|
1008 | ignored. This is a GNU extension.
|
---|
1009 |
|
---|
1010 | If you don't use the `/' or `-' form with a symbolic mode string,
|
---|
1011 | you may have to specify a rather complex mode string. For example
|
---|
1012 | `-perm g=w' will only match files that have mode 0020 (that is,
|
---|
1013 | ones for which group write permission is the only file mode bit
|
---|
1014 | set). It is more likely that you will want to use the `/' or `-'
|
---|
1015 | forms, for example `-perm -g=w', which matches any file with group
|
---|
1016 | write permission.
|
---|
1017 |
|
---|
1018 | `-perm 664'
|
---|
1019 | Match files that have read and write permission for their
|
---|
1020 | owner, and group, but that the rest of the world can read but
|
---|
1021 | not write to. Do not match files that meet these criteria
|
---|
1022 | but have other file mode bits set (for example if someone can
|
---|
1023 | execute/search the file).
|
---|
1024 |
|
---|
1025 | `-perm -664'
|
---|
1026 | Match files that have read and write permission for their
|
---|
1027 | owner, and group, but that the rest of the world can read but
|
---|
1028 | not write to, without regard to the presence of any extra
|
---|
1029 | file mode bits (for example the executable bit). This matchs
|
---|
1030 | a file with mode 0777, for example.
|
---|
1031 |
|
---|
1032 | `-perm /222'
|
---|
1033 | Match files that are writable by somebody (their owner, or
|
---|
1034 | their group, or anybody else).
|
---|
1035 |
|
---|
1036 | `-perm /022'
|
---|
1037 | Match files that are writable by either their owner or their
|
---|
1038 | group. The files don't have to be writable by both the owner
|
---|
1039 | and group to be matched; either will do.
|
---|
1040 |
|
---|
1041 | `-perm /g+w,o+w'
|
---|
1042 | As above.
|
---|
1043 |
|
---|
1044 | `-perm /g=w,o=w'
|
---|
1045 | As above.
|
---|
1046 |
|
---|
1047 | `-perm -022'
|
---|
1048 | Match files that are writable by both their owner and their
|
---|
1049 | group.
|
---|
1050 |
|
---|
1051 | `-perm -444 -perm /222 ! -perm /111'
|
---|
1052 | Match files that are readable for everybody, have at least one
|
---|
1053 | write bit set (i.e. somebody can write to them), but that
|
---|
1054 | cannot be executed/searched by anybody. Note that in some
|
---|
1055 | shells the `!' must be escaped;.
|
---|
1056 |
|
---|
1057 | `-perm -a+r -perm /a+w ! -perm /a+x'
|
---|
1058 | As above.
|
---|
1059 |
|
---|
1060 | `-perm -g+w,o+w'
|
---|
1061 | As above.
|
---|
1062 |
|
---|
1063 | Warning: If you specify `-perm /000' or `-perm /mode' where
|
---|
1064 | the symbolic mode `mode' has no bits set, the test currently
|
---|
1065 | matches no files. This differs from the behaviour of `-perm
|
---|
1066 | -000', which matches all files. The behaviour of `-perm
|
---|
1067 | /000' will be changed to be consistent with the behaviour of
|
---|
1068 | `-perm -000'. The change will probably be made in early 2006.
|
---|
1069 |
|
---|
1070 |
|
---|
1071 |
|
---|
1072 | File: find.info, Node: Contents, Next: Directories, Prev: Mode Bits, Up: Finding Files
|
---|
1073 |
|
---|
1074 | 2.8 Contents
|
---|
1075 | ============
|
---|
1076 |
|
---|
1077 | To search for files based on their contents, you can use the `grep'
|
---|
1078 | program. For example, to find out which C source files in the current
|
---|
1079 | directory contain the string `thing', you can do:
|
---|
1080 |
|
---|
1081 | grep -l thing *.[ch]
|
---|
1082 |
|
---|
1083 | If you also want to search for the string in files in subdirectories,
|
---|
1084 | you can combine `grep' with `find' and `xargs', like this:
|
---|
1085 |
|
---|
1086 | find . -name '*.[ch]' | xargs grep -l thing
|
---|
1087 |
|
---|
1088 | The `-l' option causes `grep' to print only the names of files that
|
---|
1089 | contain the string, rather than the lines that contain it. The string
|
---|
1090 | argument (`thing') is actually a regular expression, so it can contain
|
---|
1091 | metacharacters. This method can be refined a little by using the `-r'
|
---|
1092 | option to make `xargs' not run `grep' if `find' produces no output, and
|
---|
1093 | using the `find' action `-print0' and the `xargs' option `-0' to avoid
|
---|
1094 | misinterpreting files whose names contain spaces:
|
---|
1095 |
|
---|
1096 | find . -name '*.[ch]' -print0 | xargs -r -0 grep -l thing
|
---|
1097 |
|
---|
1098 | For a fuller treatment of finding files whose contents match a
|
---|
1099 | pattern, see the manual page for `grep'.
|
---|
1100 |
|
---|
1101 |
|
---|
1102 | File: find.info, Node: Directories, Next: Filesystems, Prev: Contents, Up: Finding Files
|
---|
1103 |
|
---|
1104 | 2.9 Directories
|
---|
1105 | ===============
|
---|
1106 |
|
---|
1107 | Here is how to control which directories `find' searches, and how it
|
---|
1108 | searches them. These two options allow you to process a horizontal
|
---|
1109 | slice of a directory tree.
|
---|
1110 |
|
---|
1111 | -- Option: -maxdepth levels
|
---|
1112 | Descend at most LEVELS (a non-negative integer) levels of
|
---|
1113 | directories below the command line arguments. `-maxdepth 0' means
|
---|
1114 | only apply the tests and actions to the command line arguments.
|
---|
1115 |
|
---|
1116 | -- Option: -mindepth levels
|
---|
1117 | Do not apply any tests or actions at levels less than LEVELS (a
|
---|
1118 | non-negative integer). `-mindepth 1' means process all files
|
---|
1119 | except the command line arguments.
|
---|
1120 |
|
---|
1121 | -- Option: -depth
|
---|
1122 | Process each directory's contents before the directory itself.
|
---|
1123 | Doing this is a good idea when producing lists of files to archive
|
---|
1124 | with `cpio' or `tar'. If a directory does not have write
|
---|
1125 | permission for its owner, its contents can still be restored from
|
---|
1126 | the archive since the directory's permissions are restored after
|
---|
1127 | its contents.
|
---|
1128 |
|
---|
1129 | -- Option: -d
|
---|
1130 | This is a deprecated synonym for `-depth', for compatibility with
|
---|
1131 | Mac OS X, FreeBSD and OpenBSD. The `-depth' option is a POSIX
|
---|
1132 | feature, so it is better to use that.
|
---|
1133 |
|
---|
1134 | -- Action: -prune
|
---|
1135 | If the file is a directory, do not descend into it. The result is
|
---|
1136 | true. For example, to skip the directory `src/emacs' and all
|
---|
1137 | files and directories under it, and print the names of the other
|
---|
1138 | files found:
|
---|
1139 |
|
---|
1140 | find . -wholename './src/emacs' -prune -o -print
|
---|
1141 |
|
---|
1142 | The above command will not print `./src/emacs' among its list of
|
---|
1143 | results. This however is not due to the effect of the `-prune'
|
---|
1144 | action (which only prevents further descent, it doesn't make sure
|
---|
1145 | we ignore that item). Instead, this effect is due to the use of
|
---|
1146 | `-o'. Since the left hand side of the "or" condition has
|
---|
1147 | succeeded for `./src/emacs', it is not necessary to evaluate the
|
---|
1148 | right-hand-side (`-print') at all for this particular file. If
|
---|
1149 | you wanted to print that directory name you could use either an
|
---|
1150 | extra `-print' action:
|
---|
1151 |
|
---|
1152 | find . -wholename './src/emacs' -prune -print -o -print
|
---|
1153 |
|
---|
1154 | or use the comma operator:
|
---|
1155 |
|
---|
1156 | find . -wholename './src/emacs' -prune , -print
|
---|
1157 |
|
---|
1158 | If the `-depth' option is in effect, the subdirectories will have
|
---|
1159 | already been visited in any case. Hence `-prune' has no effect
|
---|
1160 | and returns false.
|
---|
1161 |
|
---|
1162 | -- Action: -quit
|
---|
1163 | Exit immediately (with return value zero if no errors have
|
---|
1164 | occurred). No child processes will be left running, but no more
|
---|
1165 | files specified on the command line will be processed. For
|
---|
1166 | example, `find /tmp/foo /tmp/bar -print -quit' will print only
|
---|
1167 | `/tmp/foo'. Any command lines which have been built by `-exec ...
|
---|
1168 | \+' or `-execdir ... \+' are invoked before the program is
|
---|
1169 | executed.
|
---|
1170 |
|
---|
1171 | -- Option: -noleaf
|
---|
1172 | Do not optimize by assuming that directories contain 2 fewer
|
---|
1173 | subdirectories than their hard link count. This option is needed
|
---|
1174 | when searching filesystems that do not follow the Unix
|
---|
1175 | directory-link convention, such as CD-ROM or MS-DOS filesystems or
|
---|
1176 | AFS volume mount points. Each directory on a normal Unix
|
---|
1177 | filesystem has at least 2 hard links: its name and its `.' entry.
|
---|
1178 | Additionally, its subdirectories (if any) each have a `..' entry
|
---|
1179 | linked to that directory. When `find' is examining a directory,
|
---|
1180 | after it has statted 2 fewer subdirectories than the directory's
|
---|
1181 | link count, it knows that the rest of the entries in the directory
|
---|
1182 | are non-directories ("leaf" files in the directory tree). If only
|
---|
1183 | the files' names need to be examined, there is no need to stat
|
---|
1184 | them; this gives a significant increase in search speed.
|
---|
1185 |
|
---|
1186 | -- Option: -ignore_readdir_race
|
---|
1187 | If a file disappears after its name has been read from a directory
|
---|
1188 | but before `find' gets around to examining the file with `stat',
|
---|
1189 | don't issue an error message. If you don't specify this option, an
|
---|
1190 | error message will be issued. This option can be useful in system
|
---|
1191 | scripts (cron scripts, for example) that examine areas of the
|
---|
1192 | filesystem that change frequently (mail queues, temporary
|
---|
1193 | directories, and so forth), because this scenario is common for
|
---|
1194 | those sorts of directories. Completely silencing error messages
|
---|
1195 | from `find' is undesirable, so this option neatly solves the
|
---|
1196 | problem. There is no way to search one part of the filesystem
|
---|
1197 | with this option on and part of it with this option off, though.
|
---|
1198 | When this option is turned on and find discovers that one of the
|
---|
1199 | start-point files specified on the command line does not exist, no
|
---|
1200 | error message will be issued.
|
---|
1201 |
|
---|
1202 |
|
---|
1203 | -- Option: -noignore_readdir_race
|
---|
1204 | This option reverses the effect of the `-ignore_readdir_race'
|
---|
1205 | option.
|
---|
1206 |
|
---|
1207 |
|
---|
1208 | File: find.info, Node: Filesystems, Next: Combining Primaries With Operators, Prev: Directories, Up: Finding Files
|
---|
1209 |
|
---|
1210 | 2.10 Filesystems
|
---|
1211 | ================
|
---|
1212 |
|
---|
1213 | A "filesystem" is a section of a disk, either on the local host or
|
---|
1214 | mounted from a remote host over a network. Searching network
|
---|
1215 | filesystems can be slow, so it is common to make `find' avoid them.
|
---|
1216 |
|
---|
1217 | There are two ways to avoid searching certain filesystems. One way
|
---|
1218 | is to tell `find' to only search one filesystem:
|
---|
1219 |
|
---|
1220 | -- Option: -xdev
|
---|
1221 | -- Option: -mount
|
---|
1222 | Don't descend directories on other filesystems. These options are
|
---|
1223 | synonyms.
|
---|
1224 |
|
---|
1225 | The other way is to check the type of filesystem each file is on, and
|
---|
1226 | not descend directories that are on undesirable filesystem types:
|
---|
1227 |
|
---|
1228 | -- Test: -fstype type
|
---|
1229 | True if the file is on a filesystem of type TYPE. The valid
|
---|
1230 | filesystem types vary among different versions of Unix; an
|
---|
1231 | incomplete list of filesystem types that are accepted on some
|
---|
1232 | version of Unix or another is:
|
---|
1233 | ext2 ext3 proc sysfs ufs 4.2 4.3 nfs tmp mfs S51K S52K
|
---|
1234 | You can use `-printf' with the `%F' directive to see the types of
|
---|
1235 | your filesystems. The `%D' directive shows the device number.
|
---|
1236 | *Note Print File Information::. `-fstype' is usually used with
|
---|
1237 | `-prune' to avoid searching remote filesystems (*note
|
---|
1238 | Directories::).
|
---|
1239 |
|
---|
1240 |
|
---|
1241 | File: find.info, Node: Combining Primaries With Operators, Prev: Filesystems, Up: Finding Files
|
---|
1242 |
|
---|
1243 | 2.11 Combining Primaries With Operators
|
---|
1244 | =======================================
|
---|
1245 |
|
---|
1246 | Operators build a complex expression from tests and actions. The
|
---|
1247 | operators are, in order of decreasing precedence:
|
---|
1248 |
|
---|
1249 | `( EXPR )'
|
---|
1250 | Force precedence. True if EXPR is true.
|
---|
1251 |
|
---|
1252 | `! EXPR'
|
---|
1253 | `-not EXPR'
|
---|
1254 | True if EXPR is false. In some shells, it is necessary to protect
|
---|
1255 | the `!' from shell interpretation by quoting it.
|
---|
1256 |
|
---|
1257 | `EXPR1 EXPR2'
|
---|
1258 | `EXPR1 -a EXPR2'
|
---|
1259 | `EXPR1 -and EXPR2'
|
---|
1260 | And; EXPR2 is not evaluated if EXPR1 is false.
|
---|
1261 |
|
---|
1262 | `EXPR1 -o EXPR2'
|
---|
1263 | `EXPR1 -or EXPR2'
|
---|
1264 | Or; EXPR2 is not evaluated if EXPR1 is true.
|
---|
1265 |
|
---|
1266 | `EXPR1 , EXPR2'
|
---|
1267 | List; both EXPR1 and EXPR2 are always evaluated. True if EXPR2 is
|
---|
1268 | true. The value of EXPR1 is discarded. This operator lets you do
|
---|
1269 | multiple independent operations on one traversal, without
|
---|
1270 | depending on whether other operations succeeded. The two
|
---|
1271 | operations EXPR1 and EXPR2 are not always fully independent, since
|
---|
1272 | EXPR1 might have side effects like touching or deleting files, or
|
---|
1273 | it might use `-prune' which would also affect EXPR2.
|
---|
1274 |
|
---|
1275 | `find' searches the directory tree rooted at each file name by
|
---|
1276 | evaluating the expression from left to right, according to the rules of
|
---|
1277 | precedence, until the outcome is known (the left hand side is false for
|
---|
1278 | `-and', true for `-or'), at which point `find' moves on to the next
|
---|
1279 | file name.
|
---|
1280 |
|
---|
1281 | There are two other tests that can be useful in complex expressions:
|
---|
1282 |
|
---|
1283 | -- Test: -true
|
---|
1284 | Always true.
|
---|
1285 |
|
---|
1286 | -- Test: -false
|
---|
1287 | Always false.
|
---|
1288 |
|
---|
1289 |
|
---|
1290 | File: find.info, Node: Actions, Next: Databases, Prev: Finding Files, Up: Top
|
---|
1291 |
|
---|
1292 | 3 Actions
|
---|
1293 | *********
|
---|
1294 |
|
---|
1295 | There are several ways you can print information about the files that
|
---|
1296 | match the criteria you gave in the `find' expression. You can print
|
---|
1297 | the information either to the standard output or to a file that you
|
---|
1298 | name. You can also execute commands that have the file names as
|
---|
1299 | arguments. You can use those commands as further filters to select
|
---|
1300 | files.
|
---|
1301 |
|
---|
1302 | * Menu:
|
---|
1303 |
|
---|
1304 | * Print File Name::
|
---|
1305 | * Print File Information::
|
---|
1306 | * Run Commands::
|
---|
1307 | * Delete Files::
|
---|
1308 | * Adding Tests::
|
---|
1309 |
|
---|
1310 |
|
---|
1311 | File: find.info, Node: Print File Name, Next: Print File Information, Up: Actions
|
---|
1312 |
|
---|
1313 | 3.1 Print File Name
|
---|
1314 | ===================
|
---|
1315 |
|
---|
1316 | -- Action: -print
|
---|
1317 | True; print the entire file name on the standard output, followed
|
---|
1318 | by a newline. If there is the faintest possibility that one of
|
---|
1319 | the files for which you are searching might contain a newline, you
|
---|
1320 | should use `-print0' instead.
|
---|
1321 |
|
---|
1322 | -- Action: -fprint file
|
---|
1323 | True; print the entire file name into file FILE, followed by a
|
---|
1324 | newline. If FILE does not exist when `find' is run, it is
|
---|
1325 | created; if it does exist, it is truncated to 0 bytes. The named
|
---|
1326 | output file is always created, even if no output is sent to it.
|
---|
1327 | The file names `/dev/stdout' and `/dev/stderr' are handled
|
---|
1328 | specially; they refer to the standard output and standard error
|
---|
1329 | output, respectively.
|
---|
1330 |
|
---|
1331 | If there is the faintest possibility that one of the files for
|
---|
1332 | which you are searching might contain a newline, you should use
|
---|
1333 | `-fprint0' instead.
|
---|
1334 |
|
---|
1335 |
|
---|
1336 | File: find.info, Node: Print File Information, Next: Run Commands, Prev: Print File Name, Up: Actions
|
---|
1337 |
|
---|
1338 | 3.2 Print File Information
|
---|
1339 | ==========================
|
---|
1340 |
|
---|
1341 | -- Action: -ls
|
---|
1342 | True; list the current file in `ls -dils' format on the standard
|
---|
1343 | output. The output looks like this:
|
---|
1344 |
|
---|
1345 | 204744 17 -rw-r--r-- 1 djm staff 17337 Nov 2 1992 ./lwall-quotes
|
---|
1346 |
|
---|
1347 | The fields are:
|
---|
1348 |
|
---|
1349 | 1. The inode number of the file. *Note Hard Links::, for how to
|
---|
1350 | find files based on their inode number.
|
---|
1351 |
|
---|
1352 | 2. the number of blocks in the file. The block counts are of 1K
|
---|
1353 | blocks, unless the environment variable `POSIXLY_CORRECT' is
|
---|
1354 | set, in which case 512-byte blocks are used. *Note Size::,
|
---|
1355 | for how to find files based on their size.
|
---|
1356 |
|
---|
1357 | 3. The file's type and file mode bits. The type is shown as a
|
---|
1358 | dash for a regular file; for other file types, a letter like
|
---|
1359 | for `-type' is used (*note Type::). The file mode bits are
|
---|
1360 | read, write, and execute/search for the file's owner, its
|
---|
1361 | group, and other users, respectively; a dash means the
|
---|
1362 | permission is not granted. *Note File Permissions::, for
|
---|
1363 | more details about file permissions. *Note Mode Bits::, for
|
---|
1364 | how to find files based on their file mode bits.
|
---|
1365 |
|
---|
1366 | 4. The number of hard links to the file.
|
---|
1367 |
|
---|
1368 | 5. The user who owns the file.
|
---|
1369 |
|
---|
1370 | 6. The file's group.
|
---|
1371 |
|
---|
1372 | 7. The file's size in bytes.
|
---|
1373 |
|
---|
1374 | 8. The date the file was last modified.
|
---|
1375 |
|
---|
1376 | 9. The file's name. `-ls' quotes non-printable characters in the
|
---|
1377 | file names using C-like backslash escapes. This may change
|
---|
1378 | soon, as the treatment of unprintable characters is
|
---|
1379 | harmonised for `-ls', `-fls', `-print', `-fprint', `-printf'
|
---|
1380 | and `-fprintf'.
|
---|
1381 |
|
---|
1382 | -- Action: -fls file
|
---|
1383 | True; like `-ls' but write to FILE like `-fprint' (*note Print
|
---|
1384 | File Name::). The named output file is always created, even if no
|
---|
1385 | output is sent to it.
|
---|
1386 |
|
---|
1387 | -- Action: -printf format
|
---|
1388 | True; print FORMAT on the standard output, interpreting `\'
|
---|
1389 | escapes and `%' directives. Field widths and precisions can be
|
---|
1390 | specified as with the `printf' C function. Format flags (like `#'
|
---|
1391 | for example) may not work as you expect because many of the
|
---|
1392 | fields, even numeric ones, are printed with %s. Numeric flags
|
---|
1393 | which are affected in this way include G, U, b, D, k and n. This
|
---|
1394 | difference in behaviour means though that the format flag `-' will
|
---|
1395 | work; it forces left-alignment of the field. Unlike `-print',
|
---|
1396 | `-printf' does not add a newline at the end of the string. If you
|
---|
1397 | want a newline at the end of the string, add a `\n'.
|
---|
1398 |
|
---|
1399 | -- Action: -fprintf file format
|
---|
1400 | True; like `-printf' but write to FILE like `-fprint' (*note Print
|
---|
1401 | File Name::). The output file is always created, even if no
|
---|
1402 | output is ever sent to it.
|
---|
1403 |
|
---|
1404 | * Menu:
|
---|
1405 |
|
---|
1406 | * Escapes::
|
---|
1407 | * Format Directives::
|
---|
1408 | * Time Formats::
|
---|
1409 |
|
---|
1410 |
|
---|
1411 | File: find.info, Node: Escapes, Next: Format Directives, Up: Print File Information
|
---|
1412 |
|
---|
1413 | 3.2.1 Escapes
|
---|
1414 | -------------
|
---|
1415 |
|
---|
1416 | The escapes that `-printf' and `-fprintf' recognise are:
|
---|
1417 |
|
---|
1418 | `\a'
|
---|
1419 | Alarm bell.
|
---|
1420 |
|
---|
1421 | `\b'
|
---|
1422 | Backspace.
|
---|
1423 |
|
---|
1424 | `\c'
|
---|
1425 | Stop printing from this format immediately and flush the output.
|
---|
1426 |
|
---|
1427 | `\f'
|
---|
1428 | Form feed.
|
---|
1429 |
|
---|
1430 | `\n'
|
---|
1431 | Newline.
|
---|
1432 |
|
---|
1433 | `\r'
|
---|
1434 | Carriage return.
|
---|
1435 |
|
---|
1436 | `\t'
|
---|
1437 | Horizontal tab.
|
---|
1438 |
|
---|
1439 | `\v'
|
---|
1440 | Vertical tab.
|
---|
1441 |
|
---|
1442 | `\\'
|
---|
1443 | A literal backslash (`\').
|
---|
1444 |
|
---|
1445 | `\0'
|
---|
1446 | ASCII NUL.
|
---|
1447 |
|
---|
1448 | `\NNN'
|
---|
1449 | The character whose ASCII code is NNN (octal).
|
---|
1450 |
|
---|
1451 | A `\' character followed by any other character is treated as an
|
---|
1452 | ordinary character, so they both are printed, and a warning message is
|
---|
1453 | printed to the standard error output (because it was probably a typo).
|
---|
1454 |
|
---|
1455 |
|
---|
1456 | File: find.info, Node: Format Directives, Next: Time Formats, Prev: Escapes, Up: Print File Information
|
---|
1457 |
|
---|
1458 | 3.2.2 Format Directives
|
---|
1459 | -----------------------
|
---|
1460 |
|
---|
1461 | `-printf' and `-fprintf' support the following format directives to
|
---|
1462 | print information about the file being processed. The C `printf'
|
---|
1463 | function, field width and precision specifiers are supported, as
|
---|
1464 | applied to string (%s) types. That is, you can specify "minimum field
|
---|
1465 | width"."maximum field width" for each directive. Format flags (like
|
---|
1466 | `#' for example) may not work as you expect because many of the fields,
|
---|
1467 | even numeric ones, are printed with %s. The format flag `-' does work;
|
---|
1468 | it forces left-alignment of the field.
|
---|
1469 |
|
---|
1470 | `%%' is a literal percent sign. A `%' character followed by an
|
---|
1471 | unrecognised character (i.e. not a known directive or `printf' field
|
---|
1472 | width and precision specifier), is discarded (but the unrecognised
|
---|
1473 | character is printed), and a warning message is printed to the standard
|
---|
1474 | error output (because it was probably a typo). Don't rely on this
|
---|
1475 | behaviour, because other directives may be added in the future.
|
---|
1476 |
|
---|
1477 | A `%' at the end of the format argument causes undefined behaviour
|
---|
1478 | since there is no following character. In some locales, it may hide
|
---|
1479 | your door keys, while in others it may remove the final page from the
|
---|
1480 | novel you are reading.
|
---|
1481 |
|
---|
1482 | * Menu:
|
---|
1483 |
|
---|
1484 | * Name Directives::
|
---|
1485 | * Ownership Directives::
|
---|
1486 | * Size Directives::
|
---|
1487 | * Location Directives::
|
---|
1488 | * Time Directives::
|
---|
1489 | * Formatting Flags::
|
---|
1490 |
|
---|
1491 |
|
---|
1492 | File: find.info, Node: Name Directives, Next: Ownership Directives, Up: Format Directives
|
---|
1493 |
|
---|
1494 | 3.2.2.1 Name Directives
|
---|
1495 | .......................
|
---|
1496 |
|
---|
1497 | `%p'
|
---|
1498 | File's name (not the absolute path name, but the name of the file
|
---|
1499 | as it was encountered by `find' - that is, as a relative path from
|
---|
1500 | one of the starting points).
|
---|
1501 |
|
---|
1502 | `%f'
|
---|
1503 | File's name with any leading directories removed (only the last
|
---|
1504 | element).
|
---|
1505 |
|
---|
1506 | `%h'
|
---|
1507 | Leading directories of file's name (all but the last element and
|
---|
1508 | the slash before it). If the file's name contains no slashes (for
|
---|
1509 | example because it was named on the command line and is in the
|
---|
1510 | current working directory), then "%h" expands to ".". This
|
---|
1511 | prevents "%h/%f" expanding to "/foo", which would be surprising
|
---|
1512 | and probably not desirable.
|
---|
1513 |
|
---|
1514 | `%P'
|
---|
1515 | File's name with the name of the command line argument under which
|
---|
1516 | it was found removed from the beginning.
|
---|
1517 |
|
---|
1518 | `%H'
|
---|
1519 | Command line argument under which file was found.
|
---|
1520 |
|
---|
1521 |
|
---|
1522 | File: find.info, Node: Ownership Directives, Next: Size Directives, Prev: Name Directives, Up: Format Directives
|
---|
1523 |
|
---|
1524 | 3.2.2.2 Ownership Directives
|
---|
1525 | ............................
|
---|
1526 |
|
---|
1527 | `%g'
|
---|
1528 | File's group name, or numeric group ID if the group has no name.
|
---|
1529 |
|
---|
1530 | `%G'
|
---|
1531 | File's numeric group ID.
|
---|
1532 |
|
---|
1533 | `%u'
|
---|
1534 | File's user name, or numeric user ID if the user has no name.
|
---|
1535 |
|
---|
1536 | `%U'
|
---|
1537 | File's numeric user ID.
|
---|
1538 |
|
---|
1539 | `%m'
|
---|
1540 | File's mode bits (in octal). If you always want to have a leading
|
---|
1541 | zero on the number, use the '#' format flag, for example '%#m'.
|
---|
1542 |
|
---|
1543 | The file mode bit numbers used are the traditional Unix numbers,
|
---|
1544 | which will be as expected on most systems, but if your system's
|
---|
1545 | file mode bit layout differs from the traditional Unix semantics,
|
---|
1546 | you will see a difference between the mode as printed by `%m' and
|
---|
1547 | the mode as it appears in `struct stat'.
|
---|
1548 |
|
---|
1549 | `%M'
|
---|
1550 | File's type and mode bits (in symbolic form, as for `ls'). This
|
---|
1551 | directive is supported in findutils 4.2.5 and later.
|
---|
1552 |
|
---|
1553 |
|
---|
1554 | File: find.info, Node: Size Directives, Next: Location Directives, Prev: Ownership Directives, Up: Format Directives
|
---|
1555 |
|
---|
1556 | 3.2.2.3 Size Directives
|
---|
1557 | .......................
|
---|
1558 |
|
---|
1559 | `%k'
|
---|
1560 | The amount of disk space used for this file in 1K blocks. Since
|
---|
1561 | disk space is allocated in multiples of the filesystem block size
|
---|
1562 | this is usually greater than %s/1024, but it can also be smaller
|
---|
1563 | if the file is a sparse file (that is, it has "holes").
|
---|
1564 |
|
---|
1565 | `%b'
|
---|
1566 | The amount of disk space used for this file in 512-byte blocks.
|
---|
1567 | Since disk space is allocated in multiples of the filesystem block
|
---|
1568 | size this is usually greater than %s/1024, but it can also be
|
---|
1569 | smaller if the file is a sparse file (that is, it has "holes").
|
---|
1570 |
|
---|
1571 | `%s'
|
---|
1572 | File's size in bytes.
|
---|
1573 |
|
---|
1574 |
|
---|
1575 | File: find.info, Node: Location Directives, Next: Time Directives, Prev: Size Directives, Up: Format Directives
|
---|
1576 |
|
---|
1577 | 3.2.2.4 Location Directives
|
---|
1578 | ...........................
|
---|
1579 |
|
---|
1580 | `%d'
|
---|
1581 | File's depth in the directory tree (depth below a file named on the
|
---|
1582 | command line, not depth below the root directory). Files named on
|
---|
1583 | the command line have a depth of 0. Subdirectories immediately
|
---|
1584 | below them have a depth of 1, and so on.
|
---|
1585 |
|
---|
1586 | `%D'
|
---|
1587 | The device number on which the file exists (the `st_dev' field of
|
---|
1588 | `struct stat'), in decimal.
|
---|
1589 |
|
---|
1590 | `%F'
|
---|
1591 | Type of the filesystem the file is on; this value can be used for
|
---|
1592 | `-fstype' (*note Directories::).
|
---|
1593 |
|
---|
1594 | `%l'
|
---|
1595 | Object of symbolic link (empty string if file is not a symbolic
|
---|
1596 | link).
|
---|
1597 |
|
---|
1598 | `%i'
|
---|
1599 | File's inode number (in decimal).
|
---|
1600 |
|
---|
1601 | `%n'
|
---|
1602 | Number of hard links to file.
|
---|
1603 |
|
---|
1604 | `%y'
|
---|
1605 | Type of the file as used with `-type'. If the file is a symbolic
|
---|
1606 | link, `l' will be printed.
|
---|
1607 |
|
---|
1608 | `%Y'
|
---|
1609 | Type of the file as used with `-type'. If the file is a symbolic
|
---|
1610 | link, it is dereferenced. If the file is a broken symbolic link,
|
---|
1611 | `N' is printed.
|
---|
1612 |
|
---|
1613 |
|
---|
1614 |
|
---|
1615 | File: find.info, Node: Time Directives, Next: Formatting Flags, Prev: Location Directives, Up: Format Directives
|
---|
1616 |
|
---|
1617 | 3.2.2.5 Time Directives
|
---|
1618 | .......................
|
---|
1619 |
|
---|
1620 | Some of these directives use the C `ctime' function. Its output
|
---|
1621 | depends on the current locale, but it typically looks like
|
---|
1622 |
|
---|
1623 | Wed Nov 2 00:42:36 1994
|
---|
1624 |
|
---|
1625 | `%a'
|
---|
1626 | File's last access time in the format returned by the C `ctime'
|
---|
1627 | function.
|
---|
1628 |
|
---|
1629 | `%AK'
|
---|
1630 | File's last access time in the format specified by K (*note Time
|
---|
1631 | Formats::).
|
---|
1632 |
|
---|
1633 | `%c'
|
---|
1634 | File's last status change time in the format returned by the C
|
---|
1635 | `ctime' function.
|
---|
1636 |
|
---|
1637 | `%CK'
|
---|
1638 | File's last status change time in the format specified by K (*note
|
---|
1639 | Time Formats::).
|
---|
1640 |
|
---|
1641 | `%t'
|
---|
1642 | File's last modification time in the format returned by the C
|
---|
1643 | `ctime' function.
|
---|
1644 |
|
---|
1645 | `%TK'
|
---|
1646 | File's last modification time in the format specified by K (*note
|
---|
1647 | Time Formats::).
|
---|
1648 |
|
---|
1649 |
|
---|
1650 | File: find.info, Node: Time Formats, Prev: Format Directives, Up: Print File Information
|
---|
1651 |
|
---|
1652 | 3.2.3 Time Formats
|
---|
1653 | ------------------
|
---|
1654 |
|
---|
1655 | Below are the formats for the directives `%A', `%C', and `%T', which
|
---|
1656 | print the file's timestamps. Some of these formats might not be
|
---|
1657 | available on all systems, due to differences in the C `strftime'
|
---|
1658 | function between systems.
|
---|
1659 |
|
---|
1660 | * Menu:
|
---|
1661 |
|
---|
1662 | * Time Components::
|
---|
1663 | * Date Components::
|
---|
1664 | * Combined Time Formats::
|
---|
1665 |
|
---|
1666 |
|
---|
1667 | File: find.info, Node: Time Components, Next: Date Components, Up: Time Formats
|
---|
1668 |
|
---|
1669 | 3.2.3.1 Time Components
|
---|
1670 | .......................
|
---|
1671 |
|
---|
1672 | The following format directives print single components of the time.
|
---|
1673 |
|
---|
1674 | `H'
|
---|
1675 | hour (00..23)
|
---|
1676 |
|
---|
1677 | `I'
|
---|
1678 | hour (01..12)
|
---|
1679 |
|
---|
1680 | `k'
|
---|
1681 | hour ( 0..23)
|
---|
1682 |
|
---|
1683 | `l'
|
---|
1684 | hour ( 1..12)
|
---|
1685 |
|
---|
1686 | `p'
|
---|
1687 | locale's AM or PM
|
---|
1688 |
|
---|
1689 | `Z'
|
---|
1690 | time zone (e.g., EDT), or nothing if no time zone is determinable
|
---|
1691 |
|
---|
1692 | `M'
|
---|
1693 | minute (00..59)
|
---|
1694 |
|
---|
1695 | `S'
|
---|
1696 | second (00..61)
|
---|
1697 |
|
---|
1698 | `@'
|
---|
1699 | seconds since Jan. 1, 1970, 00:00 GMT.
|
---|
1700 |
|
---|
1701 |
|
---|
1702 | File: find.info, Node: Date Components, Next: Combined Time Formats, Prev: Time Components, Up: Time Formats
|
---|
1703 |
|
---|
1704 | 3.2.3.2 Date Components
|
---|
1705 | .......................
|
---|
1706 |
|
---|
1707 | The following format directives print single components of the date.
|
---|
1708 |
|
---|
1709 | `a'
|
---|
1710 | locale's abbreviated weekday name (Sun..Sat)
|
---|
1711 |
|
---|
1712 | `A'
|
---|
1713 | locale's full weekday name, variable length (Sunday..Saturday)
|
---|
1714 |
|
---|
1715 | `b'
|
---|
1716 | `h'
|
---|
1717 | locale's abbreviated month name (Jan..Dec)
|
---|
1718 |
|
---|
1719 | `B'
|
---|
1720 | locale's full month name, variable length (January..December)
|
---|
1721 |
|
---|
1722 | `m'
|
---|
1723 | month (01..12)
|
---|
1724 |
|
---|
1725 | `d'
|
---|
1726 | day of month (01..31)
|
---|
1727 |
|
---|
1728 | `w'
|
---|
1729 | day of week (0..6)
|
---|
1730 |
|
---|
1731 | `j'
|
---|
1732 | day of year (001..366)
|
---|
1733 |
|
---|
1734 | `U'
|
---|
1735 | week number of year with Sunday as first day of week (00..53)
|
---|
1736 |
|
---|
1737 | `W'
|
---|
1738 | week number of year with Monday as first day of week (00..53)
|
---|
1739 |
|
---|
1740 | `Y'
|
---|
1741 | year (1970...)
|
---|
1742 |
|
---|
1743 | `y'
|
---|
1744 | last two digits of year (00..99)
|
---|
1745 |
|
---|
1746 |
|
---|
1747 | File: find.info, Node: Combined Time Formats, Prev: Date Components, Up: Time Formats
|
---|
1748 |
|
---|
1749 | 3.2.3.3 Combined Time Formats
|
---|
1750 | .............................
|
---|
1751 |
|
---|
1752 | The following format directives print combinations of time and date
|
---|
1753 | components.
|
---|
1754 |
|
---|
1755 | `r'
|
---|
1756 | time, 12-hour (hh:mm:ss [AP]M)
|
---|
1757 |
|
---|
1758 | `T'
|
---|
1759 | time, 24-hour (hh:mm:ss)
|
---|
1760 |
|
---|
1761 | `X'
|
---|
1762 | locale's time representation (H:M:S)
|
---|
1763 |
|
---|
1764 | `c'
|
---|
1765 | locale's date and time (Sat Nov 04 12:02:33 EST 1989)
|
---|
1766 |
|
---|
1767 | `D'
|
---|
1768 | date (mm/dd/yy)
|
---|
1769 |
|
---|
1770 | `x'
|
---|
1771 | locale's date representation (mm/dd/yy)
|
---|
1772 |
|
---|
1773 | `+'
|
---|
1774 | Date and time, separated by '+', for example `2004-04-28+22:22:05'.
|
---|
1775 | The time is given in the current timezone (which may be affected by
|
---|
1776 | setting the TZ environment variable). This is a GNU extension.
|
---|
1777 |
|
---|
1778 |
|
---|
1779 | File: find.info, Node: Formatting Flags, Prev: Time Directives, Up: Format Directives
|
---|
1780 |
|
---|
1781 | 3.2.3.4 Formatting Flags
|
---|
1782 | ........................
|
---|
1783 |
|
---|
1784 | The `%m' and `%d' directives support the `#', `0' and `+' flags, but
|
---|
1785 | the other directives do not, even if they print numbers. Numeric
|
---|
1786 | directives that do not support these flags include
|
---|
1787 |
|
---|
1788 | `G', `U', `b', `D', `k' and `n'.
|
---|
1789 |
|
---|
1790 | All fields support the format flag `-', which makes fields
|
---|
1791 | left-aligned. That is, if the field width is greater than the actual
|
---|
1792 | contents of the field, the requisite number of spaces are printed after
|
---|
1793 | the field content instead of before it.
|
---|
1794 |
|
---|
1795 |
|
---|
1796 | File: find.info, Node: Run Commands, Next: Delete Files, Prev: Print File Information, Up: Actions
|
---|
1797 |
|
---|
1798 | 3.3 Run Commands
|
---|
1799 | ================
|
---|
1800 |
|
---|
1801 | You can use the list of file names created by `find' or `locate' as
|
---|
1802 | arguments to other commands. In this way you can perform arbitrary
|
---|
1803 | actions on the files.
|
---|
1804 |
|
---|
1805 | * Menu:
|
---|
1806 |
|
---|
1807 | * Single File::
|
---|
1808 | * Multiple Files::
|
---|
1809 | * Querying::
|
---|
1810 |
|
---|
1811 |
|
---|
1812 | File: find.info, Node: Single File, Next: Multiple Files, Up: Run Commands
|
---|
1813 |
|
---|
1814 | 3.3.1 Single File
|
---|
1815 | -----------------
|
---|
1816 |
|
---|
1817 | Here is how to run a command on one file at a time.
|
---|
1818 |
|
---|
1819 | -- Action: -execdir command ;
|
---|
1820 | Execute COMMAND; true if zero sftatus is returned. `find' takes
|
---|
1821 | all arguments after `-exec' to be part of the command until an
|
---|
1822 | argument consisting of `;' is reached. It replaces the string
|
---|
1823 | `{}' by the current file name being processed everywhere it occurs
|
---|
1824 | in the command. Both of these constructions need to be escaped
|
---|
1825 | (with a `\') or quoted to protect them from expansion by the
|
---|
1826 | shell. The command is executed in the directory in which `find'
|
---|
1827 | was run.
|
---|
1828 |
|
---|
1829 | For example, to compare each C header file in or below the current
|
---|
1830 | directory with the file `/tmp/master':
|
---|
1831 |
|
---|
1832 | find . -name '*.h' -execdir diff -u '{}' /tmp/master ';'
|
---|
1833 |
|
---|
1834 | If you use``-execdir', you must ensure that the current directory is
|
---|
1835 | not on $PATH, because otherwise an attacker could make `find' run
|
---|
1836 | commands of their choice simply by leaving a suitably-named file in the
|
---|
1837 | right directory. GNU find will refuse to run if you use `-execdir' and
|
---|
1838 | the current directory is in $PATH.
|
---|
1839 |
|
---|
1840 | Another similar option, `-exec' is supported, but is less secure.
|
---|
1841 | *Note Security Considerations::, for a discussion of the security
|
---|
1842 | problems surrounding `-exec'.
|
---|
1843 |
|
---|
1844 | -- Action: -exec command ;
|
---|
1845 | This insecure variant of the `-execdir' action is specified by
|
---|
1846 | POSIX. The main difference is that the command is executed in the
|
---|
1847 | directory from which `find' was invoked, meaning that `{}' is
|
---|
1848 | expanded to a relative path starting with the name of one of the
|
---|
1849 | starting directories, rather than just the basename of the matched
|
---|
1850 | file.
|
---|
1851 |
|
---|
1852 | While some implementations of `find' replace the `{}' only where
|
---|
1853 | it appears on its own in an argument, GNU `find' replaces `{}'
|
---|
1854 | wherever it appears.
|
---|
1855 |
|
---|
1856 |
|
---|
1857 | File: find.info, Node: Multiple Files, Next: Querying, Prev: Single File, Up: Run Commands
|
---|
1858 |
|
---|
1859 | 3.3.2 Multiple Files
|
---|
1860 | --------------------
|
---|
1861 |
|
---|
1862 | Sometimes you need to process files one of the time. But usually this
|
---|
1863 | is not necessary, and, it is faster to run a command on as many files
|
---|
1864 | as possible at a time, rather than once per file. Doing this saves on
|
---|
1865 | the time it takes to start up the command each time.
|
---|
1866 |
|
---|
1867 | The `-execdir' and `-exec' actions have variants that build command
|
---|
1868 | lines containing as many matched files as possible.
|
---|
1869 |
|
---|
1870 | -- Action: -execdir command {} +
|
---|
1871 | This works as for `-execdir command ;', except that the `{}' at
|
---|
1872 | the end of the command is expanded to a list of names of matching
|
---|
1873 | files. This expansion is done in such a way as to avoid exceeding
|
---|
1874 | the maximum command line length available on the system. Only one
|
---|
1875 | `{}' is allowed within the command, and it must appear at the end,
|
---|
1876 | immediately before the `+'. A `+' appearing in any position other
|
---|
1877 | than immediately after `{}' is not considered to be special (that
|
---|
1878 | is, it does not terminate the command).
|
---|
1879 |
|
---|
1880 | -- Action: -exec command {} +
|
---|
1881 | This insecure variant of the `-execdir' action is specified by
|
---|
1882 | POSIX. The main difference is that the command is executed in the
|
---|
1883 | directory from which `find' was invoked, meaning that `{}' is
|
---|
1884 | expanded to a relative path starting with the name of one of the
|
---|
1885 | starting directories, rather than just the basename of the matched
|
---|
1886 | file.
|
---|
1887 |
|
---|
1888 | Before `find' exits, any partially-built command lines are executed.
|
---|
1889 | This happens even if the exit was caused by the `-quit' action.
|
---|
1890 | However, some types of error (for example not being able to invoke
|
---|
1891 | `stat()' on the current directory) can cause an immediate fatal exit.
|
---|
1892 | In this situation, any partially-built command lines will not be
|
---|
1893 | invoked (this prevents possible infinite loops).
|
---|
1894 |
|
---|
1895 | Another, but less secure, way to run a command on more than one file
|
---|
1896 | at once, is to use the `xargs' command, which is invoked like this:
|
---|
1897 |
|
---|
1898 | xargs [OPTION...] [COMMAND [INITIAL-ARGUMENTS]]
|
---|
1899 |
|
---|
1900 | `xargs' normally reads arguments from the standard input. These
|
---|
1901 | arguments are delimited by blanks (which can be protected with double
|
---|
1902 | or single quotes or a backslash) or newlines. It executes the COMMAND
|
---|
1903 | (default is `/bin/echo') one or more times with any INITIAL-ARGUMENTS
|
---|
1904 | followed by arguments read from standard input. Blank lines on the
|
---|
1905 | standard input are ignored.
|
---|
1906 |
|
---|
1907 | Instead of blank-delimited names, it is safer to use `find -print0'
|
---|
1908 | or `find -fprint0' and process the output by giving the `-0' or
|
---|
1909 | `--null' option to GNU `xargs', GNU `tar', GNU `cpio', or `perl'. The
|
---|
1910 | `locate' command also has a `-0' or `--null' option which does the same
|
---|
1911 | thing.
|
---|
1912 |
|
---|
1913 | You can use shell command substitution (backquotes) to process a list
|
---|
1914 | of arguments, like this:
|
---|
1915 |
|
---|
1916 | grep -l sprintf `find $HOME -name '*.c' -print`
|
---|
1917 |
|
---|
1918 | However, that method produces an error if the length of the `.c'
|
---|
1919 | file names exceeds the operating system's command line length limit.
|
---|
1920 | `xargs' avoids that problem by running the command as many times as
|
---|
1921 | necessary without exceeding the limit:
|
---|
1922 |
|
---|
1923 | find $HOME -name '*.c' -print | xargs grep -l sprintf
|
---|
1924 |
|
---|
1925 | However, if the command needs to have its standard input be a
|
---|
1926 | terminal (`less', for example), you have to use the shell command
|
---|
1927 | substitution method or use the `--arg-file' option of `xargs'.
|
---|
1928 |
|
---|
1929 | The `xargs' command will process all its input, building command
|
---|
1930 | lines and executing them, unless one of the commands exits with a
|
---|
1931 | status of 255 (this will cause xargs to issue an error message and
|
---|
1932 | stop) or it reads a line contains the end of file string specified with
|
---|
1933 | the `--eof' option.
|
---|
1934 |
|
---|
1935 | * Menu:
|
---|
1936 |
|
---|
1937 | * Unsafe File Name Handling::
|
---|
1938 | * Safe File Name Handling::
|
---|
1939 | * Unusual Characters in File Names::
|
---|
1940 | * Limiting Command Size::
|
---|
1941 | * Interspersing File Names::
|
---|
1942 |
|
---|
1943 |
|
---|
1944 | File: find.info, Node: Unsafe File Name Handling, Next: Safe File Name Handling, Up: Multiple Files
|
---|
1945 |
|
---|
1946 | 3.3.2.1 Unsafe File Name Handling
|
---|
1947 | .................................
|
---|
1948 |
|
---|
1949 | Because file names can contain quotes, backslashes, blank characters,
|
---|
1950 | and even newlines, it is not safe to process them using `xargs' in its
|
---|
1951 | default mode of operation. But since most files' names do not contain
|
---|
1952 | blanks, this problem occurs only infrequently. If you are only
|
---|
1953 | searching through files that you know have safe names, then you need
|
---|
1954 | not be concerned about it.
|
---|
1955 |
|
---|
1956 | In many applications, if `xargs' botches processing a file because
|
---|
1957 | its name contains special characters, some data might be lost. The
|
---|
1958 | importance of this problem depends on the importance of the data and
|
---|
1959 | whether anyone notices the loss soon enough to correct it. However,
|
---|
1960 | here is an extreme example of the problems that using blank-delimited
|
---|
1961 | names can cause. If the following command is run daily from `cron',
|
---|
1962 | then any user can remove any file on the system:
|
---|
1963 |
|
---|
1964 | find / -name '#*' -atime +7 -print | xargs rm
|
---|
1965 |
|
---|
1966 | For example, you could do something like this:
|
---|
1967 |
|
---|
1968 | eg$ echo > '#
|
---|
1969 | vmunix'
|
---|
1970 |
|
---|
1971 | and then `cron' would delete `/vmunix', if it ran `xargs' with `/' as
|
---|
1972 | its current directory.
|
---|
1973 |
|
---|
1974 | To delete other files, for example `/u/joeuser/.plan', you could do
|
---|
1975 | this:
|
---|
1976 |
|
---|
1977 | eg$ mkdir '#
|
---|
1978 | '
|
---|
1979 | eg$ cd '#
|
---|
1980 | '
|
---|
1981 | eg$ mkdir u u/joeuser u/joeuser/.plan'
|
---|
1982 | '
|
---|
1983 | eg$ echo > u/joeuser/.plan'
|
---|
1984 | /#foo'
|
---|
1985 | eg$ cd ..
|
---|
1986 | eg$ find . -name '#*' -print | xargs echo
|
---|
1987 | ./# ./# /u/joeuser/.plan /#foo
|
---|
1988 |
|
---|
1989 |
|
---|
1990 | File: find.info, Node: Safe File Name Handling, Next: Unusual Characters in File Names, Prev: Unsafe File Name Handling, Up: Multiple Files
|
---|
1991 |
|
---|
1992 | 3.3.2.2 Safe File Name Handling
|
---|
1993 | ...............................
|
---|
1994 |
|
---|
1995 | Here is how to make `find' output file names so that they can be used
|
---|
1996 | by other programs without being mangled or misinterpreted. You can
|
---|
1997 | process file names generated this way by giving the `-0' or `--null'
|
---|
1998 | option to GNU `xargs', GNU `tar', GNU `cpio', or `perl'.
|
---|
1999 |
|
---|
2000 | -- Action: -print0
|
---|
2001 | True; print the entire file name on the standard output, followed
|
---|
2002 | by a null character.
|
---|
2003 |
|
---|
2004 | -- Action: -fprint0 file
|
---|
2005 | True; like `-print0' but write to FILE like `-fprint' (*note Print
|
---|
2006 | File Name::). The output file is always created.
|
---|
2007 |
|
---|
2008 | As of findutils version 4.2.4, the `locate' program also has a
|
---|
2009 | `--null' option which does the same thing. For similarity with
|
---|
2010 | `xargs', the short form of the option `-0' can also be used.
|
---|
2011 |
|
---|
2012 | If you want to be able to handle file names safely but need to run
|
---|
2013 | commands which want to be connected to a terminal on their input, you
|
---|
2014 | can use the `--arg-file' option to `xargs' like this:
|
---|
2015 |
|
---|
2016 | find / -name xyzzy -print0 > list
|
---|
2017 | xargs --null --arg-file=list munge
|
---|
2018 |
|
---|
2019 | The example above runs the `munge' program on all the files named
|
---|
2020 | `xyzzy' that we can find, but `munge''s input will still be the
|
---|
2021 | terminal (or whatever the shell was using as standard input). If your
|
---|
2022 | shell has the "process substitution" feature `<(...)', you can do this
|
---|
2023 | in just one step:
|
---|
2024 |
|
---|
2025 | xargs --null --arg-file=<(find / -name xyzzy -print0) munge
|
---|
2026 |
|
---|
2027 |
|
---|
2028 | File: find.info, Node: Unusual Characters in File Names, Next: Limiting Command Size, Prev: Safe File Name Handling, Up: Multiple Files
|
---|
2029 |
|
---|
2030 | 3.3.2.3 Unusual Characters in File Names
|
---|
2031 | ........................................
|
---|
2032 |
|
---|
2033 | As discussed above, you often need to be careful about how the names of
|
---|
2034 | files are handled by `find' and other programs. If the output of
|
---|
2035 | `find' is not going to another program but instead is being shown on a
|
---|
2036 | terminal, this can still be a problem. For example, some character
|
---|
2037 | sequences can reprogram the function keys on some terminals. *Note
|
---|
2038 | Security Considerations::, for a discussion of other security problems
|
---|
2039 | relating to `find'.
|
---|
2040 |
|
---|
2041 | Unusual characters are handled differently by various actions, as
|
---|
2042 | described below.
|
---|
2043 |
|
---|
2044 | `-print0'
|
---|
2045 | `-fprint0'
|
---|
2046 | Always print the exact file name, unchanged, even if the output is
|
---|
2047 | going to a terminal.
|
---|
2048 |
|
---|
2049 | `-ok'
|
---|
2050 | `-okdir'
|
---|
2051 | Always print the exact file name, unchanged. This will probably
|
---|
2052 | change in a future release.
|
---|
2053 |
|
---|
2054 | `-ls'
|
---|
2055 | `-fls'
|
---|
2056 | Unusual characters are always escaped. White space, backslash, and
|
---|
2057 | double quote characters are printed using C-style escaping (for
|
---|
2058 | example `\f', `\"'). Other unusual characters are printed using
|
---|
2059 | an octal escape. Other printable characters (for `-ls' and `-fls'
|
---|
2060 | these are the characters between octal 041 and 0176) are printed
|
---|
2061 | as-is.
|
---|
2062 |
|
---|
2063 | `-printf'
|
---|
2064 | `-fprintf'
|
---|
2065 | If the output is not going to a terminal, it is printed as-is.
|
---|
2066 | Otherwise, the result depends on which directive is in use:
|
---|
2067 |
|
---|
2068 | %D, %F, %H, %Y, %y
|
---|
2069 | These expand to values which are not under control of files'
|
---|
2070 | owners, and so are printed as-is.
|
---|
2071 |
|
---|
2072 | %a, %b, %c, %d, %g, %G, %i, %k, %m, %M, %n, %s, %t, %u, %U
|
---|
2073 | These have values which are under the control of files'
|
---|
2074 | owners but which cannot be used to send arbitrary data to the
|
---|
2075 | terminal, and so these are printed as-is.
|
---|
2076 |
|
---|
2077 | %f, %h, %l, %p, %P
|
---|
2078 | The output of these directives is quoted if the output is
|
---|
2079 | going to a terminal.
|
---|
2080 |
|
---|
2081 | This quoting is performed in the same way as for GNU `ls'.
|
---|
2082 | This is not the same quoting mechanism as the one used for
|
---|
2083 | `-ls' and `fls'. If you are able to decide what format to
|
---|
2084 | use for the output of `find' then it is normally better to
|
---|
2085 | use `\0' as a terminator than to use newline, as file names
|
---|
2086 | can contain white space and newline characters.
|
---|
2087 |
|
---|
2088 | `-print'
|
---|
2089 | `-fprint'
|
---|
2090 | Quoting is handled in the same way as for the `%p' directive of
|
---|
2091 | `-printf' and `-fprintf'. If you are using `find' in a script or
|
---|
2092 | in a situation where the matched files might have arbitrary names,
|
---|
2093 | you should consider using `-print0' instead of `-print'.
|
---|
2094 |
|
---|
2095 | The `locate' program quotes and escapes unusual characters in file
|
---|
2096 | names in the same way as `find''s `-print' action.
|
---|
2097 |
|
---|
2098 | The behaviours described above may change soon, as the treatment of
|
---|
2099 | unprintable characters is harmonised for `-ls', `-fls', `-print',
|
---|
2100 | `-fprint', `-printf' and `-fprintf'.
|
---|
2101 |
|
---|
2102 |
|
---|
2103 | File: find.info, Node: Limiting Command Size, Next: Interspersing File Names, Prev: Unusual Characters in File Names, Up: Multiple Files
|
---|
2104 |
|
---|
2105 | 3.3.2.4 Limiting Command Size
|
---|
2106 | .............................
|
---|
2107 |
|
---|
2108 | `xargs' gives you control over how many arguments it passes to the
|
---|
2109 | command each time it executes it. By default, it uses up to `ARG_MAX'
|
---|
2110 | - 2k, or 128k, whichever is smaller, characters per command. It uses
|
---|
2111 | as many lines and arguments as fit within that limit. The following
|
---|
2112 | options modify those values.
|
---|
2113 |
|
---|
2114 | `--no-run-if-empty'
|
---|
2115 | `-r'
|
---|
2116 | If the standard input does not contain any nonblanks, do not run
|
---|
2117 | the command. By default, the command is run once even if there is
|
---|
2118 | no input. This option is a GNU extension.
|
---|
2119 |
|
---|
2120 | `--max-lines[=MAX-LINES]'
|
---|
2121 | `-L MAX-LINES'
|
---|
2122 | `-l[MAX-LINES]'
|
---|
2123 | Use at most MAX-LINES nonblank input lines per command line;
|
---|
2124 | MAX-LINES defaults to 1 if omitted; omitting the argument is not
|
---|
2125 | allowed in the case of the `-L' option. Trailing blanks cause an
|
---|
2126 | input line to be logically continued on the next input line, for
|
---|
2127 | the purpose of counting the lines. Implies `-x'. The preferred
|
---|
2128 | name for this option is `-L' as this is specified by POSIX.
|
---|
2129 |
|
---|
2130 | `--max-args=MAX-ARGS'
|
---|
2131 | `-n MAX-ARGS'
|
---|
2132 | Use at most MAX-ARGS arguments per command line. Fewer than
|
---|
2133 | MAX-ARGS arguments will be used if the size (see the `-s' option)
|
---|
2134 | is exceeded, unless the `-x' option is given, in which case
|
---|
2135 | `xargs' will exit.
|
---|
2136 |
|
---|
2137 | `--max-chars=MAX-CHARS'
|
---|
2138 | `-s MAX-CHARS'
|
---|
2139 | Use at most MAX-CHARS characters per command line, including the
|
---|
2140 | command initial arguments and the terminating nulls at the ends of
|
---|
2141 | the argument strings. If you specify a value for this option
|
---|
2142 | which is too large or small, a warning message is printed and the
|
---|
2143 | appropriate upper or lower limit is used instead. You can use
|
---|
2144 | `--show-limits' option to understand the command-line limits
|
---|
2145 | applying to `xargs' and how this is affected by any other options.
|
---|
2146 |
|
---|
2147 | `--max-procs=MAX-PROCS'
|
---|
2148 | `-P MAX-PROCS'
|
---|
2149 | Run up to MAX-PROCS processes at a time; the default is 1. If
|
---|
2150 | MAX-PROCS is 0, `xargs' will run as many processes as possible at
|
---|
2151 | a time. Use the `-n', `-s', or `-L' option with `-P'; otherwise
|
---|
2152 | chances are that the command will be run only once.
|
---|
2153 |
|
---|
2154 |
|
---|
2155 | File: find.info, Node: Interspersing File Names, Prev: Limiting Command Size, Up: Multiple Files
|
---|
2156 |
|
---|
2157 | 3.3.2.5 Interspersing File Names
|
---|
2158 | ................................
|
---|
2159 |
|
---|
2160 | `xargs' can insert the name of the file it is processing between
|
---|
2161 | arguments you give for the command. Unless you also give options to
|
---|
2162 | limit the command size (*note Limiting Command Size::), this mode of
|
---|
2163 | operation is equivalent to `find -exec' (*note Single File::).
|
---|
2164 |
|
---|
2165 | `--replace[=REPLACE-STR]'
|
---|
2166 | `-I REPLACE-STR'
|
---|
2167 | `-i REPLACE-STR'
|
---|
2168 | Replace occurrences of REPLACE-STR in the initial arguments with
|
---|
2169 | names read from the input. Also, unquoted blanks do not terminate
|
---|
2170 | arguments; instead, the input is split at newlines only. For the
|
---|
2171 | `-i' option, if REPLACE-STR is omitted for `--replace' or `-i', it
|
---|
2172 | defaults to `{}' (like for `find -exec'). Implies `-x' and `-l
|
---|
2173 | 1'. `-i' is deprecated in favour of `-I'. As an example, to sort
|
---|
2174 | each file in the `bills' directory, leaving the output in that
|
---|
2175 | file name with `.sorted' appended, you could do:
|
---|
2176 |
|
---|
2177 | find bills -type f | xargs -I XX sort -o XX.sorted XX
|
---|
2178 |
|
---|
2179 | The equivalent command using `find -execdir' is:
|
---|
2180 |
|
---|
2181 | find bills -type f -execdir sort -o '{}.sorted' '{}' ';'
|
---|
2182 |
|
---|
2183 | When you use the `-I' option, each line read from the input is
|
---|
2184 | buffered internally. This means that there is an upper limit on the
|
---|
2185 | length of input line that xargs will accept when used with the `-I'
|
---|
2186 | option. To work around this limitation, you can use the `-s' option to
|
---|
2187 | increase the amount of buffer space that xargs uses, and you can also
|
---|
2188 | use an extra invocation of xargs to ensure that very long lines do not
|
---|
2189 | occur. For example:
|
---|
2190 |
|
---|
2191 | somecommand | xargs -s 50000 echo | xargs -I '{}' -s 100000 rm '{}'
|
---|
2192 |
|
---|
2193 | Here, the first invocation of `xargs' has no input line length limit
|
---|
2194 | because it doesn't use the `-I' option. The second invocation of
|
---|
2195 | `xargs' does have such a limit, but we have ensured that the it never
|
---|
2196 | encounters a line which is longer than it can handle.
|
---|
2197 |
|
---|
2198 | This is not an ideal solution. Instead, the `-I' option should not
|
---|
2199 | impose a line length limit (apart from any limit imposed by the
|
---|
2200 | operating system) and so one might consider this limitation to be a
|
---|
2201 | bug. A better solution would be to allow `xargs -I' to automatically
|
---|
2202 | move to a larger value for the `-s' option when this is needed.
|
---|
2203 |
|
---|
2204 | This sort of problem doesn't occur with the output of `find' because
|
---|
2205 | it emits just one filename per line.
|
---|
2206 |
|
---|
2207 |
|
---|
2208 | File: find.info, Node: Querying, Prev: Multiple Files, Up: Run Commands
|
---|
2209 |
|
---|
2210 | 3.3.3 Querying
|
---|
2211 | --------------
|
---|
2212 |
|
---|
2213 | To ask the user whether to execute a command on a single file, you can
|
---|
2214 | use the `find' primary `-okdir' instead of `-execdir', and the `find'
|
---|
2215 | primary `-ok' instead of `-exec':
|
---|
2216 |
|
---|
2217 | -- Action: -okdir command ;
|
---|
2218 | Like `-execdir' (*note Single File::), but ask the user first (on
|
---|
2219 | the standard input); if the response does not start with `y' or
|
---|
2220 | `Y', do not run the command, and return false. If the command is
|
---|
2221 | run, its standard input is redirected from `/dev/null'.
|
---|
2222 |
|
---|
2223 | -- Action: -ok command ;
|
---|
2224 | This insecure variant of the `-okdir' action is specified by
|
---|
2225 | POSIX. The main difference is that the command is executed in the
|
---|
2226 | directory from which `find' was invoked, meaning that `{}' is
|
---|
2227 | expanded to a relative path starting with the name of one of the
|
---|
2228 | starting directories, rather than just the basename of the matched
|
---|
2229 | file. If the command is run, its standard input is redirected from
|
---|
2230 | `/dev/null'.
|
---|
2231 |
|
---|
2232 | When processing multiple files with a single command, to query the
|
---|
2233 | user you give `xargs' the following option. When using this option,
|
---|
2234 | you might find it useful to control the number of files processed per
|
---|
2235 | invocation of the command (*note Limiting Command Size::).
|
---|
2236 |
|
---|
2237 | `--interactive'
|
---|
2238 | `-p'
|
---|
2239 | Prompt the user about whether to run each command line and read a
|
---|
2240 | line from the terminal. Only run the command line if the response
|
---|
2241 | starts with `y' or `Y'. Implies `-t'.
|
---|
2242 |
|
---|
2243 |
|
---|
2244 | File: find.info, Node: Delete Files, Next: Adding Tests, Prev: Run Commands, Up: Actions
|
---|
2245 |
|
---|
2246 | 3.4 Delete Files
|
---|
2247 | ================
|
---|
2248 |
|
---|
2249 | -- Action: -delete
|
---|
2250 | Delete files or directories; true if removal succeeded. If the
|
---|
2251 | removal failed, an error message is issued.
|
---|
2252 |
|
---|
2253 | The use of the `-delete' action on the command line automatically
|
---|
2254 | turns on the `-depth' option (*note find Expressions::).
|
---|
2255 |
|
---|
2256 |
|
---|
2257 | File: find.info, Node: Adding Tests, Prev: Delete Files, Up: Actions
|
---|
2258 |
|
---|
2259 | 3.5 Adding Tests
|
---|
2260 | ================
|
---|
2261 |
|
---|
2262 | You can test for file attributes that none of the `find' builtin tests
|
---|
2263 | check. To do this, use `xargs' to run a program that filters a list of
|
---|
2264 | files printed by `find'. If possible, use `find' builtin tests to pare
|
---|
2265 | down the list, so the program run by `xargs' has less work to do. The
|
---|
2266 | tests builtin to `find' will likely run faster than tests that other
|
---|
2267 | programs perform.
|
---|
2268 |
|
---|
2269 | For reasons of efficiency it is often useful to limit the number of
|
---|
2270 | times an external program has to be run. For this reason, it is often
|
---|
2271 | a good idea to implement "extended" tests by using `xargs'.
|
---|
2272 |
|
---|
2273 | For example, here is a way to print the names of all of the
|
---|
2274 | unstripped binaries in the `/usr/local' directory tree. Builtin tests
|
---|
2275 | avoid running `file' on files that are not regular files or are not
|
---|
2276 | executable.
|
---|
2277 |
|
---|
2278 | find /usr/local -type f -perm /a=x | xargs file |
|
---|
2279 | grep 'not stripped' | cut -d: -f1
|
---|
2280 |
|
---|
2281 | The `cut' program removes everything after the file name from the
|
---|
2282 | output of `file'.
|
---|
2283 |
|
---|
2284 | However, using `xargs' can present important security problems
|
---|
2285 | (*note Security Considerations::). These can be avoided by using
|
---|
2286 | `-execdir'. The `-execdir' action is also a useful way of putting your
|
---|
2287 | own test in the middle of a set of other tests or actions for `find'
|
---|
2288 | (for example, you might want to use `-prune').
|
---|
2289 |
|
---|
2290 | To place a special test somewhere in the middle of a `find'
|
---|
2291 | expression, you can use `-execdir' (or, less securely, `-exec') to run
|
---|
2292 | a program that performs the test. Because `-execdir' evaluates to the
|
---|
2293 | exit status of the executed program, you can use a program (which can
|
---|
2294 | be a shell script) that tests for a special attribute and make it exit
|
---|
2295 | with a true (zero) or false (non-zero) status. It is a good idea to
|
---|
2296 | place such a special test _after_ the builtin tests, because it starts
|
---|
2297 | a new process which could be avoided if a builtin test evaluates to
|
---|
2298 | false.
|
---|
2299 |
|
---|
2300 | Here is a shell script called `unstripped' that checks whether its
|
---|
2301 | argument is an unstripped binary file:
|
---|
2302 |
|
---|
2303 | #! /bin/sh
|
---|
2304 | file "$1" | grep -q "not stripped"
|
---|
2305 |
|
---|
2306 | This script relies on the shell exiting with the status of the last
|
---|
2307 | command in the pipeline, in this case `grep'. The `grep' command exits
|
---|
2308 | with a true status if it found any matches, false if not. Here is an
|
---|
2309 | example of using the script (assuming it is in your search path). It
|
---|
2310 | lists the stripped executables (and shell scripts) in the file `sbins'
|
---|
2311 | and the unstripped ones in `ubins'.
|
---|
2312 |
|
---|
2313 | find /usr/local -type f -perm /a=x \
|
---|
2314 | \( -execdir unstripped '{}' \; -fprint ubins -o -fprint sbins \)
|
---|
2315 |
|
---|
2316 |
|
---|
2317 | File: find.info, Node: Databases, Next: File Permissions, Prev: Actions, Up: Top
|
---|
2318 |
|
---|
2319 | 4 File Name Databases
|
---|
2320 | *********************
|
---|
2321 |
|
---|
2322 | The file name databases used by `locate' contain lists of files that
|
---|
2323 | were in particular directory trees when the databases were last
|
---|
2324 | updated. The file name of the default database is determined when
|
---|
2325 | `locate' and `updatedb' are configured and installed. The frequency
|
---|
2326 | with which the databases are updated and the directories for which they
|
---|
2327 | contain entries depend on how often `updatedb' is run, and with which
|
---|
2328 | arguments.
|
---|
2329 |
|
---|
2330 | You can obtain some statistics about the databases by using `locate
|
---|
2331 | --statistics'.
|
---|
2332 |
|
---|
2333 | * Menu:
|
---|
2334 |
|
---|
2335 | * Database Locations::
|
---|
2336 | * Database Formats::
|
---|
2337 | * Newline Handling::
|
---|
2338 |
|
---|
2339 |
|
---|
2340 | File: find.info, Node: Database Locations, Next: Database Formats, Up: Databases
|
---|
2341 |
|
---|
2342 | 4.1 Database Locations
|
---|
2343 | ======================
|
---|
2344 |
|
---|
2345 | There can be multiple file name databases. Users can select which
|
---|
2346 | databases `locate' searches using the `LOCATE_PATH' environment
|
---|
2347 | variable or a command line option. The system administrator can choose
|
---|
2348 | the file name of the default database, the frequency with which the
|
---|
2349 | databases are updated, and the directories for which they contain
|
---|
2350 | entries. File name databases are updated by running the `updatedb'
|
---|
2351 | program, typically nightly.
|
---|
2352 |
|
---|
2353 | In networked environments, it often makes sense to build a database
|
---|
2354 | at the root of each filesystem, containing the entries for that
|
---|
2355 | filesystem. `updatedb' is then run for each filesystem on the
|
---|
2356 | fileserver where that filesystem is on a local disk, to prevent
|
---|
2357 | thrashing the network.
|
---|
2358 |
|
---|
2359 | *Note Invoking updatedb::, for the description of the options to
|
---|
2360 | `updatedb', which specify which directories would each database contain
|
---|
2361 | entries for.
|
---|
2362 |
|
---|
2363 |
|
---|
2364 | File: find.info, Node: Database Formats, Next: Newline Handling, Prev: Database Locations, Up: Databases
|
---|
2365 |
|
---|
2366 | 4.2 Database Formats
|
---|
2367 | ====================
|
---|
2368 |
|
---|
2369 | The file name databases contain lists of files that were in particular
|
---|
2370 | directory trees when the databases were last updated. The file name
|
---|
2371 | database format changed starting with GNU `locate' version 4.0 to allow
|
---|
2372 | machines with different byte orderings to share the databases. The new
|
---|
2373 | GNU `locate' can read both the old and new database formats. However,
|
---|
2374 | old versions of `locate' and `find' produce incorrect results if given
|
---|
2375 | a new-format database.
|
---|
2376 |
|
---|
2377 | Support for the old database format will eventually be discontinued,
|
---|
2378 | first in `updatedb' and later in `xargs'.
|
---|
2379 |
|
---|
2380 | If you run `locate --statistics', the resulting summary indicates
|
---|
2381 | the type of each `locate' database.
|
---|
2382 |
|
---|
2383 | * Menu:
|
---|
2384 |
|
---|
2385 | * New Database Format::
|
---|
2386 | * Sample Database::
|
---|
2387 | * Old Database Format::
|
---|
2388 |
|
---|
2389 |
|
---|
2390 | File: find.info, Node: New Database Format, Next: Sample Database, Up: Database Formats
|
---|
2391 |
|
---|
2392 | 4.2.1 New Database Format
|
---|
2393 | -------------------------
|
---|
2394 |
|
---|
2395 | `updatedb' runs a program called `frcode' to "front-compress" the list
|
---|
2396 | of file names, which reduces the database size by a factor of 4 to 5.
|
---|
2397 | Front-compression (also known as incremental encoding) works as follows.
|
---|
2398 |
|
---|
2399 | The database entries are a sorted list (case-insensitively, for
|
---|
2400 | users' convenience). Since the list is sorted, each entry is likely to
|
---|
2401 | share a prefix (initial string) with the previous entry. Each database
|
---|
2402 | entry begins with an offset-differential count byte, which is the
|
---|
2403 | additional number of characters of prefix of the preceding entry to use
|
---|
2404 | beyond the number that the preceding entry is using of its predecessor.
|
---|
2405 | (The counts can be negative.) Following the count is a
|
---|
2406 | null-terminated ASCII remainder--the part of the name that follows the
|
---|
2407 | shared prefix.
|
---|
2408 |
|
---|
2409 | If the offset-differential count is larger than can be stored in a
|
---|
2410 | byte (+/-127), the byte has the value 0x80 and the count follows in a
|
---|
2411 | 2-byte word, with the high byte first (network byte order).
|
---|
2412 |
|
---|
2413 | Every database begins with a dummy entry for a file called
|
---|
2414 | `LOCATE02', which `locate' checks for to ensure that the database file
|
---|
2415 | has the correct format; it ignores the entry in doing the search.
|
---|
2416 |
|
---|
2417 | Databases cannot be concatenated together, even if the first (dummy)
|
---|
2418 | entry is trimmed from all but the first database. This is because the
|
---|
2419 | offset-differential count in the first entry of the second and
|
---|
2420 | following databases will be wrong.
|
---|
2421 |
|
---|
2422 | In the output of `locate --statistics', the new database format is
|
---|
2423 | referred to as `LOCATE02'.
|
---|
2424 |
|
---|
2425 |
|
---|
2426 | File: find.info, Node: Sample Database, Next: Old Database Format, Prev: New Database Format, Up: Database Formats
|
---|
2427 |
|
---|
2428 | 4.2.2 Sample Database
|
---|
2429 | ---------------------
|
---|
2430 |
|
---|
2431 | Sample input to `frcode':
|
---|
2432 |
|
---|
2433 | /usr/src
|
---|
2434 | /usr/src/cmd/aardvark.c
|
---|
2435 | /usr/src/cmd/armadillo.c
|
---|
2436 | /usr/tmp/zoo
|
---|
2437 |
|
---|
2438 | Length of the longest prefix of the preceding entry to share:
|
---|
2439 |
|
---|
2440 | 0 /usr/src
|
---|
2441 | 8 /cmd/aardvark.c
|
---|
2442 | 14 rmadillo.c
|
---|
2443 | 5 tmp/zoo
|
---|
2444 |
|
---|
2445 | Output from `frcode', with trailing nulls changed to newlines and
|
---|
2446 | count bytes made printable:
|
---|
2447 |
|
---|
2448 | 0 LOCATE02
|
---|
2449 | 0 /usr/src
|
---|
2450 | 8 /cmd/aardvark.c
|
---|
2451 | 6 rmadillo.c
|
---|
2452 | -9 tmp/zoo
|
---|
2453 |
|
---|
2454 | (6 = 14 - 8, and -9 = 5 - 14)
|
---|
2455 |
|
---|
2456 |
|
---|
2457 | File: find.info, Node: Old Database Format, Prev: Sample Database, Up: Database Formats
|
---|
2458 |
|
---|
2459 | 4.2.3 Old Database Format
|
---|
2460 | -------------------------
|
---|
2461 |
|
---|
2462 | The old database format is used by Unix `locate' and `find' programs
|
---|
2463 | and earlier releases of the GNU ones. `updatedb' produces this format
|
---|
2464 | if given the `--old-format' option.
|
---|
2465 |
|
---|
2466 | `updatedb' runs programs called `bigram' and `code' to produce
|
---|
2467 | old-format databases. The old format differs from the new one in the
|
---|
2468 | following ways. Instead of each entry starting with an
|
---|
2469 | offset-differential count byte and ending with a null, byte values from
|
---|
2470 | 0 through 28 indicate offset-differential counts from -14 through 14.
|
---|
2471 | The byte value indicating that a long offset-differential count follows
|
---|
2472 | is 0x1e (30), not 0x80. The long counts are stored in host byte order,
|
---|
2473 | which is not necessarily network byte order, and host integer word
|
---|
2474 | size, which is usually 4 bytes. They also represent a count 14 less
|
---|
2475 | than their value. The database lines have no termination byte; the
|
---|
2476 | start of the next line is indicated by its first byte having a value <=
|
---|
2477 | 30.
|
---|
2478 |
|
---|
2479 | In addition, instead of starting with a dummy entry, the old database
|
---|
2480 | format starts with a 256 byte table containing the 128 most common
|
---|
2481 | bigrams in the file list. A bigram is a pair of adjacent bytes. Bytes
|
---|
2482 | in the database that have the high bit set are indexes (with the high
|
---|
2483 | bit cleared) into the bigram table. The bigram and offset-differential
|
---|
2484 | count coding makes these databases 20-25% smaller than the new format,
|
---|
2485 | but makes them not 8-bit clean. Any byte in a file name that is in the
|
---|
2486 | ranges used for the special codes is replaced in the database by a
|
---|
2487 | question mark, which not coincidentally is the shell wildcard to match
|
---|
2488 | a single character.
|
---|
2489 |
|
---|
2490 | The old format therefore cannot faithfully store entries with
|
---|
2491 | non-ASCII characters. It therefore should not be used in
|
---|
2492 | internationalised environments.
|
---|
2493 |
|
---|
2494 | The output of `locate --statistics' will give an incorrect count of
|
---|
2495 | the number of file names containing newlines or high-bit characters for
|
---|
2496 | old-format databases.
|
---|
2497 |
|
---|
2498 |
|
---|
2499 | File: find.info, Node: Newline Handling, Prev: Database Formats, Up: Databases
|
---|
2500 |
|
---|
2501 | 4.3 Newline Handling
|
---|
2502 | ====================
|
---|
2503 |
|
---|
2504 | Within the database, file names are terminated with a null character.
|
---|
2505 | This is the case for both the old and the new format.
|
---|
2506 |
|
---|
2507 | When the new database format is being used, the compression technique
|
---|
2508 | used to generate the database though relies on the ability to sort the
|
---|
2509 | list of files before they are presented to `frcode'.
|
---|
2510 |
|
---|
2511 | If the system's sort command allows its input list of files to be
|
---|
2512 | separated with null characters via the `-z' option, this option is used
|
---|
2513 | and therefore `updatedb' and `locate' will both correctly handle file
|
---|
2514 | names containing newlines. If the `sort' command lacks support for
|
---|
2515 | this, the list of files is delimited with the newline character,
|
---|
2516 | meaning that parts of file names containing newlines will be
|
---|
2517 | incorrectly sorted. This can result in both incorrect matches and
|
---|
2518 | incorrect failures to match.
|
---|
2519 |
|
---|
2520 | On the other hand, if you are using the old database format, file
|
---|
2521 | names with embedded newlines are not correctly handled. There is no
|
---|
2522 | technical limitation which enforces this, it's just that the `bigram'
|
---|
2523 | program has not been updated to support lists of file names separated
|
---|
2524 | by nulls.
|
---|
2525 |
|
---|
2526 | So, if you are using the new database format (this is the default)
|
---|
2527 | and your system uses GNU `sort', newlines will be correctly handled at
|
---|
2528 | all times. Otherwise, newlines may not be correctly handled.
|
---|
2529 |
|
---|
2530 |
|
---|
2531 | File: find.info, Node: File Permissions, Next: Reference, Prev: Databases, Up: Top
|
---|
2532 |
|
---|
2533 | 5 File Permissions
|
---|
2534 | ******************
|
---|
2535 |
|
---|
2536 | Each file has a set of "file mode bits" that control the kinds of
|
---|
2537 | access that users have to that file. They can be represented either in
|
---|
2538 | symbolic form or as an octal number.
|
---|
2539 |
|
---|
2540 | * Menu:
|
---|
2541 |
|
---|
2542 | * Mode Structure:: Structure of file mode bits.
|
---|
2543 | * Symbolic Modes:: Mnemonic representation of file mode bits.
|
---|
2544 | * Numeric Modes:: File mode bits as octal numbers.
|
---|
2545 | * Directory Setuid and Setgid:: Set-user-ID and set-group-ID on directories.
|
---|
2546 |
|
---|
2547 |
|
---|
2548 | File: find.info, Node: Mode Structure, Next: Symbolic Modes, Up: File Permissions
|
---|
2549 |
|
---|
2550 | 5.1 Structure of File Mode Bits
|
---|
2551 | ===============================
|
---|
2552 |
|
---|
2553 | The file mode bits have two parts: the "file permission bits", which
|
---|
2554 | control ordinary access to the file, and "special mode bits", which
|
---|
2555 | affect only some files.
|
---|
2556 |
|
---|
2557 | There are three kinds of permissions that a user can have for a file:
|
---|
2558 |
|
---|
2559 | 1. permission to read the file. For directories, this means
|
---|
2560 | permission to list the contents of the directory.
|
---|
2561 |
|
---|
2562 | 2. permission to write to (change) the file. For directories, this
|
---|
2563 | means permission to create and remove files in the directory.
|
---|
2564 |
|
---|
2565 | 3. permission to execute the file (run it as a program). For
|
---|
2566 | directories, this means permission to access files in the
|
---|
2567 | directory.
|
---|
2568 |
|
---|
2569 | There are three categories of users who may have different
|
---|
2570 | permissions to perform any of the above operations on a file:
|
---|
2571 |
|
---|
2572 | 1. the file's owner;
|
---|
2573 |
|
---|
2574 | 2. other users who are in the file's group;
|
---|
2575 |
|
---|
2576 | 3. everyone else.
|
---|
2577 |
|
---|
2578 | Files are given an owner and group when they are created. Usually
|
---|
2579 | the owner is the current user and the group is the group of the
|
---|
2580 | directory the file is in, but this varies with the operating system, the
|
---|
2581 | file system the file is created on, and the way the file is created.
|
---|
2582 | You can change the owner and group of a file by using the `chown' and
|
---|
2583 | `chgrp' commands.
|
---|
2584 |
|
---|
2585 | In addition to the three sets of three permissions listed above, the
|
---|
2586 | file mode bits have three special components, which affect only
|
---|
2587 | executable files (programs) and, on most systems, directories:
|
---|
2588 |
|
---|
2589 | 1. Set the process's effective user ID to that of the file upon
|
---|
2590 | execution (called the "set-user-ID bit", or sometimes the "setgid
|
---|
2591 | bit"). For directories on a few systems, give files created in
|
---|
2592 | the directory the same owner as the directory, no matter who
|
---|
2593 | creates them, and set the set-user-ID bit of newly-created
|
---|
2594 | subdirectories.
|
---|
2595 |
|
---|
2596 | 2. Set the process's effective group ID to that of the file upon
|
---|
2597 | execution (called the "set-group-ID bit", or sometimes the "setgid
|
---|
2598 | bit"). For directories on most systems, give files created in the
|
---|
2599 | directory the same group as the directory, no matter what group
|
---|
2600 | the user who creates them is in, and set the set-group-ID bit of
|
---|
2601 | newly-created subdirectories.
|
---|
2602 |
|
---|
2603 | 3. Prevent unprivileged users from removing or renaming a file in a
|
---|
2604 | directory unless they own the file or the directory; this is
|
---|
2605 | called the "restricted deletion flag" for the directory, and is
|
---|
2606 | commonly found on world-writable directories like `/tmp'.
|
---|
2607 |
|
---|
2608 | For regular files on some older systems, save the program's text
|
---|
2609 | image on the swap device so it will load more quickly when run;
|
---|
2610 | this is called the "sticky bit".
|
---|
2611 |
|
---|
2612 | In addition to the file mode bits listed above, there may be file
|
---|
2613 | attributes specific to the file system, e.g., access control lists
|
---|
2614 | (ACLs), whether a file is compressed, whether a file can be modified
|
---|
2615 | (immutability), and whether a file can be dumped. These are usually
|
---|
2616 | set using programs specific to the file system. For example:
|
---|
2617 |
|
---|
2618 | ext2
|
---|
2619 | On GNU and GNU/Linux the file attributes specific to the ext2 file
|
---|
2620 | system are set using `chattr'.
|
---|
2621 |
|
---|
2622 | FFS
|
---|
2623 | On FreeBSD the file flags specific to the FFS file system are set
|
---|
2624 | using `chflags'.
|
---|
2625 |
|
---|
2626 | Even if a file's mode bits allow an operation on that file, that
|
---|
2627 | operation may still fail, because:
|
---|
2628 |
|
---|
2629 | * the file-system-specific attributes or flags do not permit it; or
|
---|
2630 |
|
---|
2631 | * the file system is mounted as read-only.
|
---|
2632 |
|
---|
2633 | For example, if the immutable attribute is set on a file, it cannot
|
---|
2634 | be modified, regardless of the fact that you may have just run `chmod
|
---|
2635 | a+w FILE'.
|
---|
2636 |
|
---|
2637 |
|
---|
2638 | File: find.info, Node: Symbolic Modes, Next: Numeric Modes, Prev: Mode Structure, Up: File Permissions
|
---|
2639 |
|
---|
2640 | 5.2 Symbolic Modes
|
---|
2641 | ==================
|
---|
2642 |
|
---|
2643 | "Symbolic modes" represent changes to files' mode bits as operations on
|
---|
2644 | single-character symbols. They allow you to modify either all or
|
---|
2645 | selected parts of files' mode bits, optionally based on their previous
|
---|
2646 | values, and perhaps on the current `umask' as well (*note Umask and
|
---|
2647 | Protection::).
|
---|
2648 |
|
---|
2649 | The format of symbolic modes is:
|
---|
2650 |
|
---|
2651 | [ugoa...][+-=]PERMS...[,...]
|
---|
2652 |
|
---|
2653 | where PERMS is either zero or more letters from the set `rwxXst', or a
|
---|
2654 | single letter from the set `ugo'.
|
---|
2655 |
|
---|
2656 | The following sections describe the operators and other details of
|
---|
2657 | symbolic modes.
|
---|
2658 |
|
---|
2659 | * Menu:
|
---|
2660 |
|
---|
2661 | * Setting Permissions:: Basic operations on permissions.
|
---|
2662 | * Copying Permissions:: Copying existing permissions.
|
---|
2663 | * Changing Special Mode Bits:: Special mode bits.
|
---|
2664 | * Conditional Executability:: Conditionally affecting executability.
|
---|
2665 | * Multiple Changes:: Making multiple changes.
|
---|
2666 | * Umask and Protection:: The effect of the umask.
|
---|
2667 |
|
---|
2668 |
|
---|
2669 | File: find.info, Node: Setting Permissions, Next: Copying Permissions, Up: Symbolic Modes
|
---|
2670 |
|
---|
2671 | 5.2.1 Setting Permissions
|
---|
2672 | -------------------------
|
---|
2673 |
|
---|
2674 | The basic symbolic operations on a file's permissions are adding,
|
---|
2675 | removing, and setting the permission that certain users have to read,
|
---|
2676 | write, and execute or search the file. These operations have the
|
---|
2677 | following format:
|
---|
2678 |
|
---|
2679 | USERS OPERATION PERMISSIONS
|
---|
2680 |
|
---|
2681 | The spaces between the three parts above are shown for readability only;
|
---|
2682 | symbolic modes cannot contain spaces.
|
---|
2683 |
|
---|
2684 | The USERS part tells which users' access to the file is changed. It
|
---|
2685 | consists of one or more of the following letters (or it can be empty;
|
---|
2686 | *note Umask and Protection::, for a description of what happens then).
|
---|
2687 | When more than one of these letters is given, the order that they are
|
---|
2688 | in does not matter.
|
---|
2689 |
|
---|
2690 | `u'
|
---|
2691 | the user who owns the file;
|
---|
2692 |
|
---|
2693 | `g'
|
---|
2694 | other users who are in the file's group;
|
---|
2695 |
|
---|
2696 | `o'
|
---|
2697 | all other users;
|
---|
2698 |
|
---|
2699 | `a'
|
---|
2700 | all users; the same as `ugo'.
|
---|
2701 |
|
---|
2702 | The OPERATION part tells how to change the affected users' access to
|
---|
2703 | the file, and is one of the following symbols:
|
---|
2704 |
|
---|
2705 | `+'
|
---|
2706 | to add the PERMISSIONS to whatever permissions the USERS already
|
---|
2707 | have for the file;
|
---|
2708 |
|
---|
2709 | `-'
|
---|
2710 | to remove the PERMISSIONS from whatever permissions the USERS
|
---|
2711 | already have for the file;
|
---|
2712 |
|
---|
2713 | `='
|
---|
2714 | to make the PERMISSIONS the only permissions that the USERS have
|
---|
2715 | for the file.
|
---|
2716 |
|
---|
2717 | The PERMISSIONS part tells what kind of access to the file should be
|
---|
2718 | changed; it is normally zero or more of the following letters. As with
|
---|
2719 | the USERS part, the order does not matter when more than one letter is
|
---|
2720 | given. Omitting the PERMISSIONS part is useful only with the `='
|
---|
2721 | operation, where it gives the specified USERS no access at all to the
|
---|
2722 | file.
|
---|
2723 |
|
---|
2724 | `r'
|
---|
2725 | the permission the USERS have to read the file;
|
---|
2726 |
|
---|
2727 | `w'
|
---|
2728 | the permission the USERS have to write to the file;
|
---|
2729 |
|
---|
2730 | `x'
|
---|
2731 | the permission the USERS have to execute the file, or search it if
|
---|
2732 | it is a directory.
|
---|
2733 |
|
---|
2734 | For example, to give everyone permission to read and write a regular
|
---|
2735 | file, but not to execute it, use:
|
---|
2736 |
|
---|
2737 | a=rw
|
---|
2738 |
|
---|
2739 | To remove write permission for all users other than the file's
|
---|
2740 | owner, use:
|
---|
2741 |
|
---|
2742 | go-w
|
---|
2743 |
|
---|
2744 | The above command does not affect the access that the owner of the file
|
---|
2745 | has to it, nor does it affect whether other users can read or execute
|
---|
2746 | the file.
|
---|
2747 |
|
---|
2748 | To give everyone except a file's owner no permission to do anything
|
---|
2749 | with that file, use the mode below. Other users could still remove the
|
---|
2750 | file, if they have write permission on the directory it is in.
|
---|
2751 |
|
---|
2752 | go=
|
---|
2753 |
|
---|
2754 | Another way to specify the same thing is:
|
---|
2755 |
|
---|
2756 | og-rwx
|
---|
2757 |
|
---|
2758 |
|
---|
2759 | File: find.info, Node: Copying Permissions, Next: Changing Special Mode Bits, Prev: Setting Permissions, Up: Symbolic Modes
|
---|
2760 |
|
---|
2761 | 5.2.2 Copying Existing Permissions
|
---|
2762 | ----------------------------------
|
---|
2763 |
|
---|
2764 | You can base a file's permissions on its existing permissions. To do
|
---|
2765 | this, instead of using a series of `r', `w', or `x' letters after the
|
---|
2766 | operator, you use the letter `u', `g', or `o'. For example, the mode
|
---|
2767 |
|
---|
2768 | o+g
|
---|
2769 |
|
---|
2770 | adds the permissions for users who are in a file's group to the
|
---|
2771 | permissions that other users have for the file. Thus, if the file
|
---|
2772 | started out as mode 664 (`rw-rw-r--'), the above mode would change it
|
---|
2773 | to mode 666 (`rw-rw-rw-'). If the file had started out as mode 741
|
---|
2774 | (`rwxr----x'), the above mode would change it to mode 745
|
---|
2775 | (`rwxr--r-x'). The `-' and `=' operations work analogously.
|
---|
2776 |
|
---|
2777 |
|
---|
2778 | File: find.info, Node: Changing Special Mode Bits, Next: Conditional Executability, Prev: Copying Permissions, Up: Symbolic Modes
|
---|
2779 |
|
---|
2780 | 5.2.3 Changing Special Mode Bits
|
---|
2781 | --------------------------------
|
---|
2782 |
|
---|
2783 | In addition to changing a file's read, write, and execute/search
|
---|
2784 | permissions, you can change its special mode bits. *Note Mode
|
---|
2785 | Structure::, for a summary of these special mode bits.
|
---|
2786 |
|
---|
2787 | To change the file mode bits to set the user ID on execution, use
|
---|
2788 | `u' in the USERS part of the symbolic mode and `s' in the PERMISSIONS
|
---|
2789 | part.
|
---|
2790 |
|
---|
2791 | To change the file mode bits to set the group ID on execution, use
|
---|
2792 | `g' in the USERS part of the symbolic mode and `s' in the PERMISSIONS
|
---|
2793 | part.
|
---|
2794 |
|
---|
2795 | To set both user and group ID on execution, omit the USERS part of
|
---|
2796 | the symbolic mode (or use `a') and use `s' in the PERMISSIONS part.
|
---|
2797 |
|
---|
2798 | To change the file mode bits to set the restricted deletion flag or
|
---|
2799 | sticky bit, omit the USERS part of the symbolic mode (or use `a') and
|
---|
2800 | use `t' in the PERMISSIONS part.
|
---|
2801 |
|
---|
2802 | For example, to set the set-user-ID mode bit of a program, you can
|
---|
2803 | use the mode:
|
---|
2804 |
|
---|
2805 | u+s
|
---|
2806 |
|
---|
2807 | To remove both set-user-ID and set-group-ID mode bits from it, you
|
---|
2808 | can use the mode:
|
---|
2809 |
|
---|
2810 | a-s
|
---|
2811 |
|
---|
2812 | To set the restricted deletion flag or sticky bit, you can use the
|
---|
2813 | mode:
|
---|
2814 |
|
---|
2815 | +t
|
---|
2816 |
|
---|
2817 | The combination `o+s' has no effect. On GNU systems the
|
---|
2818 | combinations `u+t' and `g+t' have no effect, and `o+t' acts like plain
|
---|
2819 | `+t'.
|
---|
2820 |
|
---|
2821 | The `=' operator is not very useful with special mode bits. For
|
---|
2822 | example, the mode:
|
---|
2823 |
|
---|
2824 | o=t
|
---|
2825 |
|
---|
2826 | does set the restricted deletion flag or sticky bit, but it also
|
---|
2827 | removes all read, write, and execute/search permissions that users not
|
---|
2828 | in the file's group might have had for it.
|
---|
2829 |
|
---|
2830 | *Note Directory Setuid and Setgid::, for additional rules concerning
|
---|
2831 | set-user-ID and set-group-ID bits and directories.
|
---|
2832 |
|
---|
2833 |
|
---|
2834 | File: find.info, Node: Conditional Executability, Next: Multiple Changes, Prev: Changing Special Mode Bits, Up: Symbolic Modes
|
---|
2835 |
|
---|
2836 | 5.2.4 Conditional Executability
|
---|
2837 | -------------------------------
|
---|
2838 |
|
---|
2839 | There is one more special type of symbolic permission: if you use `X'
|
---|
2840 | instead of `x', execute/search permission is affected only if the file
|
---|
2841 | is a directory or already had execute permission.
|
---|
2842 |
|
---|
2843 | For example, this mode:
|
---|
2844 |
|
---|
2845 | a+X
|
---|
2846 |
|
---|
2847 | gives all users permission to search directories, or to execute files if
|
---|
2848 | anyone could execute them before.
|
---|
2849 |
|
---|
2850 |
|
---|
2851 | File: find.info, Node: Multiple Changes, Next: Umask and Protection, Prev: Conditional Executability, Up: Symbolic Modes
|
---|
2852 |
|
---|
2853 | 5.2.5 Making Multiple Changes
|
---|
2854 | -----------------------------
|
---|
2855 |
|
---|
2856 | The format of symbolic modes is actually more complex than described
|
---|
2857 | above (*note Setting Permissions::). It provides two ways to make
|
---|
2858 | multiple changes to files' mode bits.
|
---|
2859 |
|
---|
2860 | The first way is to specify multiple OPERATION and PERMISSIONS parts
|
---|
2861 | after a USERS part in the symbolic mode.
|
---|
2862 |
|
---|
2863 | For example, the mode:
|
---|
2864 |
|
---|
2865 | og+rX-w
|
---|
2866 |
|
---|
2867 | gives users other than the owner of the file read permission and, if it
|
---|
2868 | is a directory or if someone already had execute permission to it,
|
---|
2869 | gives them execute/search permission; and it also denies them write
|
---|
2870 | permission to the file. It does not affect the permission that the
|
---|
2871 | owner of the file has for it. The above mode is equivalent to the two
|
---|
2872 | modes:
|
---|
2873 |
|
---|
2874 | og+rX
|
---|
2875 | og-w
|
---|
2876 |
|
---|
2877 | The second way to make multiple changes is to specify more than one
|
---|
2878 | simple symbolic mode, separated by commas. For example, the mode:
|
---|
2879 |
|
---|
2880 | a+r,go-w
|
---|
2881 |
|
---|
2882 | gives everyone permission to read the file and removes write permission
|
---|
2883 | on it for all users except its owner. Another example:
|
---|
2884 |
|
---|
2885 | u=rwx,g=rx,o=
|
---|
2886 |
|
---|
2887 | sets all of the permission bits for the file explicitly. (It gives
|
---|
2888 | users who are not in the file's group no permission at all for it.)
|
---|
2889 |
|
---|
2890 | The two methods can be combined. The mode:
|
---|
2891 |
|
---|
2892 | a+r,g+x-w
|
---|
2893 |
|
---|
2894 | gives all users permission to read the file, and gives users who are in
|
---|
2895 | the file's group permission to execute/search it as well, but not
|
---|
2896 | permission to write to it. The above mode could be written in several
|
---|
2897 | different ways; another is:
|
---|
2898 |
|
---|
2899 | u+r,g+rx,o+r,g-w
|
---|
2900 |
|
---|
2901 |
|
---|
2902 | File: find.info, Node: Umask and Protection, Prev: Multiple Changes, Up: Symbolic Modes
|
---|
2903 |
|
---|
2904 | 5.2.6 The Umask and Protection
|
---|
2905 | ------------------------------
|
---|
2906 |
|
---|
2907 | If the USERS part of a symbolic mode is omitted, it defaults to `a'
|
---|
2908 | (affect all users), except that any permissions that are _set_ in the
|
---|
2909 | system variable `umask' are _not affected_. The value of `umask' can
|
---|
2910 | be set using the `umask' command. Its default value varies from system
|
---|
2911 | to system.
|
---|
2912 |
|
---|
2913 | Omitting the USERS part of a symbolic mode is generally not useful
|
---|
2914 | with operations other than `+'. It is useful with `+' because it
|
---|
2915 | allows you to use `umask' as an easily customizable protection against
|
---|
2916 | giving away more permission to files than you intended to.
|
---|
2917 |
|
---|
2918 | As an example, if `umask' has the value 2, which removes write
|
---|
2919 | permission for users who are not in the file's group, then the mode:
|
---|
2920 |
|
---|
2921 | +w
|
---|
2922 |
|
---|
2923 | adds permission to write to the file to its owner and to other users who
|
---|
2924 | are in the file's group, but _not_ to other users. In contrast, the
|
---|
2925 | mode:
|
---|
2926 |
|
---|
2927 | a+w
|
---|
2928 |
|
---|
2929 | ignores `umask', and _does_ give write permission for the file to all
|
---|
2930 | users.
|
---|
2931 |
|
---|
2932 |
|
---|
2933 | File: find.info, Node: Numeric Modes, Next: Directory Setuid and Setgid, Prev: Symbolic Modes, Up: File Permissions
|
---|
2934 |
|
---|
2935 | 5.3 Numeric Modes
|
---|
2936 | =================
|
---|
2937 |
|
---|
2938 | As an alternative to giving a symbolic mode, you can give an octal
|
---|
2939 | (base 8) number that represents the mode. This number is always
|
---|
2940 | interpreted in octal; you do not have to add a leading `0', as you do
|
---|
2941 | in C. Mode `0055' is the same as mode `55'.
|
---|
2942 |
|
---|
2943 | A numeric mode is usually shorter than the corresponding symbolic
|
---|
2944 | mode, but it is limited in that normally it cannot take into account the
|
---|
2945 | previous file mode bits; it can only set them absolutely. (As
|
---|
2946 | discussed in the next section, the set-user-ID and set-group-ID bits of
|
---|
2947 | directories are an exception to this general limitation.)
|
---|
2948 |
|
---|
2949 | The permissions granted to the user, to other users in the file's
|
---|
2950 | group, and to other users not in the file's group each require three
|
---|
2951 | bits, which are represented as one octal digit. The three special mode
|
---|
2952 | bits also require one bit each, and they are as a group represented as
|
---|
2953 | another octal digit. Here is how the bits are arranged, starting with
|
---|
2954 | the lowest valued bit:
|
---|
2955 |
|
---|
2956 | Value in Corresponding
|
---|
2957 | Mode Mode Bit
|
---|
2958 |
|
---|
2959 | Other users not in the file's group:
|
---|
2960 | 1 Execute/search
|
---|
2961 | 2 Write
|
---|
2962 | 4 Read
|
---|
2963 |
|
---|
2964 | Other users in the file's group:
|
---|
2965 | 10 Execute/search
|
---|
2966 | 20 Write
|
---|
2967 | 40 Read
|
---|
2968 |
|
---|
2969 | The file's owner:
|
---|
2970 | 100 Execute/search
|
---|
2971 | 200 Write
|
---|
2972 | 400 Read
|
---|
2973 |
|
---|
2974 | Special mode bits:
|
---|
2975 | 1000 Restricted deletion flag or sticky bit
|
---|
2976 | 2000 Set group ID on execution
|
---|
2977 | 4000 Set user ID on execution
|
---|
2978 |
|
---|
2979 | For example, numeric mode `4755' corresponds to symbolic mode
|
---|
2980 | `u=rwxs,go=rx', and numeric mode `664' corresponds to symbolic mode
|
---|
2981 | `ug=rw,o=r'. Numeric mode `0' corresponds to symbolic mode `a='.
|
---|
2982 |
|
---|
2983 |
|
---|
2984 | File: find.info, Node: Directory Setuid and Setgid, Prev: Numeric Modes, Up: File Permissions
|
---|
2985 |
|
---|
2986 | 5.4 Directories and the Set-User-ID and Set-Group-ID Bits
|
---|
2987 | =========================================================
|
---|
2988 |
|
---|
2989 | On most systems, if a directory's set-group-ID bit is set, newly
|
---|
2990 | created subfiles inherit the same group as the directory, and newly
|
---|
2991 | created subdirectories inherit the set-group-ID bit of the parent
|
---|
2992 | directory. On a few systems, a directory's set-user-ID bit has a
|
---|
2993 | similar effect on the ownership of new subfiles and the set-user-ID
|
---|
2994 | bits of new subdirectories. These mechanisms let users share files
|
---|
2995 | more easily, by lessening the need to use `chmod' or `chown' to share
|
---|
2996 | new files.
|
---|
2997 |
|
---|
2998 | These convenience mechanisms rely on the set-user-ID and set-group-ID
|
---|
2999 | bits of directories. If commands like `chmod' and `mkdir' routinely
|
---|
3000 | cleared these bits on directories, the mechanisms would be less
|
---|
3001 | convenient and it would be harder to share files. Therefore, a command
|
---|
3002 | like `chmod' does not affect the set-user-ID or set-group-ID bits of a
|
---|
3003 | directory unless the user specifically mentions them in a symbolic
|
---|
3004 | mode, or sets them in a numeric mode. For example, on systems that
|
---|
3005 | support set-group-ID inheritance:
|
---|
3006 |
|
---|
3007 | # These commands leave the set-user-ID and
|
---|
3008 | # set-group-ID bits of the subdirectories alone,
|
---|
3009 | # so that they retain their default values.
|
---|
3010 | mkdir A B C
|
---|
3011 | chmod 755 A
|
---|
3012 | chmod 0755 B
|
---|
3013 | chmod u=rwx,go=rx C
|
---|
3014 | mkdir -m 755 D
|
---|
3015 | mkdir -m 0755 E
|
---|
3016 | mkdir -m u=rwx,go=rx F
|
---|
3017 |
|
---|
3018 | If you want to try to set these bits, you must mention them
|
---|
3019 | explicitly in the symbolic or numeric modes, e.g.:
|
---|
3020 |
|
---|
3021 | # These commands try to set the set-user-ID
|
---|
3022 | # and set-group-ID bits of the subdirectories.
|
---|
3023 | mkdir G H
|
---|
3024 | chmod 6755 G
|
---|
3025 | chmod u=rwx,go=rx,a+s H
|
---|
3026 | mkdir -m 6755 I
|
---|
3027 | mkdir -m u=rwx,go=rx,a+s J
|
---|
3028 |
|
---|
3029 | If you want to try to clear these bits, you must mention them
|
---|
3030 | explicitly in a symbolic mode, e.g.:
|
---|
3031 |
|
---|
3032 | # This command tries to clear the set-user-ID
|
---|
3033 | # and set-group-ID bits of the directory D.
|
---|
3034 | chmod a-s D
|
---|
3035 |
|
---|
3036 | This behavior is a GNU extension. Portable scripts should not rely
|
---|
3037 | on requests to set or clear these bits on directories, as POSIX allows
|
---|
3038 | implementations to ignore these requests.
|
---|
3039 |
|
---|
3040 |
|
---|
3041 | File: find.info, Node: Reference, Next: Common Tasks, Prev: File Permissions, Up: Top
|
---|
3042 |
|
---|
3043 | 6 Reference
|
---|
3044 | ***********
|
---|
3045 |
|
---|
3046 | Below are summaries of the command line syntax for the programs
|
---|
3047 | discussed in this manual.
|
---|
3048 |
|
---|
3049 | * Menu:
|
---|
3050 |
|
---|
3051 | * Invoking find::
|
---|
3052 | * Invoking locate::
|
---|
3053 | * Invoking updatedb::
|
---|
3054 | * Invoking xargs::
|
---|
3055 | * Regular Expressions::
|
---|
3056 | * Environment Variables::
|
---|
3057 |
|
---|
3058 |
|
---|
3059 | File: find.info, Node: Invoking find, Next: Invoking locate, Up: Reference
|
---|
3060 |
|
---|
3061 | 6.1 Invoking `find'
|
---|
3062 | ===================
|
---|
3063 |
|
---|
3064 | find [-H] [-L] [-P] [-D DEBUGOPTIONS] [-OLEVEL] [FILE...] [EXPRESSION]
|
---|
3065 |
|
---|
3066 | `find' searches the directory tree rooted at each file name FILE by
|
---|
3067 | evaluating the EXPRESSION on each file it finds in the tree.
|
---|
3068 |
|
---|
3069 | The command line may begin with the `-H', `-L', `-P', `-D' and `-O'
|
---|
3070 | options. These are followed by a list of files or directories that
|
---|
3071 | should be searched. If no files to search are specified, the current
|
---|
3072 | directory (`.') is used.
|
---|
3073 |
|
---|
3074 | This list of files to search is followed by a list of expressions
|
---|
3075 | describing the files we wish to search for. The first part of the
|
---|
3076 | expression is recognised by the fact that it begins with `-' followed
|
---|
3077 | by some other letters (for example `-print'), or is either `(' or `!'.
|
---|
3078 | Any arguments after it are the rest of the expression.
|
---|
3079 |
|
---|
3080 | If no expression is given, the expression `-print' is used.
|
---|
3081 |
|
---|
3082 | The `find' command exits with status zero if all files matched are
|
---|
3083 | processed successfully, greater than zero if errors occur.
|
---|
3084 |
|
---|
3085 | The `find' program also recognises two options for administrative
|
---|
3086 | use:
|
---|
3087 |
|
---|
3088 | `--help'
|
---|
3089 | Print a summary of the command line usage and exit.
|
---|
3090 |
|
---|
3091 | `--version'
|
---|
3092 | Print the version number of `find' and exit.
|
---|
3093 |
|
---|
3094 | The `-version' option is a synonym for `--version'
|
---|
3095 |
|
---|
3096 | * Menu:
|
---|
3097 |
|
---|
3098 | * Filesystem Traversal Options::
|
---|
3099 | * Warning Messages::
|
---|
3100 | * Optimisation Options::
|
---|
3101 | * Debug Options::
|
---|
3102 | * Find Expressions::
|
---|
3103 |
|
---|
3104 |
|
---|
3105 | File: find.info, Node: Filesystem Traversal Options, Next: Warning Messages, Up: Invoking find
|
---|
3106 |
|
---|
3107 | 6.1.1 Filesystem Traversal Options
|
---|
3108 | ----------------------------------
|
---|
3109 |
|
---|
3110 | The options `-H', `-L' or `-P' may be specified at the start of the
|
---|
3111 | command line (if none of these is specified, `-P' is assumed). If you
|
---|
3112 | specify more than one of these options, the last one specified takes
|
---|
3113 | effect (but note that the `-follow' option is equivalent to `-L').
|
---|
3114 |
|
---|
3115 | `-P'
|
---|
3116 | Never follow symbolic links (this is the default), except in the
|
---|
3117 | case of the `-xtype' predicate.
|
---|
3118 |
|
---|
3119 | `-L'
|
---|
3120 | Always follow symbolic links, except in the case of the `-xtype'
|
---|
3121 | predicate.
|
---|
3122 |
|
---|
3123 | `-H'
|
---|
3124 | Follow symbolic links specified in the list of files to search, or
|
---|
3125 | which are otherwise specified on the command line.
|
---|
3126 |
|
---|
3127 | If `find' would follow a symbolic link, but cannot for any reason
|
---|
3128 | (for example, because it has insufficient permissions or the link is
|
---|
3129 | broken), it falls back on using the properties of the symbolic link
|
---|
3130 | itself. *Note Symbolic Links:: for a more complete description of how
|
---|
3131 | symbolic links are handled.
|
---|
3132 |
|
---|
3133 |
|
---|
3134 | File: find.info, Node: Warning Messages, Next: Optimisation Options, Prev: Filesystem Traversal Options, Up: Invoking find
|
---|
3135 |
|
---|
3136 | 6.1.2 Warning Messages
|
---|
3137 | ----------------------
|
---|
3138 |
|
---|
3139 | If there is an error on the `find' command line, an error message is
|
---|
3140 | normally issued. However, there are some usages that are inadvisable
|
---|
3141 | but which `find' should still accept. Under these circumstances,
|
---|
3142 | `find' may issue a warning message. By default, warnings are enabled
|
---|
3143 | only if `find' is being run interactively (specifically, if the
|
---|
3144 | standard input is a terminal). Warning messages can be controlled
|
---|
3145 | explicitly by the use of options on the command line:
|
---|
3146 |
|
---|
3147 | `-warn'
|
---|
3148 | Issue warning messages where appropriate.
|
---|
3149 |
|
---|
3150 | `-nowarn'
|
---|
3151 | Do not issue warning messages.
|
---|
3152 |
|
---|
3153 | These options take effect at the point on the command line where they
|
---|
3154 | are specified. Therefore it's not useful to specify `-nowarn' at the
|
---|
3155 | end of the command line. The warning messages affected by the above
|
---|
3156 | options are triggered by:
|
---|
3157 |
|
---|
3158 | - Use of the `-d' option which is deprecated; please use `-depth'
|
---|
3159 | instead, since the latter is POSIX-compliant.
|
---|
3160 |
|
---|
3161 | - Use of the `-ipath' option which is deprecated; please use
|
---|
3162 | `-iwholename' instead.
|
---|
3163 |
|
---|
3164 | - Specifying an option (for example `-mindepth') after a non-option
|
---|
3165 | (for example `-type' or `-print') on the command line.
|
---|
3166 |
|
---|
3167 | The default behaviour above is designed to work in that way so that
|
---|
3168 | existing shell scripts don't generate spurious errors, but people will
|
---|
3169 | be made aware of the problem.
|
---|
3170 |
|
---|
3171 | Some warning messages are issued for less common or more serious
|
---|
3172 | problems, and consequently cannot be turned off:
|
---|
3173 |
|
---|
3174 | - Use of an unrecognised backslash escape sequence with `-fprintf'
|
---|
3175 |
|
---|
3176 | - Use of an unrecognised formatting directive with `-fprintf'
|
---|
3177 |
|
---|
3178 |
|
---|
3179 | File: find.info, Node: Optimisation Options, Next: Debug Options, Prev: Warning Messages, Up: Invoking find
|
---|
3180 |
|
---|
3181 | 6.1.3 Optimisation Options
|
---|
3182 | --------------------------
|
---|
3183 |
|
---|
3184 | The `-OLEVEL' option sets `find''s optimisation level to LEVEL. The
|
---|
3185 | default optimisation level is 1.
|
---|
3186 |
|
---|
3187 | At certain optimisation levels, `find' reorders tests to speed up
|
---|
3188 | execution while preserving the overall effect; that is, predicates with
|
---|
3189 | side effects are not reordered relative to each other. The
|
---|
3190 | optimisations performed at each optimisation level are as follows.
|
---|
3191 |
|
---|
3192 | `0'
|
---|
3193 | Currently equivalent to optimisation level 1.
|
---|
3194 |
|
---|
3195 | `1'
|
---|
3196 | This is the default optimisation level and corresponds to the
|
---|
3197 | traditional behaviour. Expressions are reordered so that tests
|
---|
3198 | based only on the names of files (for example` -name' and
|
---|
3199 | `-regex') are performed first.
|
---|
3200 |
|
---|
3201 | `2'
|
---|
3202 | Any `-type' or `-xtype' tests are performed after any tests based
|
---|
3203 | only on the names of files, but before any tests that require
|
---|
3204 | information from the inode. On many modern versions of Unix, file
|
---|
3205 | types are returned by `readdir()' and so these predicates are
|
---|
3206 | faster to evaluate than predicates which need to stat the file
|
---|
3207 | first.
|
---|
3208 |
|
---|
3209 | `3'
|
---|
3210 | At this optimisation level, the full cost-based query optimiser is
|
---|
3211 | enabled. The order of tests is modified so that cheap (i.e. fast)
|
---|
3212 | tests are performed first and more expensive ones are performed
|
---|
3213 | later, if necessary. Within each cost band, predicates are
|
---|
3214 | evaluated earlier or later according to whether they are likely to
|
---|
3215 | succeed or not. For `-o', predicates which are likely to succeed
|
---|
3216 | are evaluated earlier, and for `-a', predicates which are likely
|
---|
3217 | to fail are evaluated earlier.
|
---|
3218 |
|
---|
3219 |
|
---|
3220 | File: find.info, Node: Debug Options, Next: Find Expressions, Prev: Optimisation Options, Up: Invoking find
|
---|
3221 |
|
---|
3222 | 6.1.4 Debug Options
|
---|
3223 | -------------------
|
---|
3224 |
|
---|
3225 | The `-D' option makes `find' produce diagnostic output. Much of the
|
---|
3226 | information is useful only for diagnosing problems, and so most people
|
---|
3227 | will not find this option helpful.
|
---|
3228 |
|
---|
3229 | The list of debug options should be comma separated. Compatibility
|
---|
3230 | of the debug options is not guaranteed between releases of findutils.
|
---|
3231 | For a complete list of valid debug options, see the output of `find -D
|
---|
3232 | help'. Valid debug options include:
|
---|
3233 | `help'
|
---|
3234 | Explain the debugging options.
|
---|
3235 |
|
---|
3236 | `tree'
|
---|
3237 | Show the expression tree in its original and optimised form.
|
---|
3238 |
|
---|
3239 | `stat'
|
---|
3240 | Print messages as files are examined with the stat and lstat system
|
---|
3241 | calls. The find program tries to minimise such calls.
|
---|
3242 |
|
---|
3243 | `opt'
|
---|
3244 | Prints diagnostic information relating to the optimisation of the
|
---|
3245 | expression tree; see the `-O' option.
|
---|
3246 |
|
---|
3247 |
|
---|
3248 | File: find.info, Node: Find Expressions, Prev: Debug Options, Up: Invoking find
|
---|
3249 |
|
---|
3250 | 6.1.5 Find Expressions
|
---|
3251 | ----------------------
|
---|
3252 |
|
---|
3253 | The final part of the `find' command line is a list of expressions.
|
---|
3254 | *Note Primary Index::, for a summary of all of the tests, actions, and
|
---|
3255 | options that the expression can contain. If the expression is missing,
|
---|
3256 | `-print' is assumed.
|
---|
3257 |
|
---|
3258 |
|
---|
3259 | File: find.info, Node: Invoking locate, Next: Invoking updatedb, Prev: Invoking find, Up: Reference
|
---|
3260 |
|
---|
3261 | 6.2 Invoking `locate'
|
---|
3262 | =====================
|
---|
3263 |
|
---|
3264 | locate [OPTION...] PATTERN...
|
---|
3265 |
|
---|
3266 | For each PATTERN given `locate' searches one or more file name
|
---|
3267 | databases returning each match of PATTERN.
|
---|
3268 |
|
---|
3269 | For each PATTERN given `locate' searches one or more file name
|
---|
3270 | databases returning each match of PATTERN.
|
---|
3271 |
|
---|
3272 | `--all'
|
---|
3273 | `-A'
|
---|
3274 | Print only names which match all non-option arguments, not those
|
---|
3275 | matching one or more non-option arguments.
|
---|
3276 |
|
---|
3277 | `--basename'
|
---|
3278 | `-b'
|
---|
3279 | The specified pattern is matched against just the last component of
|
---|
3280 | the name of a file in the `locate' database. This last component
|
---|
3281 | is also called the "base name". For example, the base name of
|
---|
3282 | `/tmp/mystuff/foo.old.c' is `foo.old.c'. If the pattern contains
|
---|
3283 | metacharacters, it must match the base name exactly. If not, it
|
---|
3284 | must match part of the base name.
|
---|
3285 |
|
---|
3286 | `--count'
|
---|
3287 | `-c'
|
---|
3288 | Instead of printing the matched file names, just print the total
|
---|
3289 | number of matches found, unless `--print' (`-p') is also present.
|
---|
3290 |
|
---|
3291 | `--database=PATH'
|
---|
3292 | `-d PATH'
|
---|
3293 | Instead of searching the default `locate' database, `locate'
|
---|
3294 | search the file name databases in PATH, which is a colon-separated
|
---|
3295 | list of database file names. You can also use the environment
|
---|
3296 | variable `LOCATE_PATH' to set the list of database files to
|
---|
3297 | search. The option overrides the environment variable if both are
|
---|
3298 | used. Empty elements in PATH (that is, a leading or trailing
|
---|
3299 | colon, or two colons in a row) are taken to stand for the default
|
---|
3300 | database. A database can be supplied on stdin, using `-' as an
|
---|
3301 | element of `path'. If more than one element of `path' is `-',
|
---|
3302 | later instances are ignored (but a warning message is printed).
|
---|
3303 |
|
---|
3304 | `--existing'
|
---|
3305 | `-e'
|
---|
3306 | Only print out such names which currently exist (instead of such
|
---|
3307 | names which existed when the database was created). Note that
|
---|
3308 | this may slow down the program a lot, if there are many matches in
|
---|
3309 | the database. The way in which broken symbolic links are treated
|
---|
3310 | is affected by the `-L', `-P' and `-H' options. Please note that
|
---|
3311 | it is possible for the file to be deleted after `locate' has
|
---|
3312 | checked that it exists, but before you use it.
|
---|
3313 |
|
---|
3314 | `--non-existing'
|
---|
3315 | `-E'
|
---|
3316 | Only print out such names which currently do not exist (instead of
|
---|
3317 | such names which existed when the database was created). Note that
|
---|
3318 | this may slow down the program a lot, if there are many matches in
|
---|
3319 | the database. The way in which broken symbolic links are treated
|
---|
3320 | is affected by the `-L', `-P' and `-H' options. Please note that
|
---|
3321 | `locate' checks that the file does not exist, but a file of the
|
---|
3322 | same name might be created after `locate''s check but before you
|
---|
3323 | read `locate''s output.
|
---|
3324 |
|
---|
3325 | `--follow'
|
---|
3326 | `-L'
|
---|
3327 | If testing for the existence of files (with the `-e' or `-E'
|
---|
3328 | options), consider broken symbolic links to be non-existing. This
|
---|
3329 | is the default behaviour.
|
---|
3330 |
|
---|
3331 | `--nofollow'
|
---|
3332 | `-P'
|
---|
3333 | `-H'
|
---|
3334 | If testing for the existence of files (with the `-e' or `-E'
|
---|
3335 | options), treat broken symbolic links as if they were existing
|
---|
3336 | files. The `-H' form of this option is provided purely for
|
---|
3337 | similarity with `find'; the use of `-P' is recommended over `-H'.
|
---|
3338 |
|
---|
3339 | `--ignore-case'
|
---|
3340 | `-i'
|
---|
3341 | Ignore case distinctions in both the pattern and the file names.
|
---|
3342 |
|
---|
3343 | `--limit=N'
|
---|
3344 | `-l N'
|
---|
3345 | Limit the number of results printed to N. When used with the
|
---|
3346 | `--count' option, the value printed will never be larger than this
|
---|
3347 | limit.
|
---|
3348 |
|
---|
3349 | `--mmap'
|
---|
3350 | `-m'
|
---|
3351 | Accepted but does nothing. The option is supported only to provide
|
---|
3352 | compatibility with BSD's `locate'.
|
---|
3353 |
|
---|
3354 | `--null'
|
---|
3355 | `-0'
|
---|
3356 | Results are separated with the ASCII NUL character rather than the
|
---|
3357 | newline character. To get the full benefit of the use of this
|
---|
3358 | option, use the new `locate' database format (that is the default
|
---|
3359 | anyway).
|
---|
3360 |
|
---|
3361 | `--print'
|
---|
3362 | `-p'
|
---|
3363 | Print search results when they normally would not, because of the
|
---|
3364 | presence of `--statistics' (`-S') or `--count' (`-c').
|
---|
3365 |
|
---|
3366 | `--wholename'
|
---|
3367 | `-w'
|
---|
3368 | The specified pattern is matched against the whole name of the
|
---|
3369 | file in the `locate' database. If the pattern contains
|
---|
3370 | metacharacters, it must match exactly. If not, it must match part
|
---|
3371 | of the whole file name. This is the default behaviour.
|
---|
3372 |
|
---|
3373 | `--regex'
|
---|
3374 | `-r'
|
---|
3375 | Instead of using substring or shell glob matching, the pattern
|
---|
3376 | specified on the command line is understood to be a regular
|
---|
3377 | expression. GNU Emacs-style regular expressions are assumed unless
|
---|
3378 | the `--regextype' option is also given. File names from the
|
---|
3379 | `locate' database are matched using the specified regular
|
---|
3380 | expression. If the `-i' flag is also given, matching is
|
---|
3381 | case-insensitive. Matches are performed against the whole path
|
---|
3382 | name, and so by default a pathname will be matched if any part of
|
---|
3383 | it matches the specified regular expression. The regular
|
---|
3384 | expression may use `^' or `$' to anchor a match at the beginning
|
---|
3385 | or end of a pathname.
|
---|
3386 |
|
---|
3387 | `--regextype'
|
---|
3388 | This option changes the regular expression syntax and behaviour
|
---|
3389 | used by the `--regex' option. *Note Regular Expressions:: for more
|
---|
3390 | information on the regular expression dialects understood by GNU
|
---|
3391 | findutils.
|
---|
3392 |
|
---|
3393 | `--stdio'
|
---|
3394 | `-s'
|
---|
3395 | Accepted but does nothing. The option is supported only to provide
|
---|
3396 | compatibility with BSD's `locate'.
|
---|
3397 |
|
---|
3398 | `--statistics'
|
---|
3399 | `-S'
|
---|
3400 | Print some summary information for each `locate' database. No
|
---|
3401 | search is performed unless non-option arguments are given.
|
---|
3402 | Although the BSD version of locate also has this option, the
|
---|
3403 | format of the output is different.
|
---|
3404 |
|
---|
3405 | `--help'
|
---|
3406 | Print a summary of the command line usage for `locate' and exit.
|
---|
3407 |
|
---|
3408 | `--version'
|
---|
3409 | Print the version number of `locate' and exit.
|
---|
3410 |
|
---|
3411 |
|
---|
3412 | File: find.info, Node: Invoking updatedb, Next: Invoking xargs, Prev: Invoking locate, Up: Reference
|
---|
3413 |
|
---|
3414 | 6.3 Invoking `updatedb'
|
---|
3415 | =======================
|
---|
3416 |
|
---|
3417 | updatedb [OPTION...]
|
---|
3418 |
|
---|
3419 | `updatedb' creates and updates the database of file names used by
|
---|
3420 | `locate'. `updatedb' generates a list of files similar to the output
|
---|
3421 | of `find' and then uses utilities for optimizing the database for
|
---|
3422 | performance. `updatedb' is often run periodically as a `cron' job and
|
---|
3423 | configured with environment variables or command options. Typically,
|
---|
3424 | operating systems have a shell script that "exports" configurations for
|
---|
3425 | variable definitions and uses another schell script that "sources" the
|
---|
3426 | configuration file into the environment and then executes `updatedb' in
|
---|
3427 | the environment.
|
---|
3428 |
|
---|
3429 | `updatedb' creates and updates the database of file names used by
|
---|
3430 | `locate'. `updatedb' generates a list of files similar to the output
|
---|
3431 | of `find' and then uses utilities for optimizing the database for
|
---|
3432 | performance. `updatedb' is often run periodically as a `cron' job and
|
---|
3433 | configured with environment variables or command options. Typically,
|
---|
3434 | operating systems have a shell script that "exports" configurations for
|
---|
3435 | variable definitions and uses another schell script that "sources" the
|
---|
3436 | configuration file into the environment and then executes `updatedb' in
|
---|
3437 | the environment.
|
---|
3438 |
|
---|
3439 | `--findoptions='OPTION...''
|
---|
3440 | Global options to pass on to `find'. The environment variable
|
---|
3441 | `FINDOPTIONS' also sets this value. Default is none.
|
---|
3442 |
|
---|
3443 | `--localpaths='PATH...''
|
---|
3444 | Non-network directories to put in the database. Default is `/'.
|
---|
3445 |
|
---|
3446 | `--netpaths='PATH...''
|
---|
3447 | Network (NFS, AFS, RFS, etc.) directories to put in the database.
|
---|
3448 | The environment variable `NETPATHS' also sets this value. Default
|
---|
3449 | is none.
|
---|
3450 |
|
---|
3451 | `--prunepaths='PATH...''
|
---|
3452 | Directories to omit from the database, which would otherwise be
|
---|
3453 | included. The environment variable `PRUNEPATHS' also sets this
|
---|
3454 | value. Default is `/tmp /usr/tmp /var/tmp /afs'. The paths are
|
---|
3455 | used as regular expressions (with `find ... -regex', so you need
|
---|
3456 | to specify these paths in the same way that `find' will encounter
|
---|
3457 | them. This means for example that the paths must not include
|
---|
3458 | trailing slashes.
|
---|
3459 |
|
---|
3460 | `--prunefs='PATH...''
|
---|
3461 | Filesystems to omit from the database, which would otherwise be
|
---|
3462 | included. Note that files are pruned when a filesystem is reached;
|
---|
3463 | Any filesystem mounted under an undesired filesystem will be
|
---|
3464 | ignored. The environment variable `PRUNEFS' also sets this value.
|
---|
3465 | Default is `nfs NFS proc'.
|
---|
3466 |
|
---|
3467 | `--output=DBFILE'
|
---|
3468 | The database file to build. Default is system-dependent, but
|
---|
3469 | typically `/usr/local/var/locatedb'.
|
---|
3470 |
|
---|
3471 | `--localuser=USER'
|
---|
3472 | The user to search the non-network directories as, using `su'.
|
---|
3473 | Default is to search the non-network directories as the current
|
---|
3474 | user. You can also use the environment variable `LOCALUSER' to
|
---|
3475 | set this user.
|
---|
3476 |
|
---|
3477 | `--netuser=USER'
|
---|
3478 | The user to search network directories as, using `su'. Default
|
---|
3479 | `user' is `daemon'. You can also use the environment variable
|
---|
3480 | `NETUSER' to set this user.
|
---|
3481 |
|
---|
3482 | `--old-format'
|
---|
3483 | Generate a `locate' database in the old format, for compatibility
|
---|
3484 | with versions of `locate' other than GNU `locate'. Using this
|
---|
3485 | option means that `locate' will not be able to properly handle
|
---|
3486 | non-ASCII characters in file names (that is, file names containing
|
---|
3487 | characters which have the eighth bit set, such as many of the
|
---|
3488 | characters from the ISO-8859-1 character set).
|
---|
3489 |
|
---|
3490 | `--help'
|
---|
3491 | Print a summary of the command line usage and exit.
|
---|
3492 |
|
---|
3493 | `--version'
|
---|
3494 | Print the version number of `updatedb' and exit.
|
---|
3495 |
|
---|
3496 |
|
---|
3497 | File: find.info, Node: Invoking xargs, Next: Regular Expressions, Prev: Invoking updatedb, Up: Reference
|
---|
3498 |
|
---|
3499 | 6.4 Invoking `xargs'
|
---|
3500 | ====================
|
---|
3501 |
|
---|
3502 | xargs [OPTION...] [COMMAND [INITIAL-ARGUMENTS]]
|
---|
3503 |
|
---|
3504 | `xargs' exits with the following status:
|
---|
3505 |
|
---|
3506 | 0
|
---|
3507 | if it succeeds
|
---|
3508 |
|
---|
3509 | 123
|
---|
3510 | if any invocation of the command exited with status 1-125
|
---|
3511 |
|
---|
3512 | 124
|
---|
3513 | if the command exited with status 255
|
---|
3514 |
|
---|
3515 | 125
|
---|
3516 | if the command is killed by a signal
|
---|
3517 |
|
---|
3518 | 126
|
---|
3519 | if the command cannot be run
|
---|
3520 |
|
---|
3521 | 127
|
---|
3522 | if the command is not found
|
---|
3523 |
|
---|
3524 | 1
|
---|
3525 | if some other error occurred.
|
---|
3526 |
|
---|
3527 | Exit codes greater than 128 are used by the shell to indicate that a
|
---|
3528 | program died due to a fatal signal.
|
---|
3529 |
|
---|
3530 | `--arg-file=INPUTFILE'
|
---|
3531 | `-a oINPUTFILE'
|
---|
3532 | Read names from the file INPUTFILE instead of standard input. If
|
---|
3533 | you use this option, the standard input stream remains unchanged
|
---|
3534 | when commands are run. Otherwise, stdin is redirected from
|
---|
3535 | `/dev/null'.
|
---|
3536 |
|
---|
3537 | `--null'
|
---|
3538 | `-0'
|
---|
3539 | Input file names are terminated by a null character instead of by
|
---|
3540 | whitespace, and any quotes and backslash characters are not
|
---|
3541 | considered special (every character is taken literally). Disables
|
---|
3542 | the end of file string, which is treated like any other argument.
|
---|
3543 |
|
---|
3544 | `--delimiter DELIM'
|
---|
3545 | `-d DELIM'
|
---|
3546 | Input file names are terminated by the specified character DELIM
|
---|
3547 | instead of by whitespace, and any quotes and backslash characters
|
---|
3548 | are not considered special (every character is taken literally).
|
---|
3549 | Disables the end of file string, which is treated like any other
|
---|
3550 | argument.
|
---|
3551 |
|
---|
3552 | The specified delimiter may be a single character, a C-style
|
---|
3553 | character escape such as `\n', or an octal or hexadecimal escape
|
---|
3554 | code. Octal and hexadecimal escape codes are understood as for the
|
---|
3555 | `printf' command. Multibyte characters are not supported.
|
---|
3556 |
|
---|
3557 | `-E EOF-STR'
|
---|
3558 | `--eof[=EOF-STR]'
|
---|
3559 | `-e[EOF-STR]'
|
---|
3560 | Set the end of file string to EOF-STR. If the end of file string
|
---|
3561 | occurs as a line of input, the rest of the input is ignored. If
|
---|
3562 | EOF-STR is omitted (`-e') or blank (either `-e' or `-E'), there is
|
---|
3563 | no end of file string. The `-e' form of this option is deprecated
|
---|
3564 | in favour of the POSIX-compliant `-E' option, which you should use
|
---|
3565 | instead. As of GNU xargs version 4.2.9, the default behaviour of
|
---|
3566 | xargs is not to have a logical end-of-file marker. The POSIX
|
---|
3567 | standard (IEEE Std 1003.1, 2004 Edition) allows this.
|
---|
3568 |
|
---|
3569 | `--help'
|
---|
3570 | Print a summary of the options to `xargs' and exit.
|
---|
3571 |
|
---|
3572 | `-I REPLACE-STR'
|
---|
3573 | `--replace[=REPLACE-STR]'
|
---|
3574 | `-i[REPLACE-STR]'
|
---|
3575 | Replace occurrences of REPLACE-STR in the initial arguments with
|
---|
3576 | names read from standard input. Also, unquoted blanks do not
|
---|
3577 | terminate arguments; instead, the input is split at newlines only.
|
---|
3578 | If REPLACE-STR is omitted (omitting it is allowed only for `-i'),
|
---|
3579 | it defaults to `{}' (like for `find -exec'). Implies `-x' and `-l
|
---|
3580 | 1'. The `-i' option is deprecated in favour of the `-I' option.
|
---|
3581 |
|
---|
3582 | `-L MAX-LINES'
|
---|
3583 | `--max-lines[=MAX-LINES]'
|
---|
3584 | `-l[MAX-LINES]'
|
---|
3585 | Use at most MAX-LINES non-blank input lines per command line. For
|
---|
3586 | `-l', MAX-LINES defaults to 1 if omitted. For `-L', the argument
|
---|
3587 | is mandatory. Trailing blanks cause an input line to be logically
|
---|
3588 | continued on the next input line, for the purpose of counting the
|
---|
3589 | lines. Implies `-x'. The `-l' form of this option is deprecated
|
---|
3590 | in favour of the POSIX-compliant `-L' option.
|
---|
3591 |
|
---|
3592 | `--max-args=MAX-ARGS'
|
---|
3593 | `-n MAX-ARGS'
|
---|
3594 | Use at most MAX-ARGS arguments per command line. Fewer than
|
---|
3595 | MAX-ARGS arguments will be used if the size (see the `-s' option)
|
---|
3596 | is exceeded, unless the `-x' option is given, in which case
|
---|
3597 | `xargs' will exit.
|
---|
3598 |
|
---|
3599 | `--interactive'
|
---|
3600 | `-p'
|
---|
3601 | Prompt the user about whether to run each command line and read a
|
---|
3602 | line from the terminal. Only run the command line if the response
|
---|
3603 | starts with `y' or `Y'. Implies `-t'.
|
---|
3604 |
|
---|
3605 | `--no-run-if-empty'
|
---|
3606 | `-r'
|
---|
3607 | If the standard input is completely empty, do not run the command.
|
---|
3608 | By default, the command is run once even if there is no input.
|
---|
3609 |
|
---|
3610 | `--max-chars=MAX-CHARS'
|
---|
3611 | `-s MAX-CHARS'
|
---|
3612 | Use at most MAX-CHARS characters per command line, including the
|
---|
3613 | command, initial arguments and any terminating nulls at the ends of
|
---|
3614 | the argument strings.
|
---|
3615 |
|
---|
3616 | `--show-limits'
|
---|
3617 | Display the limits on the command-line length which are imposed by
|
---|
3618 | the operating system, `xargs'' choice of buffer size and the `-s'
|
---|
3619 | option. Pipe the input from `/dev/null' (and perhaps specify
|
---|
3620 | `--no-run-if-empty') if you don't want `xargs' to do anything.
|
---|
3621 |
|
---|
3622 | `--verbose'
|
---|
3623 | `-t'
|
---|
3624 | Print the command line on the standard error output before
|
---|
3625 | executing it.
|
---|
3626 |
|
---|
3627 | `--version'
|
---|
3628 | Print the version number of `xargs' and exit.
|
---|
3629 |
|
---|
3630 | `--exit'
|
---|
3631 | `-x'
|
---|
3632 | Exit if the size (see the `-s' option) is exceeded.
|
---|
3633 |
|
---|
3634 | `--max-procs=MAX-PROCS'
|
---|
3635 | `-P MAX-PROCS'
|
---|
3636 | Run simultaneously up to MAX-PROCS processes at once; the default
|
---|
3637 | is 1. If MAX-PROCS is 0, `xargs' will run as many processes as
|
---|
3638 | possible simultaneously.
|
---|
3639 |
|
---|
3640 |
|
---|
3641 | File: find.info, Node: Regular Expressions, Next: Environment Variables, Prev: Invoking xargs, Up: Reference
|
---|
3642 |
|
---|
3643 | 6.5 Regular Expressions
|
---|
3644 | =======================
|
---|
3645 |
|
---|
3646 | The `-regex' and `-iregex' tests of `find' allow matching by regular
|
---|
3647 | expression, as does the `--regex' option of `locate'. There are many
|
---|
3648 | different types of Regular Expression, but the type used by `find' and
|
---|
3649 | `locate' is the same as is used in GNU Emacs. Both programs provide an
|
---|
3650 | option which allows you to select an alternative regular expression
|
---|
3651 | syntax; for `find' this is the `-regextype' option, and for `locate'
|
---|
3652 | this is the `--regextype' option.
|
---|
3653 |
|
---|
3654 | These options take a single argument, which indicates the specific
|
---|
3655 | regular expression syntax and behaviour that should be used. This
|
---|
3656 | should be one of the following:
|
---|
3657 |
|
---|
3658 | * Menu:
|
---|
3659 |
|
---|
3660 | * findutils-default regular expression syntax::
|
---|
3661 | * awk regular expression syntax::
|
---|
3662 | * egrep regular expression syntax::
|
---|
3663 | * emacs regular expression syntax::
|
---|
3664 | * gnu-awk regular expression syntax::
|
---|
3665 | * grep regular expression syntax::
|
---|
3666 | * posix-awk regular expression syntax::
|
---|
3667 | * posix-basic regular expression syntax::
|
---|
3668 | * posix-egrep regular expression syntax::
|
---|
3669 | * posix-extended regular expression syntax::
|
---|
3670 |
|
---|
3671 |
|
---|
3672 | File: find.info, Node: findutils-default regular expression syntax, Next: awk regular expression syntax, Up: Regular Expressions
|
---|
3673 |
|
---|
3674 | 6.5.1 `findutils-default' regular expression syntax
|
---|
3675 | ---------------------------------------------------
|
---|
3676 |
|
---|
3677 | The character `.' matches any single character.
|
---|
3678 |
|
---|
3679 | `+'
|
---|
3680 | indicates that the regular expression should match one or more
|
---|
3681 | occurrences of the previous atom or regexp.
|
---|
3682 |
|
---|
3683 | `?'
|
---|
3684 | indicates that the regular expression should match zero or one
|
---|
3685 | occurrence of the previous atom or regexp.
|
---|
3686 |
|
---|
3687 | `\+'
|
---|
3688 | matches a `+'
|
---|
3689 |
|
---|
3690 | `\?'
|
---|
3691 | matches a `?'.
|
---|
3692 |
|
---|
3693 | Bracket expressions are used to match ranges of characters. Bracket
|
---|
3694 | expressions where the range is backward, for example `[z-a]', are
|
---|
3695 | ignored. Within square brackets, `\' is taken literally. Character
|
---|
3696 | classes are not supported, so for example you would need to use `[0-9]'
|
---|
3697 | instead of `[[:digit:]]'.
|
---|
3698 |
|
---|
3699 | GNU extensions are supported:
|
---|
3700 | 1. `\w' matches a character within a word
|
---|
3701 |
|
---|
3702 | 2. `\W' matches a character which is not within a word
|
---|
3703 |
|
---|
3704 | 3. `\<' matches the beginning of a word
|
---|
3705 |
|
---|
3706 | 4. `\>' matches the end of a word
|
---|
3707 |
|
---|
3708 | 5. `\b' matches a word boundary
|
---|
3709 |
|
---|
3710 | 6. `\B' matches characters which are not a word boundary
|
---|
3711 |
|
---|
3712 | 7. `\`' matches the beginning of the whole input
|
---|
3713 |
|
---|
3714 | 8. `\'' matches the end of the whole input
|
---|
3715 |
|
---|
3716 |
|
---|
3717 | Grouping is performed with backslashes followed by parentheses `\(',
|
---|
3718 | `\)'. A backslash followed by a digit acts as a back-reference and
|
---|
3719 | matches the same thing as the previous grouped expression indicated by
|
---|
3720 | that number. For example `\2' matches the second group expression.
|
---|
3721 | The order of group expressions is determined by the position of their
|
---|
3722 | opening parenthesis `\('.
|
---|
3723 |
|
---|
3724 | The alternation operator is `\|'.
|
---|
3725 |
|
---|
3726 | The character `^' only represents the beginning of a string when it
|
---|
3727 | appears:
|
---|
3728 | 1. At the beginning of a regular expression
|
---|
3729 |
|
---|
3730 | 2. After an open-group, signified by `\('
|
---|
3731 |
|
---|
3732 | 3. After the alternation operator `\|'
|
---|
3733 |
|
---|
3734 |
|
---|
3735 | The character `$' only represents the end of a string when it
|
---|
3736 | appears:
|
---|
3737 | 1. At the end of a regular expression
|
---|
3738 |
|
---|
3739 | 2. Before an close-group, signified by `\)'
|
---|
3740 |
|
---|
3741 | 3. Before the alternation operator `\|'
|
---|
3742 |
|
---|
3743 |
|
---|
3744 | `*', `+' and `?' are special at any point in a regular expression
|
---|
3745 | except:
|
---|
3746 | 1. At the beginning of a regular expression
|
---|
3747 |
|
---|
3748 | 2. After an open-group, signified by `\('
|
---|
3749 |
|
---|
3750 | 3. After the alternation operator `\|'
|
---|
3751 |
|
---|
3752 |
|
---|
3753 | The longest possible match is returned; this applies to the regular
|
---|
3754 | expression as a whole and (subject to this constraint) to
|
---|
3755 | subexpressions within groups.
|
---|
3756 |
|
---|
3757 |
|
---|
3758 | File: find.info, Node: awk regular expression syntax, Next: egrep regular expression syntax, Prev: findutils-default regular expression syntax, Up: Regular Expressions
|
---|
3759 |
|
---|
3760 | 6.5.2 `awk' regular expression syntax
|
---|
3761 | -------------------------------------
|
---|
3762 |
|
---|
3763 | The character `.' matches any single character except the null
|
---|
3764 | character.
|
---|
3765 |
|
---|
3766 | `+'
|
---|
3767 | indicates that the regular expression should match one or more
|
---|
3768 | occurrences of the previous atom or regexp.
|
---|
3769 |
|
---|
3770 | `?'
|
---|
3771 | indicates that the regular expression should match zero or one
|
---|
3772 | occurrence of the previous atom or regexp.
|
---|
3773 |
|
---|
3774 | `\+'
|
---|
3775 | matches a `+'
|
---|
3776 |
|
---|
3777 | `\?'
|
---|
3778 | matches a `?'.
|
---|
3779 |
|
---|
3780 | Bracket expressions are used to match ranges of characters. Bracket
|
---|
3781 | expressions where the range is backward, for example `[z-a]', are
|
---|
3782 | invalid. Within square brackets, `\' can be used to quote the
|
---|
3783 | following character. Character classes are not supported, so for
|
---|
3784 | example you would need to use `[0-9]' instead of `[[:digit:]]'.
|
---|
3785 |
|
---|
3786 | GNU extensions are not supported and so `\w', `\W', `\<', `\>',
|
---|
3787 | `\b', `\B', `\`', and `\'' match `w', `W', `<', `>', `b', `B', ``', and
|
---|
3788 | `'' respectively.
|
---|
3789 |
|
---|
3790 | Grouping is performed with parentheses `()'. An unmatched `)'
|
---|
3791 | matches just itself. A backslash followed by a digit matches that
|
---|
3792 | digit.
|
---|
3793 |
|
---|
3794 | The alternation operator is `|'.
|
---|
3795 |
|
---|
3796 | The characters `^' and `$' always represent the beginning and end of
|
---|
3797 | a string respectively, except within square brackets. Within brackets,
|
---|
3798 | `^' can be used to invert the membership of the character class being
|
---|
3799 | specified.
|
---|
3800 |
|
---|
3801 | `*', `+' and `?' are special at any point in a regular expression
|
---|
3802 | except:
|
---|
3803 | 1. At the beginning of a regular expression
|
---|
3804 |
|
---|
3805 | 2. After an open-group, signified by `('
|
---|
3806 |
|
---|
3807 | 3. After the alternation operator `|'
|
---|
3808 |
|
---|
3809 |
|
---|
3810 | The longest possible match is returned; this applies to the regular
|
---|
3811 | expression as a whole and (subject to this constraint) to
|
---|
3812 | subexpressions within groups.
|
---|
3813 |
|
---|
3814 |
|
---|
3815 | File: find.info, Node: egrep regular expression syntax, Next: emacs regular expression syntax, Prev: awk regular expression syntax, Up: Regular Expressions
|
---|
3816 |
|
---|
3817 | 6.5.3 `egrep' regular expression syntax
|
---|
3818 | ---------------------------------------
|
---|
3819 |
|
---|
3820 | The character `.' matches any single character except newline.
|
---|
3821 |
|
---|
3822 | `+'
|
---|
3823 | indicates that the regular expression should match one or more
|
---|
3824 | occurrences of the previous atom or regexp.
|
---|
3825 |
|
---|
3826 | `?'
|
---|
3827 | indicates that the regular expression should match zero or one
|
---|
3828 | occurrence of the previous atom or regexp.
|
---|
3829 |
|
---|
3830 | `\+'
|
---|
3831 | matches a `+'
|
---|
3832 |
|
---|
3833 | `\?'
|
---|
3834 | matches a `?'.
|
---|
3835 |
|
---|
3836 | Bracket expressions are used to match ranges of characters. Bracket
|
---|
3837 | expressions where the range is backward, for example `[z-a]', are
|
---|
3838 | ignored. Within square brackets, `\' is taken literally. Character
|
---|
3839 | classes are supported; for example `[[:digit:]]' will match a single
|
---|
3840 | decimal digit. Non-matching lists `[^...]' do not ever match newline.
|
---|
3841 |
|
---|
3842 | GNU extensions are supported:
|
---|
3843 | 1. `\w' matches a character within a word
|
---|
3844 |
|
---|
3845 | 2. `\W' matches a character which is not within a word
|
---|
3846 |
|
---|
3847 | 3. `\<' matches the beginning of a word
|
---|
3848 |
|
---|
3849 | 4. `\>' matches the end of a word
|
---|
3850 |
|
---|
3851 | 5. `\b' matches a word boundary
|
---|
3852 |
|
---|
3853 | 6. `\B' matches characters which are not a word boundary
|
---|
3854 |
|
---|
3855 | 7. `\`' matches the beginning of the whole input
|
---|
3856 |
|
---|
3857 | 8. `\'' matches the end of the whole input
|
---|
3858 |
|
---|
3859 |
|
---|
3860 | Grouping is performed with parentheses `()'. A backslash followed
|
---|
3861 | by a digit acts as a back-reference and matches the same thing as the
|
---|
3862 | previous grouped expression indicated by that number. For example `\2'
|
---|
3863 | matches the second group expression. The order of group expressions is
|
---|
3864 | determined by the position of their opening parenthesis `('.
|
---|
3865 |
|
---|
3866 | The alternation operator is `|'.
|
---|
3867 |
|
---|
3868 | The characters `^' and `$' always represent the beginning and end of
|
---|
3869 | a string respectively, except within square brackets. Within brackets,
|
---|
3870 | `^' can be used to invert the membership of the character class being
|
---|
3871 | specified.
|
---|
3872 |
|
---|
3873 | The characters `*', `+' and `?' are special anywhere in a regular
|
---|
3874 | expression.
|
---|
3875 |
|
---|
3876 | The longest possible match is returned; this applies to the regular
|
---|
3877 | expression as a whole and (subject to this constraint) to
|
---|
3878 | subexpressions within groups.
|
---|
3879 |
|
---|
3880 |
|
---|
3881 | File: find.info, Node: emacs regular expression syntax, Next: gnu-awk regular expression syntax, Prev: egrep regular expression syntax, Up: Regular Expressions
|
---|
3882 |
|
---|
3883 | 6.5.4 `emacs' regular expression syntax
|
---|
3884 | ---------------------------------------
|
---|
3885 |
|
---|
3886 | The character `.' matches any single character except newline.
|
---|
3887 |
|
---|
3888 | `+'
|
---|
3889 | indicates that the regular expression should match one or more
|
---|
3890 | occurrences of the previous atom or regexp.
|
---|
3891 |
|
---|
3892 | `?'
|
---|
3893 | indicates that the regular expression should match zero or one
|
---|
3894 | occurrence of the previous atom or regexp.
|
---|
3895 |
|
---|
3896 | `\+'
|
---|
3897 | matches a `+'
|
---|
3898 |
|
---|
3899 | `\?'
|
---|
3900 | matches a `?'.
|
---|
3901 |
|
---|
3902 | Bracket expressions are used to match ranges of characters. Bracket
|
---|
3903 | expressions where the range is backward, for example `[z-a]', are
|
---|
3904 | ignored. Within square brackets, `\' is taken literally. Character
|
---|
3905 | classes are not supported, so for example you would need to use `[0-9]'
|
---|
3906 | instead of `[[:digit:]]'.
|
---|
3907 |
|
---|
3908 | GNU extensions are supported:
|
---|
3909 | 1. `\w' matches a character within a word
|
---|
3910 |
|
---|
3911 | 2. `\W' matches a character which is not within a word
|
---|
3912 |
|
---|
3913 | 3. `\<' matches the beginning of a word
|
---|
3914 |
|
---|
3915 | 4. `\>' matches the end of a word
|
---|
3916 |
|
---|
3917 | 5. `\b' matches a word boundary
|
---|
3918 |
|
---|
3919 | 6. `\B' matches characters which are not a word boundary
|
---|
3920 |
|
---|
3921 | 7. `\`' matches the beginning of the whole input
|
---|
3922 |
|
---|
3923 | 8. `\'' matches the end of the whole input
|
---|
3924 |
|
---|
3925 |
|
---|
3926 | Grouping is performed with backslashes followed by parentheses `\(',
|
---|
3927 | `\)'. A backslash followed by a digit acts as a back-reference and
|
---|
3928 | matches the same thing as the previous grouped expression indicated by
|
---|
3929 | that number. For example `\2' matches the second group expression.
|
---|
3930 | The order of group expressions is determined by the position of their
|
---|
3931 | opening parenthesis `\('.
|
---|
3932 |
|
---|
3933 | The alternation operator is `\|'.
|
---|
3934 |
|
---|
3935 | The character `^' only represents the beginning of a string when it
|
---|
3936 | appears:
|
---|
3937 | 1. At the beginning of a regular expression
|
---|
3938 |
|
---|
3939 | 2. After an open-group, signified by `\('
|
---|
3940 |
|
---|
3941 | 3. After the alternation operator `\|'
|
---|
3942 |
|
---|
3943 |
|
---|
3944 | The character `$' only represents the end of a string when it
|
---|
3945 | appears:
|
---|
3946 | 1. At the end of a regular expression
|
---|
3947 |
|
---|
3948 | 2. Before an close-group, signified by `\)'
|
---|
3949 |
|
---|
3950 | 3. Before the alternation operator `\|'
|
---|
3951 |
|
---|
3952 |
|
---|
3953 | `*', `+' and `?' are special at any point in a regular expression
|
---|
3954 | except:
|
---|
3955 | 1. At the beginning of a regular expression
|
---|
3956 |
|
---|
3957 | 2. After an open-group, signified by `\('
|
---|
3958 |
|
---|
3959 | 3. After the alternation operator `\|'
|
---|
3960 |
|
---|
3961 |
|
---|
3962 | The longest possible match is returned; this applies to the regular
|
---|
3963 | expression as a whole and (subject to this constraint) to
|
---|
3964 | subexpressions within groups.
|
---|
3965 |
|
---|
3966 |
|
---|
3967 | File: find.info, Node: gnu-awk regular expression syntax, Next: grep regular expression syntax, Prev: emacs regular expression syntax, Up: Regular Expressions
|
---|
3968 |
|
---|
3969 | 6.5.5 `gnu-awk' regular expression syntax
|
---|
3970 | -----------------------------------------
|
---|
3971 |
|
---|
3972 | The character `.' matches any single character.
|
---|
3973 |
|
---|
3974 | `+'
|
---|
3975 | indicates that the regular expression should match one or more
|
---|
3976 | occurrences of the previous atom or regexp.
|
---|
3977 |
|
---|
3978 | `?'
|
---|
3979 | indicates that the regular expression should match zero or one
|
---|
3980 | occurrence of the previous atom or regexp.
|
---|
3981 |
|
---|
3982 | `\+'
|
---|
3983 | matches a `+'
|
---|
3984 |
|
---|
3985 | `\?'
|
---|
3986 | matches a `?'.
|
---|
3987 |
|
---|
3988 | Bracket expressions are used to match ranges of characters. Bracket
|
---|
3989 | expressions where the range is backward, for example `[z-a]', are
|
---|
3990 | invalid. Within square brackets, `\' can be used to quote the
|
---|
3991 | following character. Character classes are supported; for example
|
---|
3992 | `[[:digit:]]' will match a single decimal digit.
|
---|
3993 |
|
---|
3994 | GNU extensions are supported:
|
---|
3995 | 1. `\w' matches a character within a word
|
---|
3996 |
|
---|
3997 | 2. `\W' matches a character which is not within a word
|
---|
3998 |
|
---|
3999 | 3. `\<' matches the beginning of a word
|
---|
4000 |
|
---|
4001 | 4. `\>' matches the end of a word
|
---|
4002 |
|
---|
4003 | 5. `\b' matches a word boundary
|
---|
4004 |
|
---|
4005 | 6. `\B' matches characters which are not a word boundary
|
---|
4006 |
|
---|
4007 | 7. `\`' matches the beginning of the whole input
|
---|
4008 |
|
---|
4009 | 8. `\'' matches the end of the whole input
|
---|
4010 |
|
---|
4011 |
|
---|
4012 | Grouping is performed with parentheses `()'. An unmatched `)'
|
---|
4013 | matches just itself. A backslash followed by a digit acts as a
|
---|
4014 | back-reference and matches the same thing as the previous grouped
|
---|
4015 | expression indicated by that number. For example `\2' matches the
|
---|
4016 | second group expression. The order of group expressions is determined
|
---|
4017 | by the position of their opening parenthesis `('.
|
---|
4018 |
|
---|
4019 | The alternation operator is `|'.
|
---|
4020 |
|
---|
4021 | The characters `^' and `$' always represent the beginning and end of
|
---|
4022 | a string respectively, except within square brackets. Within brackets,
|
---|
4023 | `^' can be used to invert the membership of the character class being
|
---|
4024 | specified.
|
---|
4025 |
|
---|
4026 | `*', `+' and `?' are special at any point in a regular expression
|
---|
4027 | except:
|
---|
4028 | 1. At the beginning of a regular expression
|
---|
4029 |
|
---|
4030 | 2. After an open-group, signified by `('
|
---|
4031 |
|
---|
4032 | 3. After the alternation operator `|'
|
---|
4033 |
|
---|
4034 |
|
---|
4035 | The longest possible match is returned; this applies to the regular
|
---|
4036 | expression as a whole and (subject to this constraint) to
|
---|
4037 | subexpressions within groups.
|
---|
4038 |
|
---|
4039 |
|
---|
4040 | File: find.info, Node: grep regular expression syntax, Next: posix-awk regular expression syntax, Prev: gnu-awk regular expression syntax, Up: Regular Expressions
|
---|
4041 |
|
---|
4042 | 6.5.6 `grep' regular expression syntax
|
---|
4043 | --------------------------------------
|
---|
4044 |
|
---|
4045 | The character `.' matches any single character except newline.
|
---|
4046 |
|
---|
4047 | `\+'
|
---|
4048 | indicates that the regular expression should match one or more
|
---|
4049 | occurrences of the previous atom or regexp.
|
---|
4050 |
|
---|
4051 | `\?'
|
---|
4052 | indicates that the regular expression should match zero or one
|
---|
4053 | occurrence of the previous atom or regexp.
|
---|
4054 |
|
---|
4055 | `+ and ?'
|
---|
4056 | match themselves.
|
---|
4057 |
|
---|
4058 | Bracket expressions are used to match ranges of characters. Bracket
|
---|
4059 | expressions where the range is backward, for example `[z-a]', are
|
---|
4060 | ignored. Within square brackets, `\' is taken literally. Character
|
---|
4061 | classes are supported; for example `[[:digit:]]' will match a single
|
---|
4062 | decimal digit. Non-matching lists `[^...]' do not ever match newline.
|
---|
4063 |
|
---|
4064 | GNU extensions are supported:
|
---|
4065 | 1. `\w' matches a character within a word
|
---|
4066 |
|
---|
4067 | 2. `\W' matches a character which is not within a word
|
---|
4068 |
|
---|
4069 | 3. `\<' matches the beginning of a word
|
---|
4070 |
|
---|
4071 | 4. `\>' matches the end of a word
|
---|
4072 |
|
---|
4073 | 5. `\b' matches a word boundary
|
---|
4074 |
|
---|
4075 | 6. `\B' matches characters which are not a word boundary
|
---|
4076 |
|
---|
4077 | 7. `\`' matches the beginning of the whole input
|
---|
4078 |
|
---|
4079 | 8. `\'' matches the end of the whole input
|
---|
4080 |
|
---|
4081 |
|
---|
4082 | Grouping is performed with backslashes followed by parentheses `\(',
|
---|
4083 | `\)'. A backslash followed by a digit acts as a back-reference and
|
---|
4084 | matches the same thing as the previous grouped expression indicated by
|
---|
4085 | that number. For example `\2' matches the second group expression.
|
---|
4086 | The order of group expressions is determined by the position of their
|
---|
4087 | opening parenthesis `\('.
|
---|
4088 |
|
---|
4089 | The alternation operator is `\|'.
|
---|
4090 |
|
---|
4091 | The character `^' only represents the beginning of a string when it
|
---|
4092 | appears:
|
---|
4093 | 1. At the beginning of a regular expression
|
---|
4094 |
|
---|
4095 | 2. After an open-group, signified by `\('
|
---|
4096 |
|
---|
4097 | 3. After a newline
|
---|
4098 |
|
---|
4099 | 4. After the alternation operator `\|'
|
---|
4100 |
|
---|
4101 |
|
---|
4102 | The character `$' only represents the end of a string when it
|
---|
4103 | appears:
|
---|
4104 | 1. At the end of a regular expression
|
---|
4105 |
|
---|
4106 | 2. Before an close-group, signified by `\)'
|
---|
4107 |
|
---|
4108 | 3. Before a newline
|
---|
4109 |
|
---|
4110 | 4. Before the alternation operator `\|'
|
---|
4111 |
|
---|
4112 |
|
---|
4113 | `\*', `\+' and `\?' are special at any point in a regular expression
|
---|
4114 | except:
|
---|
4115 | 1. At the beginning of a regular expression
|
---|
4116 |
|
---|
4117 | 2. After an open-group, signified by `\('
|
---|
4118 |
|
---|
4119 | 3. After a newline
|
---|
4120 |
|
---|
4121 | 4. After the alternation operator `\|'
|
---|
4122 |
|
---|
4123 |
|
---|
4124 | Intervals are specified by `\{' and `\}'. Invalid intervals such as
|
---|
4125 | `a\{1z' are not accepted.
|
---|
4126 |
|
---|
4127 | The longest possible match is returned; this applies to the regular
|
---|
4128 | expression as a whole and (subject to this constraint) to
|
---|
4129 | subexpressions within groups.
|
---|
4130 |
|
---|
4131 |
|
---|
4132 | File: find.info, Node: posix-awk regular expression syntax, Next: posix-basic regular expression syntax, Prev: grep regular expression syntax, Up: Regular Expressions
|
---|
4133 |
|
---|
4134 | 6.5.7 `posix-awk' regular expression syntax
|
---|
4135 | -------------------------------------------
|
---|
4136 |
|
---|
4137 | The character `.' matches any single character except the null
|
---|
4138 | character.
|
---|
4139 |
|
---|
4140 | `+'
|
---|
4141 | indicates that the regular expression should match one or more
|
---|
4142 | occurrences of the previous atom or regexp.
|
---|
4143 |
|
---|
4144 | `?'
|
---|
4145 | indicates that the regular expression should match zero or one
|
---|
4146 | occurrence of the previous atom or regexp.
|
---|
4147 |
|
---|
4148 | `\+'
|
---|
4149 | matches a `+'
|
---|
4150 |
|
---|
4151 | `\?'
|
---|
4152 | matches a `?'.
|
---|
4153 |
|
---|
4154 | Bracket expressions are used to match ranges of characters. Bracket
|
---|
4155 | expressions where the range is backward, for example `[z-a]', are
|
---|
4156 | invalid. Within square brackets, `\' can be used to quote the
|
---|
4157 | following character. Character classes are supported; for example
|
---|
4158 | `[[:digit:]]' will match a single decimal digit.
|
---|
4159 |
|
---|
4160 | GNU extensions are not supported and so `\w', `\W', `\<', `\>',
|
---|
4161 | `\b', `\B', `\`', and `\'' match `w', `W', `<', `>', `b', `B', ``', and
|
---|
4162 | `'' respectively.
|
---|
4163 |
|
---|
4164 | Grouping is performed with parentheses `()'. An unmatched `)'
|
---|
4165 | matches just itself. A backslash followed by a digit acts as a
|
---|
4166 | back-reference and matches the same thing as the previous grouped
|
---|
4167 | expression indicated by that number. For example `\2' matches the
|
---|
4168 | second group expression. The order of group expressions is determined
|
---|
4169 | by the position of their opening parenthesis `('.
|
---|
4170 |
|
---|
4171 | The alternation operator is `|'.
|
---|
4172 |
|
---|
4173 | The characters `^' and `$' always represent the beginning and end of
|
---|
4174 | a string respectively, except within square brackets. Within brackets,
|
---|
4175 | `^' can be used to invert the membership of the character class being
|
---|
4176 | specified.
|
---|
4177 |
|
---|
4178 | `*', `+' and `?' are special at any point in a regular expression
|
---|
4179 | except the following places, where they are not allowed:
|
---|
4180 | 1. At the beginning of a regular expression
|
---|
4181 |
|
---|
4182 | 2. After an open-group, signified by `('
|
---|
4183 |
|
---|
4184 | 3. After the alternation operator `|'
|
---|
4185 |
|
---|
4186 |
|
---|
4187 | Intervals are specified by `{' and `}'. Invalid intervals such as
|
---|
4188 | `a{1z' are not accepted.
|
---|
4189 |
|
---|
4190 | The longest possible match is returned; this applies to the regular
|
---|
4191 | expression as a whole and (subject to this constraint) to
|
---|
4192 | subexpressions within groups.
|
---|
4193 |
|
---|
4194 |
|
---|
4195 | File: find.info, Node: posix-basic regular expression syntax, Next: posix-egrep regular expression syntax, Prev: posix-awk regular expression syntax, Up: Regular Expressions
|
---|
4196 |
|
---|
4197 | 6.5.8 `posix-basic' regular expression syntax
|
---|
4198 | ---------------------------------------------
|
---|
4199 |
|
---|
4200 | The character `.' matches any single character except the null
|
---|
4201 | character.
|
---|
4202 |
|
---|
4203 | `\+'
|
---|
4204 | indicates that the regular expression should match one or more
|
---|
4205 | occurrences of the previous atom or regexp.
|
---|
4206 |
|
---|
4207 | `\?'
|
---|
4208 | indicates that the regular expression should match zero or one
|
---|
4209 | occurrence of the previous atom or regexp.
|
---|
4210 |
|
---|
4211 | `+ and ?'
|
---|
4212 | match themselves.
|
---|
4213 |
|
---|
4214 | Bracket expressions are used to match ranges of characters. Bracket
|
---|
4215 | expressions where the range is backward, for example `[z-a]', are
|
---|
4216 | invalid. Within square brackets, `\' is taken literally. Character
|
---|
4217 | classes are supported; for example `[[:digit:]]' will match a single
|
---|
4218 | decimal digit.
|
---|
4219 |
|
---|
4220 | GNU extensions are supported:
|
---|
4221 | 1. `\w' matches a character within a word
|
---|
4222 |
|
---|
4223 | 2. `\W' matches a character which is not within a word
|
---|
4224 |
|
---|
4225 | 3. `\<' matches the beginning of a word
|
---|
4226 |
|
---|
4227 | 4. `\>' matches the end of a word
|
---|
4228 |
|
---|
4229 | 5. `\b' matches a word boundary
|
---|
4230 |
|
---|
4231 | 6. `\B' matches characters which are not a word boundary
|
---|
4232 |
|
---|
4233 | 7. `\`' matches the beginning of the whole input
|
---|
4234 |
|
---|
4235 | 8. `\'' matches the end of the whole input
|
---|
4236 |
|
---|
4237 |
|
---|
4238 | Grouping is performed with backslashes followed by parentheses `\(',
|
---|
4239 | `\)'. A backslash followed by a digit acts as a back-reference and
|
---|
4240 | matches the same thing as the previous grouped expression indicated by
|
---|
4241 | that number. For example `\2' matches the second group expression.
|
---|
4242 | The order of group expressions is determined by the position of their
|
---|
4243 | opening parenthesis `\('.
|
---|
4244 |
|
---|
4245 | The alternation operator is `\|'.
|
---|
4246 |
|
---|
4247 | The character `^' only represents the beginning of a string when it
|
---|
4248 | appears:
|
---|
4249 | 1. At the beginning of a regular expression
|
---|
4250 |
|
---|
4251 | 2. After an open-group, signified by `\('
|
---|
4252 |
|
---|
4253 | 3. After the alternation operator `\|'
|
---|
4254 |
|
---|
4255 |
|
---|
4256 | The character `$' only represents the end of a string when it
|
---|
4257 | appears:
|
---|
4258 | 1. At the end of a regular expression
|
---|
4259 |
|
---|
4260 | 2. Before an close-group, signified by `\)'
|
---|
4261 |
|
---|
4262 | 3. Before the alternation operator `\|'
|
---|
4263 |
|
---|
4264 |
|
---|
4265 | `\*', `\+' and `\?' are special at any point in a regular expression
|
---|
4266 | except:
|
---|
4267 | 1. At the beginning of a regular expression
|
---|
4268 |
|
---|
4269 | 2. After an open-group, signified by `\('
|
---|
4270 |
|
---|
4271 | 3. After the alternation operator `\|'
|
---|
4272 |
|
---|
4273 |
|
---|
4274 | Intervals are specified by `\{' and `\}'. Invalid intervals such as
|
---|
4275 | `a\{1z' are not accepted.
|
---|
4276 |
|
---|
4277 | The longest possible match is returned; this applies to the regular
|
---|
4278 | expression as a whole and (subject to this constraint) to
|
---|
4279 | subexpressions within groups.
|
---|
4280 |
|
---|
4281 |
|
---|
4282 | File: find.info, Node: posix-egrep regular expression syntax, Next: posix-extended regular expression syntax, Prev: posix-basic regular expression syntax, Up: Regular Expressions
|
---|
4283 |
|
---|
4284 | 6.5.9 `posix-egrep' regular expression syntax
|
---|
4285 | ---------------------------------------------
|
---|
4286 |
|
---|
4287 | The character `.' matches any single character except newline.
|
---|
4288 |
|
---|
4289 | `+'
|
---|
4290 | indicates that the regular expression should match one or more
|
---|
4291 | occurrences of the previous atom or regexp.
|
---|
4292 |
|
---|
4293 | `?'
|
---|
4294 | indicates that the regular expression should match zero or one
|
---|
4295 | occurrence of the previous atom or regexp.
|
---|
4296 |
|
---|
4297 | `\+'
|
---|
4298 | matches a `+'
|
---|
4299 |
|
---|
4300 | `\?'
|
---|
4301 | matches a `?'.
|
---|
4302 |
|
---|
4303 | Bracket expressions are used to match ranges of characters. Bracket
|
---|
4304 | expressions where the range is backward, for example `[z-a]', are
|
---|
4305 | ignored. Within square brackets, `\' is taken literally. Character
|
---|
4306 | classes are supported; for example `[[:digit:]]' will match a single
|
---|
4307 | decimal digit. Non-matching lists `[^...]' do not ever match newline.
|
---|
4308 |
|
---|
4309 | GNU extensions are supported:
|
---|
4310 | 1. `\w' matches a character within a word
|
---|
4311 |
|
---|
4312 | 2. `\W' matches a character which is not within a word
|
---|
4313 |
|
---|
4314 | 3. `\<' matches the beginning of a word
|
---|
4315 |
|
---|
4316 | 4. `\>' matches the end of a word
|
---|
4317 |
|
---|
4318 | 5. `\b' matches a word boundary
|
---|
4319 |
|
---|
4320 | 6. `\B' matches characters which are not a word boundary
|
---|
4321 |
|
---|
4322 | 7. `\`' matches the beginning of the whole input
|
---|
4323 |
|
---|
4324 | 8. `\'' matches the end of the whole input
|
---|
4325 |
|
---|
4326 |
|
---|
4327 | Grouping is performed with parentheses `()'. A backslash followed
|
---|
4328 | by a digit acts as a back-reference and matches the same thing as the
|
---|
4329 | previous grouped expression indicated by that number. For example `\2'
|
---|
4330 | matches the second group expression. The order of group expressions is
|
---|
4331 | determined by the position of their opening parenthesis `('.
|
---|
4332 |
|
---|
4333 | The alternation operator is `|'.
|
---|
4334 |
|
---|
4335 | The characters `^' and `$' always represent the beginning and end of
|
---|
4336 | a string respectively, except within square brackets. Within brackets,
|
---|
4337 | `^' can be used to invert the membership of the character class being
|
---|
4338 | specified.
|
---|
4339 |
|
---|
4340 | The characters `*', `+' and `?' are special anywhere in a regular
|
---|
4341 | expression.
|
---|
4342 |
|
---|
4343 | Intervals are specified by `{' and `}'. Invalid intervals are
|
---|
4344 | treated as literals, for example `a{1' is treated as `a\{1'
|
---|
4345 |
|
---|
4346 | The longest possible match is returned; this applies to the regular
|
---|
4347 | expression as a whole and (subject to this constraint) to
|
---|
4348 | subexpressions within groups.
|
---|
4349 |
|
---|
4350 |
|
---|
4351 | File: find.info, Node: posix-extended regular expression syntax, Prev: posix-egrep regular expression syntax, Up: Regular Expressions
|
---|
4352 |
|
---|
4353 | 6.5.10 `posix-extended' regular expression syntax
|
---|
4354 | -------------------------------------------------
|
---|
4355 |
|
---|
4356 | The character `.' matches any single character except the null
|
---|
4357 | character.
|
---|
4358 |
|
---|
4359 | `+'
|
---|
4360 | indicates that the regular expression should match one or more
|
---|
4361 | occurrences of the previous atom or regexp.
|
---|
4362 |
|
---|
4363 | `?'
|
---|
4364 | indicates that the regular expression should match zero or one
|
---|
4365 | occurrence of the previous atom or regexp.
|
---|
4366 |
|
---|
4367 | `\+'
|
---|
4368 | matches a `+'
|
---|
4369 |
|
---|
4370 | `\?'
|
---|
4371 | matches a `?'.
|
---|
4372 |
|
---|
4373 | Bracket expressions are used to match ranges of characters. Bracket
|
---|
4374 | expressions where the range is backward, for example `[z-a]', are
|
---|
4375 | invalid. Within square brackets, `\' is taken literally. Character
|
---|
4376 | classes are supported; for example `[[:digit:]]' will match a single
|
---|
4377 | decimal digit.
|
---|
4378 |
|
---|
4379 | GNU extensions are supported:
|
---|
4380 | 1. `\w' matches a character within a word
|
---|
4381 |
|
---|
4382 | 2. `\W' matches a character which is not within a word
|
---|
4383 |
|
---|
4384 | 3. `\<' matches the beginning of a word
|
---|
4385 |
|
---|
4386 | 4. `\>' matches the end of a word
|
---|
4387 |
|
---|
4388 | 5. `\b' matches a word boundary
|
---|
4389 |
|
---|
4390 | 6. `\B' matches characters which are not a word boundary
|
---|
4391 |
|
---|
4392 | 7. `\`' matches the beginning of the whole input
|
---|
4393 |
|
---|
4394 | 8. `\'' matches the end of the whole input
|
---|
4395 |
|
---|
4396 |
|
---|
4397 | Grouping is performed with parentheses `()'. An unmatched `)'
|
---|
4398 | matches just itself. A backslash followed by a digit acts as a
|
---|
4399 | back-reference and matches the same thing as the previous grouped
|
---|
4400 | expression indicated by that number. For example `\2' matches the
|
---|
4401 | second group expression. The order of group expressions is determined
|
---|
4402 | by the position of their opening parenthesis `('.
|
---|
4403 |
|
---|
4404 | The alternation operator is `|'.
|
---|
4405 |
|
---|
4406 | The characters `^' and `$' always represent the beginning and end of
|
---|
4407 | a string respectively, except within square brackets. Within brackets,
|
---|
4408 | `^' can be used to invert the membership of the character class being
|
---|
4409 | specified.
|
---|
4410 |
|
---|
4411 | `*', `+' and `?' are special at any point in a regular expression
|
---|
4412 | except the following places, where they are not allowed:
|
---|
4413 | 1. At the beginning of a regular expression
|
---|
4414 |
|
---|
4415 | 2. After an open-group, signified by `('
|
---|
4416 |
|
---|
4417 | 3. After the alternation operator `|'
|
---|
4418 |
|
---|
4419 |
|
---|
4420 | Intervals are specified by `{' and `}'. Invalid intervals such as
|
---|
4421 | `a{1z' are not accepted.
|
---|
4422 |
|
---|
4423 | The longest possible match is returned; this applies to the regular
|
---|
4424 | expression as a whole and (subject to this constraint) to
|
---|
4425 | subexpressions within groups.
|
---|
4426 |
|
---|
4427 |
|
---|
4428 | File: find.info, Node: Environment Variables, Prev: Regular Expressions, Up: Reference
|
---|
4429 |
|
---|
4430 | 6.6 Environment Variables
|
---|
4431 | =========================
|
---|
4432 |
|
---|
4433 | LANG
|
---|
4434 | Provides a default value for the internationalisation variables
|
---|
4435 | that are unset or null.
|
---|
4436 |
|
---|
4437 | LC_ALL
|
---|
4438 | If set to a non-empty string value, override the values of all the
|
---|
4439 | other internationalisation variables.
|
---|
4440 |
|
---|
4441 | LC_COLLATE
|
---|
4442 | The POSIX standard specifies that this variable affects the pattern
|
---|
4443 | matching to be used for the `\-name' option. GNU find uses the
|
---|
4444 | GNU version of the `fnmatch' library function.
|
---|
4445 |
|
---|
4446 | POSIX also specifies that the `LC_COLLATE' environment variable
|
---|
4447 | affects the interpretation of the user's response to the query
|
---|
4448 | issued by `\-ok', but this is not the case for GNU find.
|
---|
4449 |
|
---|
4450 | LC_CTYPE
|
---|
4451 | This variable affects the treatment of character classes used with
|
---|
4452 | the `-name' test, if the system's `fnmatch' library function
|
---|
4453 | supports this. It has no effect on the behaviour of the `-ok'
|
---|
4454 | expression.
|
---|
4455 |
|
---|
4456 | LC_MESSAGES
|
---|
4457 | Determines the locale to be used for internationalised messages.
|
---|
4458 |
|
---|
4459 | NLSPATH
|
---|
4460 | Determines the location of the internationalisation message
|
---|
4461 | catalogues.
|
---|
4462 |
|
---|
4463 | PATH
|
---|
4464 | Affects the directories which are searched to find the executables
|
---|
4465 | invoked by `-exec', `-execdir' `-ok' and `-okdir'. If the PATH
|
---|
4466 | environment variable includes the current directory (by explicitly
|
---|
4467 | including `.' or by having an empty element), and the find command
|
---|
4468 | line includes `-execdir' or `-okdir', `find' will refuse to run.
|
---|
4469 | *Note Security Considerations::, for a more detailed discussion of
|
---|
4470 | security matters.
|
---|
4471 |
|
---|
4472 | POSIXLY_CORRECT
|
---|
4473 | Determines the block size used by `-ls' and `-fls'. If
|
---|
4474 | POSIXLY_CORRECT is set, blocks are units of 512 bytes. Otherwise
|
---|
4475 | they are units of 1024 bytes.
|
---|
4476 |
|
---|
4477 | TZ
|
---|
4478 | Affects the time zone used for some of the time-related format
|
---|
4479 | directives of `-printf' and `-fprintf'.
|
---|
4480 |
|
---|
4481 |
|
---|
4482 | File: find.info, Node: Common Tasks, Next: Worked Examples, Prev: Reference, Up: Top
|
---|
4483 |
|
---|
4484 | 7 Common Tasks
|
---|
4485 | **************
|
---|
4486 |
|
---|
4487 | The sections that follow contain some extended examples that both give
|
---|
4488 | a good idea of the power of these programs, and show you how to solve
|
---|
4489 | common real-world problems.
|
---|
4490 |
|
---|
4491 | * Menu:
|
---|
4492 |
|
---|
4493 | * Viewing And Editing::
|
---|
4494 | * Archiving::
|
---|
4495 | * Cleaning Up::
|
---|
4496 | * Strange File Names::
|
---|
4497 | * Fixing Permissions::
|
---|
4498 | * Classifying Files::
|
---|
4499 |
|
---|
4500 |
|
---|
4501 | File: find.info, Node: Viewing And Editing, Next: Archiving, Up: Common Tasks
|
---|
4502 |
|
---|
4503 | 7.1 Viewing And Editing
|
---|
4504 | =======================
|
---|
4505 |
|
---|
4506 | To view a list of files that meet certain criteria, simply run your
|
---|
4507 | file viewing program with the file names as arguments. Shells
|
---|
4508 | substitute a command enclosed in backquotes with its output, so the
|
---|
4509 | whole command looks like this:
|
---|
4510 |
|
---|
4511 | less `find /usr/include -name '*.h' | xargs grep -l mode_t`
|
---|
4512 |
|
---|
4513 | You can edit those files by giving an editor name instead of a file
|
---|
4514 | viewing program:
|
---|
4515 |
|
---|
4516 | emacs `find /usr/include -name '*.h' | xargs grep -l mode_t`
|
---|
4517 |
|
---|
4518 | Because there is a limit to the length of any individual command
|
---|
4519 | line, there is a limit to the number of files that can be handled in
|
---|
4520 | this way. We can get around this difficulty by using xargs like this:
|
---|
4521 |
|
---|
4522 | find /usr/include -name '*.h' | xargs grep -l mode_t > todo
|
---|
4523 | xargs --arg-file=todo emacs
|
---|
4524 |
|
---|
4525 | Here, `xargs' will run `emacs' as many times as necessary to visit
|
---|
4526 | all of the files listed in the file `todo'.
|
---|
4527 |
|
---|
4528 |
|
---|
4529 | File: find.info, Node: Archiving, Next: Cleaning Up, Prev: Viewing And Editing, Up: Common Tasks
|
---|
4530 |
|
---|
4531 | 7.2 Archiving
|
---|
4532 | =============
|
---|
4533 |
|
---|
4534 | You can pass a list of files produced by `find' to a file archiving
|
---|
4535 | program. GNU `tar' and `cpio' can both read lists of file names from
|
---|
4536 | the standard input--either delimited by nulls (the safe way) or by
|
---|
4537 | blanks (the lazy, risky default way). To use null-delimited names,
|
---|
4538 | give them the `--null' option. You can store a file archive in a file,
|
---|
4539 | write it on a tape, or send it over a network to extract on another
|
---|
4540 | machine.
|
---|
4541 |
|
---|
4542 | One common use of `find' to archive files is to send a list of the
|
---|
4543 | files in a directory tree to `cpio'. Use `-depth' so if a directory
|
---|
4544 | does not have write permission for its owner, its contents can still be
|
---|
4545 | restored from the archive since the directory's permissions are
|
---|
4546 | restored after its contents. Here is an example of doing this using
|
---|
4547 | `cpio'; you could use a more complex `find' expression to archive only
|
---|
4548 | certain files.
|
---|
4549 |
|
---|
4550 | find . -depth -print0 |
|
---|
4551 | cpio --create --null --format=crc --file=/dev/nrst0
|
---|
4552 |
|
---|
4553 | You could restore that archive using this command:
|
---|
4554 |
|
---|
4555 | cpio --extract --null --make-dir --unconditional \
|
---|
4556 | --preserve --file=/dev/nrst0
|
---|
4557 |
|
---|
4558 | Here are the commands to do the same things using `tar':
|
---|
4559 |
|
---|
4560 | find . -depth -print0 |
|
---|
4561 | tar --create --null --files-from=- --file=/dev/nrst0
|
---|
4562 |
|
---|
4563 | tar --extract --null --preserve-perm --same-owner \
|
---|
4564 | --file=/dev/nrst0
|
---|
4565 |
|
---|
4566 | Here is an example of copying a directory from one machine to
|
---|
4567 | another:
|
---|
4568 |
|
---|
4569 | find . -depth -print0 | cpio -0o -Hnewc |
|
---|
4570 | rsh OTHER-MACHINE "cd `pwd` && cpio -i0dum"
|
---|
4571 |
|
---|
4572 |
|
---|
4573 | File: find.info, Node: Cleaning Up, Next: Strange File Names, Prev: Archiving, Up: Common Tasks
|
---|
4574 |
|
---|
4575 | 7.3 Cleaning Up
|
---|
4576 | ===============
|
---|
4577 |
|
---|
4578 | This section gives examples of removing unwanted files in various
|
---|
4579 | situations. Here is a command to remove the CVS backup files created
|
---|
4580 | when an update requires a merge:
|
---|
4581 |
|
---|
4582 | find . -name '.#*' -print0 | xargs -0r rm -f
|
---|
4583 |
|
---|
4584 | The command above works, but the following is safer:
|
---|
4585 |
|
---|
4586 | find . -name '.#*' -depth -delete
|
---|
4587 |
|
---|
4588 | You can run this command to clean out your clutter in `/tmp'. You
|
---|
4589 | might place it in the file your shell runs when you log out
|
---|
4590 | (`.bash_logout', `.logout', or `.zlogout', depending on which shell you
|
---|
4591 | use).
|
---|
4592 |
|
---|
4593 | find /tmp -depth -user "$LOGNAME" -type f -delete
|
---|
4594 |
|
---|
4595 | If your `find' command removes directories, you may find that you
|
---|
4596 | get a spurious error message when `find' tries to recurse into a
|
---|
4597 | directory that has now been removed. Using the `-depth' option will
|
---|
4598 | normally resolve this problem.
|
---|
4599 |
|
---|
4600 | To remove old Emacs backup and auto-save files, you can use a command
|
---|
4601 | like the following. It is especially important in this case to use
|
---|
4602 | null-terminated file names because Emacs packages like the VM mailer
|
---|
4603 | often create temporary file names with spaces in them, like `#reply to
|
---|
4604 | David J. MacKenzie<1>#'.
|
---|
4605 |
|
---|
4606 | find ~ \( -name '*~' -o -name '#*#' \) -print0 |
|
---|
4607 | xargs --no-run-if-empty --null rm -vf
|
---|
4608 |
|
---|
4609 | Removing old files from `/tmp' is commonly done from `cron':
|
---|
4610 |
|
---|
4611 | find /tmp /var/tmp -not -type d -mtime +3 -delete
|
---|
4612 | find /tmp /var/tmp -depth -mindepth 1 -type d -empty -delete
|
---|
4613 |
|
---|
4614 | The second `find' command above uses `-depth' so it cleans out empty
|
---|
4615 | directories depth-first, hoping that the parents become empty and can
|
---|
4616 | be removed too. It uses `-mindepth' to avoid removing `/tmp' itself if
|
---|
4617 | it becomes totally empty.
|
---|
4618 |
|
---|
4619 |
|
---|
4620 | File: find.info, Node: Strange File Names, Next: Fixing Permissions, Prev: Cleaning Up, Up: Common Tasks
|
---|
4621 |
|
---|
4622 | 7.4 Strange File Names
|
---|
4623 | ======================
|
---|
4624 |
|
---|
4625 | `find' can help you remove or rename a file with strange characters in
|
---|
4626 | its name. People are sometimes stymied by files whose names contain
|
---|
4627 | characters such as spaces, tabs, control characters, or characters with
|
---|
4628 | the high bit set. The simplest way to remove such files is:
|
---|
4629 |
|
---|
4630 | rm -i SOME*PATTERN*THAT*MATCHES*THE*PROBLEM*FILE
|
---|
4631 |
|
---|
4632 | `rm' asks you whether to remove each file matching the given
|
---|
4633 | pattern. If you are using an old shell, this approach might not work
|
---|
4634 | if the file name contains a character with the high bit set; the shell
|
---|
4635 | may strip it off. A more reliable way is:
|
---|
4636 |
|
---|
4637 | find . -maxdepth 1 TESTS -okdir rm '{}' \;
|
---|
4638 |
|
---|
4639 | where TESTS uniquely identify the file. The `-maxdepth 1' option
|
---|
4640 | prevents `find' from wasting time searching for the file in any
|
---|
4641 | subdirectories; if there are no subdirectories, you may omit it. A
|
---|
4642 | good way to uniquely identify the problem file is to figure out its
|
---|
4643 | inode number; use
|
---|
4644 |
|
---|
4645 | ls -i
|
---|
4646 |
|
---|
4647 | Suppose you have a file whose name contains control characters, and
|
---|
4648 | you have found that its inode number is 12345. This command prompts
|
---|
4649 | you for whether to remove it:
|
---|
4650 |
|
---|
4651 | find . -maxdepth 1 -inum 12345 -okdir rm -f '{}' \;
|
---|
4652 |
|
---|
4653 | If you don't want to be asked, perhaps because the file name may
|
---|
4654 | contain a strange character sequence that will mess up your screen when
|
---|
4655 | printed, then use `-execdir' instead of `-okdir'.
|
---|
4656 |
|
---|
4657 | If you want to rename the file instead, you can use `mv' instead of
|
---|
4658 | `rm':
|
---|
4659 |
|
---|
4660 | find . -maxdepth 1 -inum 12345 -okdir mv '{}' NEW-FILE-NAME \;
|
---|
4661 |
|
---|
4662 |
|
---|
4663 | File: find.info, Node: Fixing Permissions, Next: Classifying Files, Prev: Strange File Names, Up: Common Tasks
|
---|
4664 |
|
---|
4665 | 7.5 Fixing Permissions
|
---|
4666 | ======================
|
---|
4667 |
|
---|
4668 | Suppose you want to make sure that everyone can write to the
|
---|
4669 | directories in a certain directory tree. Here is a way to find
|
---|
4670 | directories lacking either user or group write permission (or both),
|
---|
4671 | and fix their permissions:
|
---|
4672 |
|
---|
4673 | find . -type d -not -perm -ug=w | xargs chmod ug+w
|
---|
4674 |
|
---|
4675 | You could also reverse the operations, if you want to make sure that
|
---|
4676 | directories do _not_ have world write permission.
|
---|
4677 |
|
---|
4678 |
|
---|
4679 | File: find.info, Node: Classifying Files, Prev: Fixing Permissions, Up: Common Tasks
|
---|
4680 |
|
---|
4681 | 7.6 Classifying Files
|
---|
4682 | =====================
|
---|
4683 |
|
---|
4684 | If you want to classify a set of files into several groups based on
|
---|
4685 | different criteria, you can use the comma operator to perform multiple
|
---|
4686 | independent tests on the files. Here is an example:
|
---|
4687 |
|
---|
4688 | find / -type d \( -perm -o=w -fprint allwrite , \
|
---|
4689 | -perm -o=x -fprint allexec \)
|
---|
4690 |
|
---|
4691 | echo "Directories that can be written to by everyone:"
|
---|
4692 | cat allwrite
|
---|
4693 | echo ""
|
---|
4694 | echo "Directories with search permissions for everyone:"
|
---|
4695 | cat allexec
|
---|
4696 |
|
---|
4697 | `find' has only to make one scan through the directory tree (which
|
---|
4698 | is one of the most time consuming parts of its work).
|
---|
4699 |
|
---|
4700 |
|
---|
4701 | File: find.info, Node: Worked Examples, Next: Security Considerations, Prev: Common Tasks, Up: Top
|
---|
4702 |
|
---|
4703 | 8 Worked Examples
|
---|
4704 | *****************
|
---|
4705 |
|
---|
4706 | The tools in the findutils package, and in particular `find', have a
|
---|
4707 | large number of options. This means that quite often, there is more
|
---|
4708 | than one way to do things. Some of the options and facilities only
|
---|
4709 | exist for compatibility with other tools, and findutils provides
|
---|
4710 | improved ways of doing things.
|
---|
4711 |
|
---|
4712 | This chapter describes a number of useful tasks that are commonly
|
---|
4713 | performed, and compares the different ways of achieving them.
|
---|
4714 |
|
---|
4715 | * Menu:
|
---|
4716 |
|
---|
4717 | * Deleting Files::
|
---|
4718 | * Updating A Timestamp File::
|
---|
4719 |
|
---|
4720 |
|
---|
4721 | File: find.info, Node: Deleting Files, Next: Updating A Timestamp File, Up: Worked Examples
|
---|
4722 |
|
---|
4723 | 8.1 Deleting Files
|
---|
4724 | ==================
|
---|
4725 |
|
---|
4726 | One of the most common tasks that `find' is used for is locating files
|
---|
4727 | that can be deleted. This might include:
|
---|
4728 |
|
---|
4729 | * Files last modified more than 3 years ago which haven't been
|
---|
4730 | accessed for at least 2 years
|
---|
4731 |
|
---|
4732 | * Files belonging to a certain user
|
---|
4733 |
|
---|
4734 | * Temporary files which are no longer required
|
---|
4735 |
|
---|
4736 | This example concentrates on the actual deletion task rather than on
|
---|
4737 | sophisticated ways of locating the files that need to be deleted.
|
---|
4738 | We'll assume that the files we want to delete are old files underneath
|
---|
4739 | `/var/tmp/stuff'.
|
---|
4740 |
|
---|
4741 | 8.1.1 The Traditional Way
|
---|
4742 | -------------------------
|
---|
4743 |
|
---|
4744 | The traditional way to delete files in `var/tmp/stuff' that have not
|
---|
4745 | been modified in over 90 days would have been:
|
---|
4746 |
|
---|
4747 | find /var/tmp/stuff -mtime +90 -exec /bin/rm {} \;
|
---|
4748 |
|
---|
4749 | The above command uses `-exec' to run the `/bin/rm' command to
|
---|
4750 | remove each file. This approach works and in fact would have worked in
|
---|
4751 | Version 7 Unix in 1979. However, there are a number of problems with
|
---|
4752 | this approach.
|
---|
4753 |
|
---|
4754 | The most obvious problem with the approach above is that it causes
|
---|
4755 | `find' to fork every time it finds a file that needs to delete, and the
|
---|
4756 | child process then has to use the `exec' system call to launch
|
---|
4757 | `/bin/rm'. All this is quite inefficient. If we are going to use
|
---|
4758 | `/bin/rm' to do this job, it is better to make it delete more than one
|
---|
4759 | file at a time.
|
---|
4760 |
|
---|
4761 | The most obvious way of doing this is to use the shell's command
|
---|
4762 | expansion feature:
|
---|
4763 |
|
---|
4764 | /bin/rm `find /var/tmp/stuff -mtime +90 -print`
|
---|
4765 | or you could use the more modern form
|
---|
4766 | /bin/rm $(find /var/tmp/stuff -mtime +90 -print)
|
---|
4767 |
|
---|
4768 | The commands above are much more efficient than the first attempt.
|
---|
4769 | However, there is a problem with them. The shell has a maximum command
|
---|
4770 | length which is imposed by the operating system (the actual limit
|
---|
4771 | varies between systems). This means that while the command expansion
|
---|
4772 | technique will usually work, it will suddenly fail when there are lots
|
---|
4773 | of files to delete. Since the task is to delete unwanted files, this
|
---|
4774 | is precisely the time we don't want things to go wrong.
|
---|
4775 |
|
---|
4776 | 8.1.2 Making Use of xargs
|
---|
4777 | -------------------------
|
---|
4778 |
|
---|
4779 | So, is there a way to be more efficient in the use of `fork()' and
|
---|
4780 | `exec()' without running up against this limit? Yes, we can be almost
|
---|
4781 | optimally efficient by making use of the `xargs' command. The `xargs'
|
---|
4782 | command reads arguments from its standard input and builds them into
|
---|
4783 | command lines. We can use it like this:
|
---|
4784 |
|
---|
4785 | find /var/tmp/stuff -mtime +90 -print | xargs /bin/rm
|
---|
4786 |
|
---|
4787 | For example if the files found by `find' are `/var/tmp/stuff/A',
|
---|
4788 | `/var/tmp/stuff/B' and `/var/tmp/stuff/C' then `xargs' might issue the
|
---|
4789 | commands
|
---|
4790 |
|
---|
4791 | /bin/rm /var/tmp/stuff/A /var/tmp/stuff/B
|
---|
4792 | /bin/rm /var/tmp/stuff/C
|
---|
4793 |
|
---|
4794 | The above assumes that `xargs' has a very small maximum command line
|
---|
4795 | length. The real limit is much larger but the idea is that `xargs'
|
---|
4796 | will run `/bin/rm' as many times as necessary to get the job done,
|
---|
4797 | given the limits on command line length.
|
---|
4798 |
|
---|
4799 | This usage of `xargs' is pretty efficient, and the `xargs' command
|
---|
4800 | is widely implemented (all modern versions of Unix offer it). So far
|
---|
4801 | then, the news is all good. However, there is bad news too.
|
---|
4802 |
|
---|
4803 | 8.1.3 Unusual characters in filenames
|
---|
4804 | -------------------------------------
|
---|
4805 |
|
---|
4806 | Unix-like systems allow any characters to appear in file names with the
|
---|
4807 | exception of the ASCII NUL character and the backslash. Backslashes
|
---|
4808 | can occur in path names (as the directory separator) but not in the
|
---|
4809 | names of actual directory entries. This means that the list of files
|
---|
4810 | that `xargs' reads could in fact contain white space characters --
|
---|
4811 | spaces, tabs and newline characters. Since by default, `xargs' assumes
|
---|
4812 | that the list of files it is reading uses white space as an argument
|
---|
4813 | separator, it cannot correctly handle the case where a filename
|
---|
4814 | actually includes white space. This makes the default behaviour of
|
---|
4815 | `xargs' almost useless for handling arbitrary data.
|
---|
4816 |
|
---|
4817 | To solve this problem, GNU findutils introduced the `-print0' action
|
---|
4818 | for `find'. This uses the ASCII NUL character to separate the entries
|
---|
4819 | in the file list that it produces. This is the ideal choice of
|
---|
4820 | separator since it is the only character that cannot appear within a
|
---|
4821 | path name. The `-0' option to `xargs' makes it assume that arguments
|
---|
4822 | are separated with ASCII NUL instead of white space. It also turns off
|
---|
4823 | another misfeature in the default behaviour of `xargs', which is that
|
---|
4824 | it pays attention to quote characters in its input. Some versions of
|
---|
4825 | `xargs' also terminate when they see a lone `_' in the input, but GNU
|
---|
4826 | `find' no longer does that (since it has become an optional behaviour
|
---|
4827 | in the Unix standard).
|
---|
4828 |
|
---|
4829 | So, putting `find -print0' together with `xargs -0' we get this
|
---|
4830 | command:
|
---|
4831 |
|
---|
4832 | find /var/tmp/stuff -mtime +90 -print0 | xargs -0 /bin/rm
|
---|
4833 |
|
---|
4834 | The result is an efficient way of proceeding that correctly handles
|
---|
4835 | all the possible characters that could appear in the list of files to
|
---|
4836 | delete. This is good news. However, there is, as I'm sure you're
|
---|
4837 | expecting, also more bad news. The problem is that this is not a
|
---|
4838 | portable construct; although other versions of Unix (notable
|
---|
4839 | BSD-derived ones) support `-print0', it's not universal. So, is there
|
---|
4840 | a more universal mechanism?
|
---|
4841 |
|
---|
4842 | 8.1.4 Going back to -exec
|
---|
4843 | -------------------------
|
---|
4844 |
|
---|
4845 | There is indeed a more universal mechanism, which is a slight
|
---|
4846 | modification to the `-exec' action. The normal `-exec' action assumes
|
---|
4847 | that the command to run is terminated with a semicolon (the semicolon
|
---|
4848 | normally has to be quoted in order to protect it from interpretation as
|
---|
4849 | the shell command separator). The SVR4 edition of Unix introduced a
|
---|
4850 | slight variation, which involves terminating the command with `+'
|
---|
4851 | instead:
|
---|
4852 |
|
---|
4853 | find /var/tmp/stuff -mtime +90 -exec /bin/rm {} \+
|
---|
4854 |
|
---|
4855 | The above use of `-exec' causes `find' to build up a long command
|
---|
4856 | line and then issue it. This can be less efficient than some uses of
|
---|
4857 | `xargs'; for example `xargs' allows new command lines to be built up
|
---|
4858 | while the previous command is still executing, and allows you to
|
---|
4859 | specify a number of commands to run in parallel. However, the `find
|
---|
4860 | ... -exec ... +' construct has the advantage of wide portability. GNU
|
---|
4861 | findutils did not support `-exec ... +' until version 4.2.12; one of
|
---|
4862 | the reasons for this is that it already had the `-print0' action in any
|
---|
4863 | case.
|
---|
4864 |
|
---|
4865 | 8.1.5 A more secure version of -exec
|
---|
4866 | ------------------------------------
|
---|
4867 |
|
---|
4868 | The command above seems to be efficient and portable. However, within
|
---|
4869 | it lurks a security problem. The problem is shared with all the
|
---|
4870 | commands we've tried in this worked example so far, too. The security
|
---|
4871 | problem is a race condition; that is, if it is possible for somebody to
|
---|
4872 | manipulate the filesystem that you are searching while you are
|
---|
4873 | searching it, it is possible for them to persuade your `find' command
|
---|
4874 | to cause the deletion of a file that you can delete but they normally
|
---|
4875 | cannot.
|
---|
4876 |
|
---|
4877 | The problem occurs because the `-exec' action is defined by the
|
---|
4878 | POSIX standard to invoke its command with the same working directory as
|
---|
4879 | `find' had when it was started. This means that the arguments which
|
---|
4880 | replace the {} include a relative path from `find''s starting point
|
---|
4881 | down the file that needs to be deleted. For example,
|
---|
4882 |
|
---|
4883 | find /var/tmp/stuff -mtime +90 -exec /bin/rm {} \+
|
---|
4884 |
|
---|
4885 | might actually issue the command:
|
---|
4886 |
|
---|
4887 | /bin/rm /var/tmp/stuff/A /var/tmp/stuff/B /var/tmp/stuff/passwd
|
---|
4888 |
|
---|
4889 | Notice the file `/var/tmp/stuff/passwd'. Likewise, the command:
|
---|
4890 |
|
---|
4891 | cd /var/tmp && find stuff -mtime +90 -exec /bin/rm {} \+
|
---|
4892 |
|
---|
4893 | might actually issue the command:
|
---|
4894 |
|
---|
4895 | /bin/rm stuff/A stuff/B stuff/passwd
|
---|
4896 |
|
---|
4897 | If an attacker can rename `stuff' to something else (making use of
|
---|
4898 | their write permissions in `/var/tmp') they can replace it with a
|
---|
4899 | symbolic link to `/etc'. That means that the `/bin/rm' command will be
|
---|
4900 | invoked on `/etc/passwd'. If you are running your `find' command as
|
---|
4901 | root, the attacker has just managed to delete a vital file. All they
|
---|
4902 | needed to do to achieve this was replace a subdirectory with a symbolic
|
---|
4903 | link at the vital moment.
|
---|
4904 |
|
---|
4905 | There is however, a simple solution to the problem. This is an
|
---|
4906 | action which works a lot like `-exec' but doesn't need to traverse a
|
---|
4907 | chain of directories to reach the file that it needs to work on. This
|
---|
4908 | is the `-execdir' action, which was introduced by the BSD family of
|
---|
4909 | operating systems. The command,
|
---|
4910 |
|
---|
4911 | find /var/tmp/stuff -mtime +90 -execdir /bin/rm {} \+
|
---|
4912 |
|
---|
4913 | might delete a set of files by performing these actions:
|
---|
4914 |
|
---|
4915 | 1. Change directory to /var/tmp/stuff/foo
|
---|
4916 |
|
---|
4917 | 2. Invoke `/bin/rm ./file1 ./file2 ./file3'
|
---|
4918 |
|
---|
4919 | 3. Change directory to /var/tmp/stuff/bar
|
---|
4920 |
|
---|
4921 | 4. Invoke `/bin/rm ./file99 ./file100 ./file101'
|
---|
4922 |
|
---|
4923 | This is a much more secure method. We are no longer exposed to a
|
---|
4924 | race condition. For many typical uses of `find', this is the best
|
---|
4925 | strategy. It's reasonably efficient, but the length of the command
|
---|
4926 | line is limited not just by the operating system limits, but also by
|
---|
4927 | how many files we actually need to delete from each directory.
|
---|
4928 |
|
---|
4929 | Is it possible to do any better? In the case of general file
|
---|
4930 | processing, no. However, in the specific case of deleting files it is
|
---|
4931 | indeed possible to do better.
|
---|
4932 |
|
---|
4933 | 8.1.6 Using the -delete action
|
---|
4934 | ------------------------------
|
---|
4935 |
|
---|
4936 | The most efficient and secure method of solving this problem is to use
|
---|
4937 | the `-delete' action:
|
---|
4938 |
|
---|
4939 | find /var/tmp/stuff -mtime +90 -delete
|
---|
4940 |
|
---|
4941 | This alternative is more efficient than any of the `-exec' or
|
---|
4942 | `-execdir' actions, since it entirely avoids the overhead of forking a
|
---|
4943 | new process and using `exec' to run `/bin/rm'. It is also normally
|
---|
4944 | more efficient than `xargs' for the same reason. The file deletion is
|
---|
4945 | performed from the directory containing the entry to be deleted, so the
|
---|
4946 | `-delete' action has the same security advantages as the `-execdir'
|
---|
4947 | action has.
|
---|
4948 |
|
---|
4949 | The `-delete' action was introduced by the BSD family of operating
|
---|
4950 | systems.
|
---|
4951 |
|
---|
4952 | 8.1.7 Improving things still further
|
---|
4953 | ------------------------------------
|
---|
4954 |
|
---|
4955 | Is it possible to improve things still further? Not without either
|
---|
4956 | modifying the system library to the operating system or having more
|
---|
4957 | specific knowledge of the layout of the filesystem and disk I/O
|
---|
4958 | subsystem, or both.
|
---|
4959 |
|
---|
4960 | The `find' command traverses the filesystem, reading directories.
|
---|
4961 | It then issues a separate system call for each file to be deleted. If
|
---|
4962 | we could modify the operating system, there are potential gains that
|
---|
4963 | could be made:
|
---|
4964 |
|
---|
4965 | * We could have a system call to which we pass more than one filename
|
---|
4966 | for deletion
|
---|
4967 |
|
---|
4968 | * Alternatively, we could pass in a list of inode numbers (on
|
---|
4969 | GNU/Linux systems, `readdir()' also returns the inode number of
|
---|
4970 | each directory entry) to be deleted.
|
---|
4971 |
|
---|
4972 | The above possibilities sound interesting, but from the kernel's
|
---|
4973 | point of view it is difficult to enforce standard Unix access controls
|
---|
4974 | for such processing by inode number. Such a facility would probably
|
---|
4975 | need to be restricted to the superuser.
|
---|
4976 |
|
---|
4977 | Another way of improving performance would be to increase the
|
---|
4978 | parallelism of the process. For example if the directory hierarchy we
|
---|
4979 | are searching is actually spread across a number of disks, we might
|
---|
4980 | somehow be able to arrange for `find' to process each disk in parallel.
|
---|
4981 | In practice GNU `find' doesn't have such an intimate understanding of
|
---|
4982 | the system's filesystem layout and disk I/O subsystem.
|
---|
4983 |
|
---|
4984 | However, since the system administrator can have such an
|
---|
4985 | understanding they can take advantage of it like so:
|
---|
4986 |
|
---|
4987 | find /var/tmp/stuff1 -mtime +90 -delete &
|
---|
4988 | find /var/tmp/stuff2 -mtime +90 -delete &
|
---|
4989 | find /var/tmp/stuff3 -mtime +90 -delete &
|
---|
4990 | find /var/tmp/stuff4 -mtime +90 -delete &
|
---|
4991 | wait
|
---|
4992 |
|
---|
4993 | In the example above, four separate instances of `find' are used to
|
---|
4994 | search four subdirectories in parallel. The `wait' command simply
|
---|
4995 | waits for all of these to complete. Whether this approach is more or
|
---|
4996 | less efficient than a single instance of `find' depends on a number of
|
---|
4997 | things:
|
---|
4998 |
|
---|
4999 | * Are the directories being searched in parallel actually on separate
|
---|
5000 | disks? If not, this parallel search might just result in a lot of
|
---|
5001 | disk head movement and so the speed might even be slower.
|
---|
5002 |
|
---|
5003 | * Other activity - are other programs also doing things on those
|
---|
5004 | disks?
|
---|
5005 |
|
---|
5006 | 8.1.8 Conclusion
|
---|
5007 | ----------------
|
---|
5008 |
|
---|
5009 | The fastest and most secure way to delete files with the help of `find'
|
---|
5010 | is to use `-delete'. Using `xargs -0 -P N' can also make effective use
|
---|
5011 | of the disk, but it is not as secure.
|
---|
5012 |
|
---|
5013 | In the case where we're doing things other than deleting files, the
|
---|
5014 | most secure alternative is `-execdir ... +', but this is not as
|
---|
5015 | portable as the insecure action `-exec ... +'.
|
---|
5016 |
|
---|
5017 | The `-delete' action is not completely portable, but the only other
|
---|
5018 | possibillity which is as secure (`-execdir') is no more portable. The
|
---|
5019 | most efficient portable alternative is `-exec ...+', but this is
|
---|
5020 | insecure and isn't supported by versions of GNU findutils prior to
|
---|
5021 | 4.2.12.
|
---|
5022 |
|
---|
5023 |
|
---|
5024 | File: find.info, Node: Updating A Timestamp File, Prev: Deleting Files, Up: Worked Examples
|
---|
5025 |
|
---|
5026 | 8.2 Updating A Timestamp File
|
---|
5027 | =============================
|
---|
5028 |
|
---|
5029 | Suppose we have a directory full of files which is maintained with a
|
---|
5030 | set of automated tools; perhaps one set of tools updates them and
|
---|
5031 | another set of tools uses the result. In this situation, it might be
|
---|
5032 | useful for the second set of tools to know if the files have recently
|
---|
5033 | been changed. It might be useful, for example, to have a 'timestamp'
|
---|
5034 | file which gives the timestamp on the newest file in the collection.
|
---|
5035 |
|
---|
5036 | We can use `find' to achieve this, but there are several different
|
---|
5037 | ways to do it.
|
---|
5038 |
|
---|
5039 | 8.2.1 Updating the Timestamp The Wrong Way
|
---|
5040 | ------------------------------------------
|
---|
5041 |
|
---|
5042 | The obvious but wrong answer is just to use `-newer':-
|
---|
5043 |
|
---|
5044 | find subdir -newer timestamp -exec touch -r {} timestamp \;
|
---|
5045 |
|
---|
5046 | This does the right sort of thing but has a bug. Suppose that two
|
---|
5047 | files in the subdirectory have been updated, and that these are called
|
---|
5048 | `file1' and `file2'. The command above will update `timestamp' with
|
---|
5049 | the modification time of `file1' or that of `file2', but we don't know
|
---|
5050 | which one. Since the timestamps on `file1' and `file2' will in general
|
---|
5051 | be different, this could well be the wrong value.
|
---|
5052 |
|
---|
5053 | One solution to this problem is to modify `find' to recheck the
|
---|
5054 | modification time of `timestamp' every time a file is to be compared
|
---|
5055 | against it, but that will reduce the performance of `find'.
|
---|
5056 |
|
---|
5057 | 8.2.2 Using the test utility to compare timestamps
|
---|
5058 | --------------------------------------------------
|
---|
5059 |
|
---|
5060 | The `test' command can be used to compare timestamps:
|
---|
5061 |
|
---|
5062 | find subdir -exec test {} -nt timestamp \; -exec touch -r {} timestamp \;
|
---|
5063 |
|
---|
5064 | This will ensure that any changes made to the modification time of
|
---|
5065 | `timestamp' that take place during the execution of `find' are taken
|
---|
5066 | into account. This resolves our earlier problem, but unfortunately
|
---|
5067 | this runs much more slowly.
|
---|
5068 |
|
---|
5069 | 8.2.3 A combined approach
|
---|
5070 | -------------------------
|
---|
5071 |
|
---|
5072 | We can of course still use `-newer' to cut down on the number of calls
|
---|
5073 | to `test':
|
---|
5074 |
|
---|
5075 | find subdir -newer timestamp -a \
|
---|
5076 | -exec test {} -nt timestamp \; -a \
|
---|
5077 | -exec touch -r {} timestamp \;
|
---|
5078 |
|
---|
5079 | Here, the `-newer' test excludes all the files which are definitely
|
---|
5080 | older than the timestamp, but all the files which are newer than the
|
---|
5081 | old value of the timestamp are compared against the current updated
|
---|
5082 | timestamp.
|
---|
5083 |
|
---|
5084 | This is indeed faster in general, but the speed difference will
|
---|
5085 | depend on how many updated files there are.
|
---|
5086 |
|
---|
5087 | 8.2.4 Using -printf and sort to compare timestamps
|
---|
5088 | --------------------------------------------------
|
---|
5089 |
|
---|
5090 | It is possible to use the `-printf' action to abandon the use of `test'
|
---|
5091 | entirely:
|
---|
5092 |
|
---|
5093 | newest=$(find subdir -newer timestamp -printf "%A%p\n" |
|
---|
5094 | sort -n |
|
---|
5095 | tail -1 |
|
---|
5096 | cut -d: -f2- )
|
---|
5097 | touch -r "${newest:-timestamp}" timestamp
|
---|
5098 |
|
---|
5099 | The command above works by generating a list of the timestamps and
|
---|
5100 | names of all the files which are newer than the timestamp. The `sort',
|
---|
5101 | `tail' and `cut' commands simply pull out the name of the file with the
|
---|
5102 | largest timestamp value (that is, the latest file). The `touch'
|
---|
5103 | command is then used to update the timestamp,
|
---|
5104 |
|
---|
5105 | The `"${newest:-timestamp}"' expression simply expands to the value
|
---|
5106 | of `$newest' if that variable is set, but to `timestamp' otherwise.
|
---|
5107 | This ensures that an argument is always given to the `-r' option of the
|
---|
5108 | `touch' command.
|
---|
5109 |
|
---|
5110 | This approach seems quite efficient, but unfortunately it has a bug.
|
---|
5111 | Many operating systems now keep file modification time information at a
|
---|
5112 | granularity which is finer than one second. Unfortunately the `%A@'
|
---|
5113 | format for `-printf' only prints a whole-number value currently; that
|
---|
5114 | is, these values are at a one-second granularity. This means that in
|
---|
5115 | our example above, `$newest' will be the name of a file which is no
|
---|
5116 | more than one second older than the newest file, but may indeed be
|
---|
5117 | older.
|
---|
5118 |
|
---|
5119 | It would be possible to solve this problem with some kind of loop:
|
---|
5120 |
|
---|
5121 | while true; do
|
---|
5122 | newest=$(find subdir -newer timestamp -printf "%A@:%p\n" |
|
---|
5123 | sort -n |
|
---|
5124 | tail -1 |
|
---|
5125 | cut -d: -f2- )
|
---|
5126 | if test -z "$newest" ; then
|
---|
5127 | break
|
---|
5128 | else
|
---|
5129 | touch -r "$newest" timestamp
|
---|
5130 | fi
|
---|
5131 | done
|
---|
5132 |
|
---|
5133 | A better fix for this problem would be to allow the `%A@' format to
|
---|
5134 | produce a result having a fractional part, too. While this is planned
|
---|
5135 | for GNU `find', it hasn't been done yet.
|
---|
5136 |
|
---|
5137 | 8.2.5 Coping with sub-second timestamp resolution
|
---|
5138 | -------------------------------------------------
|
---|
5139 |
|
---|
5140 | Another tool which often works with timestamps is `make'. We can use
|
---|
5141 | `find' to generate a `Makefile' file on the fly and then use `make' to
|
---|
5142 | update the timestamps:
|
---|
5143 |
|
---|
5144 | makefile=$(mktemp)
|
---|
5145 | find subdir \
|
---|
5146 | \( \! -xtype l \) \
|
---|
5147 | -newer timestamp \
|
---|
5148 | -printf "timestamp:: %p\n\ttouch -r %p timestamp\n\n" > "$makefile"
|
---|
5149 | make -f "$makefile"
|
---|
5150 | rm -f "$makefile"
|
---|
5151 |
|
---|
5152 | Unfortunately although the solution above is quite elegant, it fails
|
---|
5153 | to cope with white space within file names, and adjusting it to do so
|
---|
5154 | would require a rather complex shell script.
|
---|
5155 |
|
---|
5156 | 8.2.6 Coping with odd filenames too
|
---|
5157 | -----------------------------------
|
---|
5158 |
|
---|
5159 | We can fix both of these problems (looping and problems with white
|
---|
5160 | space), and do things more efficiently too. The following command
|
---|
5161 | works with newlines and doesn't need to sort the list of filenames.
|
---|
5162 |
|
---|
5163 | find subdir -newer timestamp -printf "%A@:%p\0" |
|
---|
5164 | perl -0 newest.pl |
|
---|
5165 | xargs --no-run-if-empty --null -i \
|
---|
5166 | find {} -maxdepth 0 -newer timestamp -exec touch -r {} timestamp \;
|
---|
5167 |
|
---|
5168 | The first `find' command generates a list of files which are newer
|
---|
5169 | than the original timestamp file, and prints a list of them with their
|
---|
5170 | timestamps. The `newest.pl' script simply filters out all the
|
---|
5171 | filenames which have timestamps which are older than whatever the
|
---|
5172 | newest file is:-
|
---|
5173 |
|
---|
5174 |
|
---|
5175 | #! /usr/bin/perl -0
|
---|
5176 | my @newest = ();
|
---|
5177 | my $latest_stamp = undef;
|
---|
5178 | while (<>) {
|
---|
5179 | my ($stamp, $name) = split(/:/);
|
---|
5180 | if (!defined($latest_stamp) || ($tstamp > $latest_stamp)) {
|
---|
5181 | $latest_stamp = $stamp;
|
---|
5182 | @newest = ();
|
---|
5183 | }
|
---|
5184 | if ($tstamp >= $latest_stamp) {
|
---|
5185 | push @newest, $name;
|
---|
5186 | }
|
---|
5187 | }
|
---|
5188 | print join("\0", @newest);
|
---|
5189 |
|
---|
5190 | This prints a list of zero or more files, all of which are newer than
|
---|
5191 | the original timestamp file, and which have the same timestamp as each
|
---|
5192 | other, to the nearest second. The second `find' command takes each
|
---|
5193 | resulting file one at a time, and if that is newer than the timestamp
|
---|
5194 | file, the timestamp is updated.
|
---|
5195 |
|
---|
5196 |
|
---|
5197 | File: find.info, Node: Security Considerations, Next: Error Messages, Prev: Worked Examples, Up: Top
|
---|
5198 |
|
---|
5199 | 9 Security Considerations
|
---|
5200 | *************************
|
---|
5201 |
|
---|
5202 | Security considerations are important if you are using `find' or
|
---|
5203 | `xargs' to search for or process files that don't belong to you or
|
---|
5204 | which other people have control. Security considerations relating to
|
---|
5205 | `locate' may also apply if you have files which you do not want others
|
---|
5206 | to see.
|
---|
5207 |
|
---|
5208 | The most severe forms of security problems affecting `find' and
|
---|
5209 | related programs are when third parties bring about a situation
|
---|
5210 | allowing them to do something they would normally not be able to
|
---|
5211 | accomplish. This is called _privilege elevation_. This might include
|
---|
5212 | deleting files they would not normally be able to delete. It is common
|
---|
5213 | for the operating system to periodically invoke `find' for
|
---|
5214 | self-maintenance purposes. These invocations of `find' are
|
---|
5215 | particularly problematic from a security point of view as these are
|
---|
5216 | often invoked by the superuser and search the entire filesystem
|
---|
5217 | hierarchy. Generally, the severity of any associated problem depends
|
---|
5218 | on what the system is going to do with the files found by `find'.
|
---|
5219 |
|
---|
5220 | * Menu:
|
---|
5221 |
|
---|
5222 | * Levels of Risk:: What is your level of exposure to security problems?
|
---|
5223 | * Security Considerations for find:: Security problems with find
|
---|
5224 | * Security Considerations for xargs:: Security problems with xargs
|
---|
5225 | * Security Considerations for locate:: Security problems with locate
|
---|
5226 | * Security Summary:: That was all very complex, what does it boil down to?
|
---|
5227 |
|
---|
5228 |
|
---|
5229 | File: find.info, Node: Levels of Risk, Next: Security Considerations for find, Up: Security Considerations
|
---|
5230 |
|
---|
5231 | 9.1 Levels of Risk
|
---|
5232 | ==================
|
---|
5233 |
|
---|
5234 | There are some security risks inherent in the use of `find', `xargs'
|
---|
5235 | and (to a lesser extent) `locate'. The severity of these risks depends
|
---|
5236 | on what sort of system you are using:
|
---|
5237 |
|
---|
5238 | *High risk*
|
---|
5239 | Multi-user systems where you do not control (or trust) the other
|
---|
5240 | users, and on which you execute `find', including areas where
|
---|
5241 | those other users can manipulate the filesystem (for example
|
---|
5242 | beneath `/home' or `/tmp').
|
---|
5243 |
|
---|
5244 | *Medium Risk*
|
---|
5245 | Systems where the actions of other users can create file names
|
---|
5246 | chosen by them, but to which they don't have access while `find' is
|
---|
5247 | being run. This access might include leaving programs running
|
---|
5248 | (shell background jobs, `at' or `cron' tasks, for example). On
|
---|
5249 | these sorts of systems, carefully written commands (avoiding use of
|
---|
5250 | `-print' for example) should not expose you to a high degree of
|
---|
5251 | risk. Most systems fall into this category.
|
---|
5252 |
|
---|
5253 | *Low Risk*
|
---|
5254 | Systems to which untrusted parties do not have access, cannot
|
---|
5255 | create file names of their own choice (even remotely) and which
|
---|
5256 | contain no security flaws which might enable an untrusted third
|
---|
5257 | party to gain access. Most systems do not fall into this category
|
---|
5258 | because there are many ways in which external parties can affect
|
---|
5259 | the names of files that are created on your system. The system on
|
---|
5260 | which I am writing this for example automatically downloads
|
---|
5261 | software updates from the Internet; the names of the files in
|
---|
5262 | which these updates exist are chosen by third parties(1).
|
---|
5263 |
|
---|
5264 | In the discussion above, "risk" denotes the likelihood that someone
|
---|
5265 | can cause `find', `xargs', `locate' or some other program which is
|
---|
5266 | controlled by them to do something you did not intend. The levels of
|
---|
5267 | risk suggested do not take any account of the consequences of this sort
|
---|
5268 | of event. That is, if you operate a "low risk" type system, but the
|
---|
5269 | consequences of a security problem are disastrous, then you should
|
---|
5270 | still give serious thought to all the possible security problems, many
|
---|
5271 | of which of course will not be discussed here - this section of the
|
---|
5272 | manual is intended to be informative but not comprehensive or
|
---|
5273 | exhaustive.
|
---|
5274 |
|
---|
5275 | If you are responsible for the operation of a system where the
|
---|
5276 | consequences of a security problem could be very important, you should
|
---|
5277 | do two things:-
|
---|
5278 |
|
---|
5279 | 1. Define a security policy which defines who is allowed to do what
|
---|
5280 | on your system.
|
---|
5281 |
|
---|
5282 | 2. Seek competent advice on how to enforce your policy, detect
|
---|
5283 | breaches of that policy, and take account of any potential problems
|
---|
5284 | that might fall outside the scope of your policy.
|
---|
5285 |
|
---|
5286 | ---------- Footnotes ----------
|
---|
5287 |
|
---|
5288 | (1) Of course, I trust these parties to a large extent anyway,
|
---|
5289 | because I install software provided by them; I choose to trust them in
|
---|
5290 | this way, and that's a deliberate choice
|
---|
5291 |
|
---|
5292 |
|
---|
5293 | File: find.info, Node: Security Considerations for find, Next: Security Considerations for xargs, Prev: Levels of Risk, Up: Security Considerations
|
---|
5294 |
|
---|
5295 | 9.2 Security Considerations for `find'
|
---|
5296 | ======================================
|
---|
5297 |
|
---|
5298 | Some of the actions `find' might take have a direct effect; these
|
---|
5299 | include `-exec' and `-delete'. However, it is also common to use
|
---|
5300 | `-print' explicitly or implicitly, and so if `find' produces the wrong
|
---|
5301 | list of file names, that can also be a security problem; consider the
|
---|
5302 | case for example where `find' is producing a list of files to be
|
---|
5303 | deleted.
|
---|
5304 |
|
---|
5305 | We normally assume that the `find' command line expresses the file
|
---|
5306 | selection criteria and actions that the user had in mind - that is, the
|
---|
5307 | command line is "trusted" data.
|
---|
5308 |
|
---|
5309 | From a security analysis point of view, the output of `find' should
|
---|
5310 | be correct; that is, the output should contain only the names of those
|
---|
5311 | files which meet the user's criteria specified on the command line.
|
---|
5312 | This applies for the `-exec' and `-delete' actions; one can consider
|
---|
5313 | these to be part of the output.
|
---|
5314 |
|
---|
5315 | On the other hand, the contents of the filesystem can be manipulated
|
---|
5316 | by other people, and hence we regard this as "untrusted" data. This
|
---|
5317 | implies that the `find' command line is a filter which converts the
|
---|
5318 | untrusted contents of the filesystem into a correct list of output
|
---|
5319 | files.
|
---|
5320 |
|
---|
5321 | The filesystem will in general change while `find' is searching it;
|
---|
5322 | in fact, most of the potential security problems with `find' relate to
|
---|
5323 | this issue in some way.
|
---|
5324 |
|
---|
5325 | "Race conditions" are a general class of security problem where the
|
---|
5326 | relative ordering of actions taken by `find' (for example) and
|
---|
5327 | something else are critically important in getting the correct and
|
---|
5328 | expected result(1) .
|
---|
5329 |
|
---|
5330 | For `find', an attacker might move or rename files or directories in
|
---|
5331 | the hope that an action might be taken against a file which was not
|
---|
5332 | normally intended to be affected. Alternatively, this sort of attack
|
---|
5333 | might be intended to persuade `find' to search part of the filesystem
|
---|
5334 | which would not normally be included in the search (defeating the
|
---|
5335 | `-prune' action for example).
|
---|
5336 |
|
---|
5337 | * Menu:
|
---|
5338 |
|
---|
5339 | * Problems with -exec and filenames::
|
---|
5340 | * Changing the Current Working Directory::
|
---|
5341 | * Race Conditions with -exec::
|
---|
5342 | * Race Conditions with -print and -print0::
|
---|
5343 |
|
---|
5344 | ---------- Footnotes ----------
|
---|
5345 |
|
---|
5346 | (1) This is more or less the definition of the term "race condition"
|
---|
5347 |
|
---|
5348 |
|
---|
5349 | File: find.info, Node: Problems with -exec and filenames, Next: Changing the Current Working Directory, Up: Security Considerations for find
|
---|
5350 |
|
---|
5351 | 9.2.1 Problems with -exec and filenames
|
---|
5352 | ---------------------------------------
|
---|
5353 |
|
---|
5354 | It is safe in many cases to use the `-execdir' action with any file
|
---|
5355 | name. Because `-execdir' prefixes the arguments it passes to programs
|
---|
5356 | with `./', you will not accidentally pass an argument which is
|
---|
5357 | interpreted as an option. For example the file `-f' would be passed to
|
---|
5358 | `rm' as `./-f', which is harmless.
|
---|
5359 |
|
---|
5360 | However, your degree of safety does depend on the nature of the
|
---|
5361 | program you are running. For example constructs such as these two
|
---|
5362 | commands
|
---|
5363 |
|
---|
5364 | find -exec sh -c "something {}" \;
|
---|
5365 | find -execdir sh -c "something {}" \;
|
---|
5366 |
|
---|
5367 | are very dangerous. The reason for this is that the `{}' is
|
---|
5368 | expanded to a filename which might contain a semicolon or other
|
---|
5369 | characters special to the shell. If for example someone creates the
|
---|
5370 | file `/tmp/foo; rm -rf $HOME' then the two commands above could delete
|
---|
5371 | someone's home directory.
|
---|
5372 |
|
---|
5373 | So for this reason do not run any command which will pass untrusted
|
---|
5374 | data (such as the names of files) to commands which interpret arguments
|
---|
5375 | as commands to be further interpreted (for example `sh').
|
---|
5376 |
|
---|
5377 |
|
---|
5378 | File: find.info, Node: Changing the Current Working Directory, Next: Race Conditions with -exec, Prev: Problems with -exec and filenames, Up: Security Considerations for find
|
---|
5379 |
|
---|
5380 | 9.2.2 Changing the Current Working Directory
|
---|
5381 | --------------------------------------------
|
---|
5382 |
|
---|
5383 | As `find' searches the filesystem, it finds subdirectories and then
|
---|
5384 | searches within them by changing its working directory. First, `find'
|
---|
5385 | reaches and recognises a subdirectory. It then decides if that
|
---|
5386 | subdirectory meets the criteria for being searched; that is, any
|
---|
5387 | `-xdev' or `-prune' expressions are taken into account. The `find'
|
---|
5388 | program will then change working directory and proceed to search the
|
---|
5389 | directory.
|
---|
5390 |
|
---|
5391 | A race condition attack might take the form that once the checks
|
---|
5392 | relevant to `-xdev' and `-prune' have been done, an attacker might
|
---|
5393 | rename the directory that was being considered, and put in its place a
|
---|
5394 | symbolic link that actually points somewhere else.
|
---|
5395 |
|
---|
5396 | The idea behind this attack is to fool `find' into going into the
|
---|
5397 | wrong directory. This would leave `find' with a working directory
|
---|
5398 | chosen by an attacker, bypassing any protection apparently provided by
|
---|
5399 | `-xdev' and `-prune', and any protection provided by being able to
|
---|
5400 | _not_ list particular directories on the `find' command line. This
|
---|
5401 | form of attack is particularly problematic if the attacker can predict
|
---|
5402 | when the `find' command will be run, as is the case with `cron' tasks
|
---|
5403 | for example.
|
---|
5404 |
|
---|
5405 | GNU `find' has specific safeguards to prevent this general class of
|
---|
5406 | problem. The exact form of these safeguards depends on the properties
|
---|
5407 | of your system.
|
---|
5408 |
|
---|
5409 | * Menu:
|
---|
5410 |
|
---|
5411 | * O_NOFOLLOW:: Safely changing directory using fchdir().
|
---|
5412 | * Systems without O_NOFOLLOW:: Checking for symbolic links after chdir().
|
---|
5413 |
|
---|
5414 |
|
---|
5415 | File: find.info, Node: O_NOFOLLOW, Next: Systems without O_NOFOLLOW, Up: Changing the Current Working Directory
|
---|
5416 |
|
---|
5417 | 9.2.2.1 O_NOFOLLOW
|
---|
5418 | ..................
|
---|
5419 |
|
---|
5420 | If your system supports the O_NOFOLLOW flag (1) to the `open(2)' system
|
---|
5421 | call, `find' uses it when safely changing directory. The target
|
---|
5422 | directory is first opened and then `find' changes working directory
|
---|
5423 | with the `fchdir()' system call. This ensures that symbolic links are
|
---|
5424 | not followed, preventing the sort of race condition attack in which use
|
---|
5425 | is made of symbolic links.
|
---|
5426 |
|
---|
5427 | If for any reason this approach does not work, `find' will fall back
|
---|
5428 | on the method which is normally used if O_NOFOLLOW is not supported.
|
---|
5429 |
|
---|
5430 | You can tell if your system supports O_NOFOLLOW by running
|
---|
5431 |
|
---|
5432 | find --version
|
---|
5433 |
|
---|
5434 | This will tell you the version number and which features are enabled.
|
---|
5435 | For example, if I run this on my system now, this gives:
|
---|
5436 | GNU find version 4.2.18-CVS
|
---|
5437 | Features enabled: D_TYPE O_NOFOLLOW(enabled)
|
---|
5438 |
|
---|
5439 | Here, you can see that I am running a version of `find' which was
|
---|
5440 | built from the development (CVS) code prior to the release of
|
---|
5441 | findutils-4.2.18, and that the D_TYPE and O_NOFOLLOW features are
|
---|
5442 | present. O_NOFOLLOW is qualified with "enabled". This simply means
|
---|
5443 | that the current system seems to support O_NOFOLLOW. This check is
|
---|
5444 | needed because it is possible to build `find' on a system that defines
|
---|
5445 | O_NOFOLLOW and then run it on a system that ignores the O_NOFOLLOW
|
---|
5446 | flag. We try to detect such cases at startup by checking the operating
|
---|
5447 | system and version number; when this happens you will see
|
---|
5448 | "O_NOFOLLOW(disabled)" instead.
|
---|
5449 |
|
---|
5450 | ---------- Footnotes ----------
|
---|
5451 |
|
---|
5452 | (1) GNU/Linux (kernel version 2.1.126 and later) and FreeBSD
|
---|
5453 | (3.0-CURRENT and later) support this
|
---|
5454 |
|
---|
5455 |
|
---|
5456 | File: find.info, Node: Systems without O_NOFOLLOW, Prev: O_NOFOLLOW, Up: Changing the Current Working Directory
|
---|
5457 |
|
---|
5458 | 9.2.2.2 Systems without O_NOFOLLOW
|
---|
5459 | ..................................
|
---|
5460 |
|
---|
5461 | The strategy for preventing this type of problem on systems that lack
|
---|
5462 | support for the O_NOFOLLOW flag is more complex. Each time `find'
|
---|
5463 | changes directory, it examines the directory it is about to move to,
|
---|
5464 | issues the `chdir()' system call, and then checks that it has ended up
|
---|
5465 | in the subdirectory it expected. If all is as expected, processing
|
---|
5466 | continues as normal. However, there are two main reasons why the
|
---|
5467 | directory might change: the use of an automounter and the someone
|
---|
5468 | removing the old directory and replacing it with something else while
|
---|
5469 | `find' is trying to descend into it.
|
---|
5470 |
|
---|
5471 | Where a filesystem "automounter" is in use it can be the case that
|
---|
5472 | the use of the `chdir()' system call can itself cause a new filesystem
|
---|
5473 | to be mounted at that point. On systems that do not support
|
---|
5474 | O_NOFOLLOW, this will cause `find''s security check to fail.
|
---|
5475 |
|
---|
5476 | However, this does not normally represent a security problem, since
|
---|
5477 | the automounter configuration is normally set up by the system
|
---|
5478 | administrator. Therefore, if the `chdir()' sanity check fails, `find'
|
---|
5479 | will make one more attempt. If that succeeds, execution carries on as
|
---|
5480 | normal. This is the usual case for automounters.
|
---|
5481 |
|
---|
5482 | Where an attacker is trying to exploit a race condition, the problem
|
---|
5483 | may not have gone away on the second attempt. If this is the case,
|
---|
5484 | `find' will issue a warning message and then ignore that subdirectory.
|
---|
5485 | When this happens, actions such as `-exec' or `-print' may already have
|
---|
5486 | taken place for the problematic subdirectory. This is because `find'
|
---|
5487 | applies tests and actions to directories before searching within them
|
---|
5488 | (unless `-depth' was specified).
|
---|
5489 |
|
---|
5490 | Because of the nature of the directory-change operation and security
|
---|
5491 | check, in the worst case the only things that `find' would have done
|
---|
5492 | with the directory are to move into it and back out to the original
|
---|
5493 | parent. No operations would have been performed within that directory.
|
---|
5494 |
|
---|
5495 |
|
---|
5496 | File: find.info, Node: Race Conditions with -exec, Next: Race Conditions with -print and -print0, Prev: Changing the Current Working Directory, Up: Security Considerations for find
|
---|
5497 |
|
---|
5498 | 9.2.3 Race Conditions with -exec
|
---|
5499 | --------------------------------
|
---|
5500 |
|
---|
5501 | The `-exec' action causes another program to be run. It passes to the
|
---|
5502 | program the name of the file which is being considered at the time.
|
---|
5503 | The invoked program will typically then perform some action on that
|
---|
5504 | file. Once again, there is a race condition which can be exploited
|
---|
5505 | here. We shall take as a specific example the command
|
---|
5506 |
|
---|
5507 | find /tmp -path /tmp/umsp/passwd -exec /bin/rm
|
---|
5508 |
|
---|
5509 | In this simple example, we are identifying just one file to be
|
---|
5510 | deleted and invoking `/bin/rm' to delete it. A problem exists because
|
---|
5511 | there is a time gap between the point where `find' decides that it
|
---|
5512 | needs to process the `-exec' action and the point where the `/bin/rm'
|
---|
5513 | command actually issues the `unlink()' system call to delete the file
|
---|
5514 | from the filesystem. Within this time period, an attacker can rename
|
---|
5515 | the `/tmp/umsp' directory, replacing it with a symbolic link to `/etc'.
|
---|
5516 | There is no way for `/bin/rm' to determine that it is working on the
|
---|
5517 | same file that `find' had in mind. Once the symbolic link is in place,
|
---|
5518 | the attacker has persuaded `find' to cause the deletion of the
|
---|
5519 | `/etc/passwd' file, which is not the effect intended by the command
|
---|
5520 | which was actually invoked.
|
---|
5521 |
|
---|
5522 | One possible defence against this type of attack is to modify the
|
---|
5523 | behaviour of `-exec' so that the `/bin/rm' command is run with the
|
---|
5524 | argument `./passwd' and a suitable choice of working directory. This
|
---|
5525 | would allow the normal sanity check that `find' performs to protect
|
---|
5526 | against this form of attack too. Unfortunately, this strategy cannot
|
---|
5527 | be used as the POSIX standard specifies that the current working
|
---|
5528 | directory for commands invoked with `-exec' must be the same as the
|
---|
5529 | current working directory from which `find' was invoked. This means
|
---|
5530 | that the `-exec' action is inherently insecure and can't be fixed.
|
---|
5531 |
|
---|
5532 | GNU `find' implements a more secure variant of the `-exec' action,
|
---|
5533 | `-execdir'. The `-execdir' action ensures that it is not necessary to
|
---|
5534 | dereference subdirectories to process target files. The current
|
---|
5535 | directory used to invoke programs is the same as the directory in which
|
---|
5536 | the file to be processed exists (`/tmp/umsp' in our example, and only
|
---|
5537 | the basename of the file to be processed is passed to the invoked
|
---|
5538 | command, with a `./' prepended (giving `./passwd' in our example).
|
---|
5539 |
|
---|
5540 | The `-execdir' action refuses to do anything if the current
|
---|
5541 | directory is included in the $PATH environment variable. This is
|
---|
5542 | necessary because `-execdir' runs programs in the same directory in
|
---|
5543 | which it finds files - in general, such a directory might be writable
|
---|
5544 | by untrusted users. For similar reasons, `-execdir' does not allow
|
---|
5545 | `{}' to appear in the name of the command to be run.
|
---|
5546 |
|
---|
5547 |
|
---|
5548 | File: find.info, Node: Race Conditions with -print and -print0, Prev: Race Conditions with -exec, Up: Security Considerations for find
|
---|
5549 |
|
---|
5550 | 9.2.4 Race Conditions with -print and -print0
|
---|
5551 | ---------------------------------------------
|
---|
5552 |
|
---|
5553 | The `-print' and `-print0' actions can be used to produce a list of
|
---|
5554 | files matching some criteria, which can then be used with some other
|
---|
5555 | command, perhaps with `xargs'. Unfortunately, this means that there is
|
---|
5556 | an unavoidable time gap between `find' deciding that one or more files
|
---|
5557 | meet its criteria and the relevant command being executed. For this
|
---|
5558 | reason, the `-print' and `-print0' actions are just as insecure as
|
---|
5559 | `-exec'.
|
---|
5560 |
|
---|
5561 | In fact, since the construction
|
---|
5562 |
|
---|
5563 | find ... -print | xargs ....
|
---|
5564 |
|
---|
5565 | does not cope correctly with newlines or other "white space" in file
|
---|
5566 | names, and copes poorly with file names containing quotes, the `-print'
|
---|
5567 | action is less secure even than `-print0'.
|
---|
5568 |
|
---|
5569 |
|
---|
5570 | File: find.info, Node: Security Considerations for xargs, Next: Security Considerations for locate, Prev: Security Considerations for find, Up: Security Considerations
|
---|
5571 |
|
---|
5572 | 9.3 Security Considerations for `xargs'
|
---|
5573 | =======================================
|
---|
5574 |
|
---|
5575 | The description of the race conditions affecting the `-print' action of
|
---|
5576 | `find' shows that `xargs' cannot be secure if it is possible for an
|
---|
5577 | attacker to modify a filesystem after `find' has started but before
|
---|
5578 | `xargs' has completed all its actions.
|
---|
5579 |
|
---|
5580 | However, there are other security issues that exist even if it is not
|
---|
5581 | possible for an attacker to have access to the filesystem in real time.
|
---|
5582 | Firstly, if it is possible for an attacker to create files with names
|
---|
5583 | of their choice on the filesystem, then `xargs' is insecure unless the
|
---|
5584 | `-0' option is used. If a file with the name
|
---|
5585 | `/home/someuser/foo/bar\n/etc/passwd' exists (assume that `\n' stands
|
---|
5586 | for a newline character), then `find ... -print' can be persuaded to
|
---|
5587 | print three separate lines:
|
---|
5588 |
|
---|
5589 | /home/someuser/foo/bar
|
---|
5590 |
|
---|
5591 | /etc/passwd
|
---|
5592 |
|
---|
5593 | If it finds a blank line in the input, `xargs' will ignore it.
|
---|
5594 | Therefore, if some action is to be taken on the basis of this list of
|
---|
5595 | files, the `/etc/passwd' file would be included even if this was not
|
---|
5596 | the intent of the person running find. There are circumstances in
|
---|
5597 | which an attacker can use this to their advantage. The same
|
---|
5598 | consideration applies to file names containing ordinary spaces rather
|
---|
5599 | than newlines, except that of course the list of file names will no
|
---|
5600 | longer contain an "extra" newline.
|
---|
5601 |
|
---|
5602 | This problem is an unavoidable consequence of the default behaviour
|
---|
5603 | of the `xargs' command, which is specified by the POSIX standard. The
|
---|
5604 | only ways to avoid this problem are either to avoid all use of `xargs'
|
---|
5605 | in favour for example of `find -exec' or (where available) `find
|
---|
5606 | -execdir', or to use the `-0' option, which ensures that `xargs'
|
---|
5607 | considers file names to be separated by ASCII NUL characters rather
|
---|
5608 | than whitespace. However, useful as this option is, the POSIX standard
|
---|
5609 | does not make it mandatory.
|
---|
5610 |
|
---|
5611 |
|
---|
5612 | File: find.info, Node: Security Considerations for locate, Next: Security Summary, Prev: Security Considerations for xargs, Up: Security Considerations
|
---|
5613 |
|
---|
5614 | 9.4 Security Considerations for `locate'
|
---|
5615 | ========================================
|
---|
5616 |
|
---|
5617 | It is fairly unusual for the output of `locate' to be fed into another
|
---|
5618 | command. However, if this were to be done, this would raise the same
|
---|
5619 | set of security issues as the use of `find ... -print'. Although the
|
---|
5620 | problems relating to whitespace in file names can be resolved by using
|
---|
5621 | `locate''s `-0' option, this still leaves the race condition problems
|
---|
5622 | associated with `find ... -print0'. There is no way to avoid these
|
---|
5623 | problems in the case of `locate'.
|
---|
5624 |
|
---|
5625 |
|
---|
5626 | File: find.info, Node: Security Summary, Prev: Security Considerations for locate, Up: Security Considerations
|
---|
5627 |
|
---|
5628 | 9.5 Summary
|
---|
5629 | ===========
|
---|
5630 |
|
---|
5631 | Where untrusted parties can create files on the system, or affect the
|
---|
5632 | names of files that are created, all uses for `find', `locate' and
|
---|
5633 | `xargs' have known security problems except the following:
|
---|
5634 |
|
---|
5635 | Informational use only
|
---|
5636 | Uses where the programs are used to prepare lists of file names
|
---|
5637 | upon which no further action will ever be taken.
|
---|
5638 |
|
---|
5639 | `-delete'
|
---|
5640 | Use of the `-delete' action with `find' to delete files which meet
|
---|
5641 | specified criteria
|
---|
5642 |
|
---|
5643 | `-execdir'
|
---|
5644 | Use of the `-execdir' action with `find' where the `PATH'
|
---|
5645 | environment variable contains directories which contain only
|
---|
5646 | trusted programs.
|
---|
5647 |
|
---|
5648 |
|
---|
5649 | File: find.info, Node: Error Messages, Next: Primary Index, Prev: Security Considerations, Up: Top
|
---|
5650 |
|
---|
5651 | 10 Error Messages
|
---|
5652 | *****************
|
---|
5653 |
|
---|
5654 | This section describes some of the error messages sometimes made by
|
---|
5655 | `find', `xargs', or `locate', explains them and in some cases provides
|
---|
5656 | advice as to what you should do about this.
|
---|
5657 |
|
---|
5658 | This manual is written in English. The GNU findutils software
|
---|
5659 | features translations of error messages for many languages. For this
|
---|
5660 | reason the error messages produced by the programs are made to be as
|
---|
5661 | self-explanatory as possible. This approach avoids leaving people to
|
---|
5662 | figure out which test an English-language error message corresponds to.
|
---|
5663 | Error messages which are self-explanatory will not normally be
|
---|
5664 | mentioned in this document. For those messages mentioned in this
|
---|
5665 | document, only the English-language version of the message will be
|
---|
5666 | listed.
|
---|
5667 |
|
---|
5668 | * Menu:
|
---|
5669 |
|
---|
5670 | * Error Messages From find::
|
---|
5671 | * Error Messages From xargs::
|
---|
5672 | * Error Messages From locate::
|
---|
5673 | * Error Messages From updatedb::
|
---|
5674 |
|
---|
5675 |
|
---|
5676 | File: find.info, Node: Error Messages From find, Next: Error Messages From xargs, Up: Error Messages
|
---|
5677 |
|
---|
5678 | 10.1 Error Messages From `find'
|
---|
5679 | ===============================
|
---|
5680 |
|
---|
5681 | `invalid predicate `-foo''
|
---|
5682 | This means that the `find' command line included something that
|
---|
5683 | started with a dash or other special character. The `find'
|
---|
5684 | program tried to interpret this as a test, action or option, but
|
---|
5685 | didn't recognise it. If it was intended to be a test, check what
|
---|
5686 | was specified against the documentation. If, on the other hand,
|
---|
5687 | the string is the name of a file which has been expanded from a
|
---|
5688 | wildcard (for example because you have a `*' on the command line),
|
---|
5689 | consider using `./*' or just `.' instead.
|
---|
5690 |
|
---|
5691 | `unexpected extra predicate'
|
---|
5692 | This usually happens if you have an extra bracket on the command
|
---|
5693 | line (for example `find . -print \)').
|
---|
5694 |
|
---|
5695 | `Warning: filesystem /path/foo has recently been mounted'
|
---|
5696 | `Warning: filesystem /path/foo has recently been unmounted'
|
---|
5697 | These messages might appear when `find' moves into a directory and
|
---|
5698 | finds that the device number and inode are different to what it
|
---|
5699 | expected them to be. If the directory `find' has moved into is on
|
---|
5700 | an network filesystem (NFS), it will not issue this message,
|
---|
5701 | because `automount' frequently mounts new filesystems on
|
---|
5702 | directories as you move into them (that is how it knows you want
|
---|
5703 | to use the filesystem). So, if you do see this message, be wary --
|
---|
5704 | `automount' may not have been responsible. Consider the
|
---|
5705 | possibility that someone else is manipulating the filesystem while
|
---|
5706 | `find' is running. Some people might do this in order to mislead
|
---|
5707 | `find' or persuade it to look at one set of files when it thought
|
---|
5708 | it was looking at another set.
|
---|
5709 |
|
---|
5710 | `/path/foo changed during execution of find (old device number 12345, new device number 6789, filesystem type is <whatever>) [ref XXX]'
|
---|
5711 | This message is issued when `find' moves into a directory and ends
|
---|
5712 | up somewhere it didn't expect to be. This happens in one of two
|
---|
5713 | circumstances. Firstly, this happens when `automount' intervenes
|
---|
5714 | on a system where `find' doesn't know how to determine what the
|
---|
5715 | current set of mounted filesystems is.
|
---|
5716 |
|
---|
5717 | Secondly, this can happen when the device number of a directory
|
---|
5718 | appears to change during a change of current directory, but `find'
|
---|
5719 | is moving up the filesystem hierarchy rather than down into it.
|
---|
5720 | In order to prevent `find' wandering off into some unexpected part
|
---|
5721 | of the filesystem, we stop it at this point.
|
---|
5722 |
|
---|
5723 | `Don't know how to use getmntent() to read `/etc/mtab'. This is a bug.'
|
---|
5724 | This message is issued when a problem similar to the above occurs
|
---|
5725 | on a system where `find' doesn't know how to figure out the current
|
---|
5726 | list of mount points. Ask for help on <bug-findutils@gnu.org>.
|
---|
5727 |
|
---|
5728 | `/path/foo/bar changed during execution of find (old inode number 12345, new inode number 67893, filesystem type is <whatever>) [ref XXX]"),'
|
---|
5729 | This message is issued when `find' moves into a directory and
|
---|
5730 | discovers that the inode number of that directory is different
|
---|
5731 | from the inode number that it obtained when it examined the
|
---|
5732 | directory previously. This usually means that while `find' was
|
---|
5733 | deep in a directory hierarchy doing a time consuming operation,
|
---|
5734 | somebody has moved one of the parent directories to another
|
---|
5735 | location in the same filesystem. This may or may not have been
|
---|
5736 | done maliciously. In any case, `find' stops at this point to
|
---|
5737 | avoid traversing parts of the filesystem that it wasn't intended.
|
---|
5738 | You can use `ls -li' or `find /path -inum 12345 -o -inum 67893' to
|
---|
5739 | find out more about what has happened.
|
---|
5740 |
|
---|
5741 | `sanity check of the fnmatch() library function failed.'
|
---|
5742 | Please submit a bug report. You may well be asked questions about
|
---|
5743 | your system, and if you compiled the `findutils' code yourself,
|
---|
5744 | you should keep your copy of the build tree around. The likely
|
---|
5745 | explanation is that your system has a buggy implementation of
|
---|
5746 | `fnmatch' that looks enough like the GNU version to fool
|
---|
5747 | `configure', but which doesn't work properly.
|
---|
5748 |
|
---|
5749 | `cannot fork'
|
---|
5750 | This normally happens if you use the `-exec' action or something
|
---|
5751 | similar (`-ok' and so forth) but the system has run out of free
|
---|
5752 | process slots. This is either because the system is very busy and
|
---|
5753 | the system has reached its maximum process limit, or because you
|
---|
5754 | have a resource limit in place and you've reached it. Check the
|
---|
5755 | system for runaway processes (with `ps', if possible). Some
|
---|
5756 | process slots are normally reserved for use by `root'.
|
---|
5757 |
|
---|
5758 | `some-program terminated by signal 99'
|
---|
5759 | Some program which was launched with `-exec' or similar was killed
|
---|
5760 | with a fatal signal. This is just an advisory message.
|
---|
5761 |
|
---|
5762 |
|
---|
5763 | File: find.info, Node: Error Messages From xargs, Next: Error Messages From locate, Prev: Error Messages From find, Up: Error Messages
|
---|
5764 |
|
---|
5765 | 10.2 Error Messages From xargs
|
---|
5766 | ==============================
|
---|
5767 |
|
---|
5768 | `environment is too large for exec'
|
---|
5769 | This message means that you have so many environment variables set
|
---|
5770 | (or such large values for them) that there is no room within the
|
---|
5771 | system-imposed limits on program command line argument length to
|
---|
5772 | invoke any program. This is an unlikely situation and is more
|
---|
5773 | likely result of an attempt to test the limits of `xargs', or
|
---|
5774 | break it. Please try unsetting some environment variables, or
|
---|
5775 | exiting the current shell. You can also use `xargs --show-limits'
|
---|
5776 | to understand the relevant sizes.
|
---|
5777 |
|
---|
5778 | `can not fit single argument within argument list size limit'
|
---|
5779 | You are using the `-I' option and `xargs' doesn't have enough
|
---|
5780 | space to build a command line because it has read a really large
|
---|
5781 | item and it doesn't fit. You can probably work around this
|
---|
5782 | problem with the `-s' option, but the default size is pretty
|
---|
5783 | large. This is a rare situation and is more likely an attempt to
|
---|
5784 | test the limits of `xargs', or break it. Otherwise, you will need
|
---|
5785 | to try to shorten the problematic argument or not use `xargs'.
|
---|
5786 |
|
---|
5787 | `cannot fork'
|
---|
5788 | See the description of the similar message for `find'.
|
---|
5789 |
|
---|
5790 | `<program>: exited with status 255; aborting'
|
---|
5791 | When a command run by `xargs' exits with status 255, `xargs' is
|
---|
5792 | supposed to stop. If this is not what you intended, wrap the
|
---|
5793 | program you are trying to invoke in a shell script which doesn't
|
---|
5794 | return status 255.
|
---|
5795 |
|
---|
5796 | `<program>: terminated by signal 99'
|
---|
5797 | See the description of the similar message for `find'.
|
---|
5798 |
|
---|
5799 |
|
---|
5800 | File: find.info, Node: Error Messages From locate, Next: Error Messages From updatedb, Prev: Error Messages From xargs, Up: Error Messages
|
---|
5801 |
|
---|
5802 | 10.3 Error Messages From `locate'
|
---|
5803 | =================================
|
---|
5804 |
|
---|
5805 | `warning: database `/usr/local/var/locatedb' is more than 8 days old'
|
---|
5806 | The `locate' program relies on a database which is periodically
|
---|
5807 | built by the `updatedb' program. That hasn't happened in a long
|
---|
5808 | time. To fix this problem, run `updatedb' manually. This can
|
---|
5809 | often happen on systems that are generally not left on, so the
|
---|
5810 | periodic "cron" task which normally does this doesn't get a chance
|
---|
5811 | to run.
|
---|
5812 |
|
---|
5813 | `locate database `/usr/local/var/locatedb' is corrupt or invalid'
|
---|
5814 | This should not happen. Re-run `updatedb'. If that works, but
|
---|
5815 | `locate' still produces this error, run `locate --version' and
|
---|
5816 | `updatedb --version'. These should produce the same output. If
|
---|
5817 | not, you are using a mixed toolset; check your `$PATH' environment
|
---|
5818 | variable and your shell aliases (if you have any). If both
|
---|
5819 | programs claim to be GNU versions, this is a bug; all versions of
|
---|
5820 | these programs should interoperate without problem. Ask for help
|
---|
5821 | on <bug-findutils@gnu.org>.
|
---|
5822 |
|
---|
5823 |
|
---|
5824 | File: find.info, Node: Error Messages From updatedb, Prev: Error Messages From locate, Up: Error Messages
|
---|
5825 |
|
---|
5826 | 10.4 Error Messages From updatedb
|
---|
5827 | =================================
|
---|
5828 |
|
---|
5829 | The `updatedb' program (and the programs it invokes) do issue error
|
---|
5830 | messages, but none seem to be candidates for guidance. If you are
|
---|
5831 | having a problem understanding one of these, ask for help on
|
---|
5832 | <bug-findutils@gnu.org>.
|
---|
5833 |
|
---|
5834 |
|
---|
5835 | File: find.info, Node: Primary Index, Prev: Error Messages, Up: Top
|
---|
5836 |
|
---|
5837 | `find' Primary Index
|
---|
5838 | ********************
|
---|
5839 |
|
---|
5840 | This is a list of all of the primaries (tests, actions, and options)
|
---|
5841 | that make up `find' expressions for selecting files. *Note find
|
---|
5842 | Expressions::, for more information on expressions.
|
---|
5843 |
|
---|
5844 | [index]
|
---|
5845 | * Menu:
|
---|
5846 |
|
---|
5847 | * !: Combining Primaries With Operators.
|
---|
5848 | (line 14)
|
---|
5849 | * (): Combining Primaries With Operators.
|
---|
5850 | (line 10)
|
---|
5851 | * ,: Combining Primaries With Operators.
|
---|
5852 | (line 27)
|
---|
5853 | * -a: Combining Primaries With Operators.
|
---|
5854 | (line 20)
|
---|
5855 | * -amin: Age Ranges. (line 18)
|
---|
5856 | * -and: Combining Primaries With Operators.
|
---|
5857 | (line 20)
|
---|
5858 | * -anewer: Comparing Timestamps.
|
---|
5859 | (line 17)
|
---|
5860 | * -atime: Age Ranges. (line 9)
|
---|
5861 | * -cmin: Age Ranges. (line 19)
|
---|
5862 | * -cnewer: Comparing Timestamps.
|
---|
5863 | (line 18)
|
---|
5864 | * -ctime: Age Ranges. (line 10)
|
---|
5865 | * -d: Directories. (line 29)
|
---|
5866 | * -daystart: Age Ranges. (line 29)
|
---|
5867 | * -delete: Delete Files. (line 7)
|
---|
5868 | * -depth: Directories. (line 21)
|
---|
5869 | * -empty: Size. (line 50)
|
---|
5870 | * -exec <1>: Multiple Files. (line 25)
|
---|
5871 | * -exec: Single File. (line 34)
|
---|
5872 | * -execdir <1>: Multiple Files. (line 15)
|
---|
5873 | * -execdir: Single File. (line 9)
|
---|
5874 | * -executable: Mode Bits. (line 42)
|
---|
5875 | * -false: Combining Primaries With Operators.
|
---|
5876 | (line 47)
|
---|
5877 | * -fls: Print File Information.
|
---|
5878 | (line 48)
|
---|
5879 | * -fprint: Print File Name. (line 13)
|
---|
5880 | * -fprint0: Safe File Name Handling.
|
---|
5881 | (line 16)
|
---|
5882 | * -fprintf: Print File Information.
|
---|
5883 | (line 65)
|
---|
5884 | * -fstype: Filesystems. (line 22)
|
---|
5885 | * -gid: Owner. (line 13)
|
---|
5886 | * -group: Owner. (line 8)
|
---|
5887 | * -ignore_readdir_race: Directories. (line 86)
|
---|
5888 | * -ilname: Symbolic Links. (line 87)
|
---|
5889 | * -iname: Base Name Patterns. (line 8)
|
---|
5890 | * -inum: Hard Links. (line 41)
|
---|
5891 | * -ipath: Full Name Patterns. (line 20)
|
---|
5892 | * -iregex: Full Name Patterns. (line 26)
|
---|
5893 | * -iwholename: Full Name Patterns. (line 8)
|
---|
5894 | * -links: Hard Links. (line 53)
|
---|
5895 | * -lname: Symbolic Links. (line 86)
|
---|
5896 | * -ls: Print File Information.
|
---|
5897 | (line 7)
|
---|
5898 | * -maxdepth: Directories. (line 11)
|
---|
5899 | * -mindepth: Directories. (line 16)
|
---|
5900 | * -mmin: Age Ranges. (line 20)
|
---|
5901 | * -mount: Filesystems. (line 15)
|
---|
5902 | * -mtime: Age Ranges. (line 11)
|
---|
5903 | * -name: Base Name Patterns. (line 7)
|
---|
5904 | * -newer: Comparing Timestamps.
|
---|
5905 | (line 19)
|
---|
5906 | * -nogroup: Owner. (line 18)
|
---|
5907 | * -noignore_readdir_race: Directories. (line 103)
|
---|
5908 | * -noleaf: Directories. (line 71)
|
---|
5909 | * -not: Combining Primaries With Operators.
|
---|
5910 | (line 14)
|
---|
5911 | * -nouser: Owner. (line 17)
|
---|
5912 | * -o: Combining Primaries With Operators.
|
---|
5913 | (line 24)
|
---|
5914 | * -ok: Querying. (line 17)
|
---|
5915 | * -okdir: Querying. (line 11)
|
---|
5916 | * -or: Combining Primaries With Operators.
|
---|
5917 | (line 24)
|
---|
5918 | * -path: Full Name Patterns. (line 19)
|
---|
5919 | * -perm: Mode Bits. (line 45)
|
---|
5920 | * -print: Print File Name. (line 7)
|
---|
5921 | * -print0: Safe File Name Handling.
|
---|
5922 | (line 12)
|
---|
5923 | * -printf: Print File Information.
|
---|
5924 | (line 53)
|
---|
5925 | * -prune: Directories. (line 34)
|
---|
5926 | * -quit: Directories. (line 62)
|
---|
5927 | * -readable: Mode Bits. (line 34)
|
---|
5928 | * -regex: Full Name Patterns. (line 25)
|
---|
5929 | * -regextype: Full Name Patterns. (line 37)
|
---|
5930 | * -samefile: Hard Links. (line 36)
|
---|
5931 | * -size: Size. (line 7)
|
---|
5932 | * -true: Combining Primaries With Operators.
|
---|
5933 | (line 44)
|
---|
5934 | * -type: Type. (line 7)
|
---|
5935 | * -uid: Owner. (line 12)
|
---|
5936 | * -used: Comparing Timestamps.
|
---|
5937 | (line 29)
|
---|
5938 | * -user: Owner. (line 7)
|
---|
5939 | * -wholename: Full Name Patterns. (line 7)
|
---|
5940 | * -writable: Mode Bits. (line 37)
|
---|
5941 | * -xdev: Filesystems. (line 14)
|
---|
5942 | * -xtype: Type. (line 36)
|
---|
5943 |
|
---|
5944 |
|
---|
5945 |
|
---|
5946 | Tag Table:
|
---|
5947 | Node: Top1523
|
---|
5948 | Node: Introduction2566
|
---|
5949 | Node: Scope4862
|
---|
5950 | Node: Overview6808
|
---|
5951 | Node: find Expressions8679
|
---|
5952 | Node: Finding Files10511
|
---|
5953 | Node: Name10976
|
---|
5954 | Node: Base Name Patterns11604
|
---|
5955 | Ref: Base Name Patterns-Footnote-112702
|
---|
5956 | Node: Full Name Patterns12914
|
---|
5957 | Node: Fast Full Name Search15577
|
---|
5958 | Node: Shell Pattern Matching17998
|
---|
5959 | Node: Links20088
|
---|
5960 | Node: Symbolic Links20523
|
---|
5961 | Node: Hard Links25031
|
---|
5962 | Node: Time27585
|
---|
5963 | Node: Age Ranges28173
|
---|
5964 | Node: Comparing Timestamps29700
|
---|
5965 | Node: Size30992
|
---|
5966 | Node: Type32834
|
---|
5967 | Node: Owner34502
|
---|
5968 | Node: Mode Bits35327
|
---|
5969 | Node: Contents40452
|
---|
5970 | Node: Directories41623
|
---|
5971 | Node: Filesystems46584
|
---|
5972 | Node: Combining Primaries With Operators47935
|
---|
5973 | Node: Actions49553
|
---|
5974 | Node: Print File Name50115
|
---|
5975 | Node: Print File Information51132
|
---|
5976 | Node: Escapes54141
|
---|
5977 | Node: Format Directives54892
|
---|
5978 | Node: Name Directives56354
|
---|
5979 | Node: Ownership Directives57340
|
---|
5980 | Node: Size Directives58348
|
---|
5981 | Node: Location Directives59114
|
---|
5982 | Node: Time Directives60233
|
---|
5983 | Node: Time Formats61136
|
---|
5984 | Node: Time Components61572
|
---|
5985 | Node: Date Components62078
|
---|
5986 | Node: Combined Time Formats62901
|
---|
5987 | Node: Formatting Flags63618
|
---|
5988 | Node: Run Commands64230
|
---|
5989 | Node: Single File64588
|
---|
5990 | Node: Multiple Files66511
|
---|
5991 | Node: Unsafe File Name Handling70365
|
---|
5992 | Node: Safe File Name Handling71928
|
---|
5993 | Node: Unusual Characters in File Names73504
|
---|
5994 | Node: Limiting Command Size76540
|
---|
5995 | Node: Interspersing File Names78833
|
---|
5996 | Node: Querying81288
|
---|
5997 | Node: Delete Files82818
|
---|
5998 | Node: Adding Tests83222
|
---|
5999 | Node: Databases85862
|
---|
6000 | Node: Database Locations86580
|
---|
6001 | Node: Database Formats87588
|
---|
6002 | Node: New Database Format88492
|
---|
6003 | Node: Sample Database90159
|
---|
6004 | Node: Old Database Format90807
|
---|
6005 | Node: Newline Handling92867
|
---|
6006 | Node: File Permissions94313
|
---|
6007 | Node: Mode Structure94906
|
---|
6008 | Node: Symbolic Modes98594
|
---|
6009 | Node: Setting Permissions99685
|
---|
6010 | Node: Copying Permissions102291
|
---|
6011 | Node: Changing Special Mode Bits103103
|
---|
6012 | Node: Conditional Executability104918
|
---|
6013 | Node: Multiple Changes105455
|
---|
6014 | Node: Umask and Protection107115
|
---|
6015 | Node: Numeric Modes108213
|
---|
6016 | Node: Directory Setuid and Setgid110106
|
---|
6017 | Node: Reference112361
|
---|
6018 | Node: Invoking find112709
|
---|
6019 | Node: Filesystem Traversal Options114191
|
---|
6020 | Node: Warning Messages115284
|
---|
6021 | Node: Optimisation Options117038
|
---|
6022 | Node: Debug Options118770
|
---|
6023 | Node: Find Expressions119731
|
---|
6024 | Node: Invoking locate120097
|
---|
6025 | Node: Invoking updatedb125988
|
---|
6026 | Node: Invoking xargs129673
|
---|
6027 | Node: Regular Expressions134703
|
---|
6028 | Node: findutils-default regular expression syntax135898
|
---|
6029 | Node: awk regular expression syntax138404
|
---|
6030 | Node: egrep regular expression syntax140289
|
---|
6031 | Node: emacs regular expression syntax142500
|
---|
6032 | Node: gnu-awk regular expression syntax145029
|
---|
6033 | Node: grep regular expression syntax147369
|
---|
6034 | Node: posix-awk regular expression syntax150095
|
---|
6035 | Node: posix-basic regular expression syntax152366
|
---|
6036 | Node: posix-egrep regular expression syntax155005
|
---|
6037 | Node: posix-extended regular expression syntax157378
|
---|
6038 | Node: Environment Variables159853
|
---|
6039 | Node: Common Tasks161797
|
---|
6040 | Node: Viewing And Editing162222
|
---|
6041 | Node: Archiving163228
|
---|
6042 | Node: Cleaning Up164860
|
---|
6043 | Node: Strange File Names166649
|
---|
6044 | Node: Fixing Permissions168299
|
---|
6045 | Node: Classifying Files168863
|
---|
6046 | Node: Worked Examples169581
|
---|
6047 | Node: Deleting Files170218
|
---|
6048 | Node: Updating A Timestamp File183238
|
---|
6049 | Node: Security Considerations189968
|
---|
6050 | Node: Levels of Risk191502
|
---|
6051 | Ref: Levels of Risk-Footnote-1194300
|
---|
6052 | Node: Security Considerations for find194479
|
---|
6053 | Ref: Security Considerations for find-Footnote-1196801
|
---|
6054 | Node: Problems with -exec and filenames196874
|
---|
6055 | Node: Changing the Current Working Directory198137
|
---|
6056 | Node: O_NOFOLLOW199906
|
---|
6057 | Ref: O_NOFOLLOW-Footnote-1201550
|
---|
6058 | Node: Systems without O_NOFOLLOW201652
|
---|
6059 | Node: Race Conditions with -exec203756
|
---|
6060 | Node: Race Conditions with -print and -print0206667
|
---|
6061 | Node: Security Considerations for xargs207587
|
---|
6062 | Node: Security Considerations for locate209657
|
---|
6063 | Node: Security Summary210354
|
---|
6064 | Node: Error Messages211111
|
---|
6065 | Node: Error Messages From find212123
|
---|
6066 | Node: Error Messages From xargs216980
|
---|
6067 | Node: Error Messages From locate218740
|
---|
6068 | Node: Error Messages From updatedb219972
|
---|
6069 | Node: Primary Index220375
|
---|
6070 |
|
---|
6071 | End Tag Table
|
---|