Merged latest changes from 4.2.x branch
[findutils.git] / doc / find.texi
blobaaa7b41f5c4b8a5b3a1c74846351f84cacd8ad6a
1 \input texinfo @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename find.info
4 @settitle Finding Files
5 @c For double-sided printing, uncomment:
6 @c @setchapternewpage odd
7 @c %**end of header
9 @include version.texi
11 @iftex
12 @finalout
13 @end iftex
15 @dircategory Basics
16 @direntry
17 * Finding files: (find).        Operating on files matching certain criteria.
18 @end direntry
20 @dircategory Individual utilities
21 @direntry
22 * find: (find)Invoking find.                    Finding and acting on files.
23 * locate: (find)Invoking locate.                Finding files in a database.
24 * updatedb: (find)Invoking updatedb.            Building the locate database.
25 * xargs: (find)Invoking xargs.                  Operating on many files.
26 @end direntry
28 @copying
30 This file documents the GNU utilities for finding files that match
31 certain criteria and performing various operations on them.
33 Copyright (C) 1994, 1996, 1998, 2000, 2001, 2003, 2004, 2005 Free
34 Software Foundation, Inc.
36 Permission is granted to make and distribute verbatim copies of
37 this manual provided the copyright notice and this permission notice
38 are preserved on all copies.
40 @ignore
41 Permission is granted to process this file through TeX and print the
42 results, provided the printed document carries copying permission
43 notice identical to this one except for the removal of this paragraph
44 (this paragraph not being relevant to the printed manual).
46 @end ignore
47 Permission is granted to copy and distribute modified versions of this
48 manual under the conditions for verbatim copying, provided that the
49 entire resulting derived work is distributed under the terms of a
50 permission notice identical to this one.
52 Permission is granted to copy and distribute translations of this
53 manual into another language, under the above conditions for modified
54 versions, except that this permission notice may be stated in a
55 translation approved by the Foundation.
56 @end copying
58 @titlepage
59 @title Finding Files
60 @subtitle Edition @value{EDITION}, for GNU @code{find} version @value{VERSION}
61 @subtitle @value{UPDATED}
62 @author by David MacKenzie and James Youngman
64 @page
65 @vskip 0pt plus 1filll
66 @insertcopying{}
67 @end titlepage
69 @contents
71 @ifnottex
72 @node Top, Introduction, , (dir)
73 @comment  node-name,  next,  previous,  up
75 This file documents the GNU utilities for finding files that match
76 certain criteria and performing various actions on them.
78 This is edition @value{EDITION}, for @code{find} version @value{VERSION}.
79 @end ifnottex
81 @c The master menu, created with texinfo-master-menu, goes here.
83 @menu
84 * Introduction::                Summary of the tasks this manual describes.
85 * Finding Files::               Finding files that match certain criteria.
86 * Actions::                     Doing things to files you have found.
87 * Databases::                   Maintaining file name databases.
88 * File Permissions::            How to control access to files.
89 * Reference::                   Summary of how to invoke the programs.
90 * Common Tasks::                Solutions to common real-world problems.
91 * Worked Examples::             Examples demonstrating more complex points.
92 * Security Considerations::     Security issues relating to findutils.
93 * Error Messages::              Explanations of some messages you might see.
94 * Primary Index::               The components of @code{find} expressions.
95 @end menu
97 @node Introduction, Finding Files, Top, Top
98 @chapter Introduction
100 This manual shows how to find files that meet criteria you specify,
101 and how to perform various actions on the files that you find.  The
102 principal programs that you use to perform these tasks are
103 @code{find}, @code{locate}, and @code{xargs}.  Some of the examples in
104 this manual use capabilities specific to the GNU versions of those
105 programs.
107 GNU @code{find} was originally written by Eric Decker, with
108 enhancements by David MacKenzie, Jay Plett, and Tim Wood.  GNU
109 @code{xargs} was originally written by Mike Rendell, with enhancements
110 by David MacKenzie.  GNU @code{locate} and its associated utilities
111 were originally written by James Woods, with enhancements by David
112 MacKenzie.  The idea for @samp{find -print0} and @samp{xargs -0} came
113 from Dan Bernstein.  The current maintainer of GNU findutils (and this
114 manual) is James Youngman.  Many other people have contributed bug
115 fixes, small improvements, and helpful suggestions.  Thanks!
117 To report a bug in GNU findutils, please use the form on the Savannah
118 web site at
119 @code{http://savannah.gnu.org/bugs/?group=findutils}.  Reporting bugs
120 this way means that you will then be able to track progress in fixing
121 the problem.  
123 If you don't have web access, you can also just send mail to the
124 mailing list.  The mailing list @email{bug-findutils@@gnu.org} carries
125 discussion of bugs in findutils, questions and answers about the
126 software and discussion of the development of the programs.  To join
127 the list, send email to @email{bug-findutils-request@@gnu.org}.
129 Please read any relevant sections of this manual before asking for
130 help on the mailing list.  You may also find it helpful to read the
131 NON-BUGS section of the @code{find} manual page.
133 If you ask for help on the mailing list, people will be able to help
134 you much more effectively if you include the following things:
136 @itemize @bullet
137 @item The version of the software you are running.  You can find this
138 out by running @samp{locate --version}.
139 @item What you were trying to do
140 @item The @emph{exact} command line you used
141 @item The @emph{exact} output you got (if this is very long, try to
142 find a smaller example which exhibits the same problem)
143 @item The output you expected to get
144 @end itemize
146 @menu
147 * Scope::
148 * Overview::
149 * find Expressions::
150 @end menu
152 @node Scope
153 @section Scope
155 For brevity, the word @dfn{file} in this manual means a regular file,
156 a directory, a symbolic link, or any other kind of node that has a
157 directory entry.  A directory entry is also called a @dfn{file name}.
158 A file name may contain some, all, or none of the directories in a
159 path that leads to the file.  These are all examples of what this
160 manual calls ``file names'':
162 @example
163 parser.c
164 README
165 ./budget/may-94.sc
166 fred/.cshrc
167 /usr/local/include/termcap.h
168 @end example
170 A @dfn{directory tree} is a directory and the files it contains, all
171 of its subdirectories and the files they contain, etc.  It can also be
172 a single non-directory file.
174 These programs enable you to find the files in one or more directory
175 trees that:
177 @itemize @bullet
178 @item
179 have names that contain certain text or match a certain pattern;
180 @item
181 are links to certain files;
182 @item
183 were last used during a certain period of time;
184 @item
185 are within a certain size range;
186 @item
187 are of a certain type (regular file, directory, symbolic link, etc.);
188 @item
189 are owned by a certain user or group;
190 @item
191 have certain access permissions;
192 @item
193 contain text that matches a certain pattern;
194 @item
195 are within a certain depth in the directory tree;
196 @item
197 or some combination of the above.
198 @end itemize
200 Once you have found the files you're looking for (or files that are
201 potentially the ones you're looking for), you can do more to them than
202 simply list their names.  You can get any combination of the files'
203 attributes, or process the files in many ways, either individually or
204 in groups of various sizes.  Actions that you might want to perform on
205 the files you have found include, but are not limited to:
207 @itemize @bullet
208 @item
209 view or edit
210 @item
211 store in an archive
212 @item
213 remove or rename
214 @item
215 change access permissions
216 @item
217 classify into groups
218 @end itemize
220 This manual describes how to perform each of those tasks, and more.
222 @node Overview
223 @section Overview
225 The principal programs used for making lists of files that match given
226 criteria and running commands on them are @code{find}, @code{locate},
227 and @code{xargs}.  An additional command, @code{updatedb}, is used by
228 system administrators to create databases for @code{locate} to use.
230 @code{find} searches for files in a directory hierarchy and prints
231 information about the files it found.  It is run like this:
233 @example
234 find @r{[}@var{file}@dots{}@r{]} @r{[}@var{expression}@r{]}
235 @end example
237 @noindent
238 Here is a typical use of @code{find}.  This example prints the names
239 of all files in the directory tree rooted in @file{/usr/src} whose
240 name ends with @samp{.c} and that are larger than 100 Kilobytes.
241 @example
242 find /usr/src -name '*.c' -size +100k -print
243 @end example
245 Notice that the wildcard must be enclosed in quotes in order to
246 protect it from expansion by the shell.
248 @code{locate} searches special file name databases for file names that
249 match patterns.  The system administrator runs the @code{updatedb}
250 program to create the databases.  @code{locate} is run like this:
252 @example
253 locate @r{[}@var{option}@dots{}@r{]} @var{pattern}@dots{}
254 @end example
256 @noindent
257 This example prints the names of all files in the default file name
258 database whose name ends with @samp{Makefile} or @samp{makefile}.
259 Which file names are stored in the database depends on how the system
260 administrator ran @code{updatedb}.
261 @example
262 locate '*[Mm]akefile'
263 @end example
265 The name @code{xargs}, pronounced EX-args, means ``combine
266 arguments.''  @code{xargs} builds and executes command lines by
267 gathering together arguments it reads on the standard input.  Most
268 often, these arguments are lists of file names generated by
269 @code{find}.  @code{xargs} is run like this:
271 @example
272 xargs @r{[}@var{option}@dots{}@r{]} @r{[}@var{command} @r{[}@var{initial-arguments}@r{]}@r{]}
273 @end example
275 @noindent
276 The following command searches the files listed in the file
277 @file{file-list} and prints all of the lines in them that contain the
278 word @samp{typedef}.
279 @example
280 xargs grep typedef < file-list
281 @end example
283 @node find Expressions
284 @section @code{find} Expressions
286 The expression that @code{find} uses to select files consists of one
287 or more @dfn{primaries}, each of which is a separate command line
288 argument to @code{find}.  @code{find} evaluates the expression each
289 time it processes a file.  An expression can contain any of the
290 following types of primaries:
292 @table @dfn
293 @item options
294 affect overall operation rather than the processing of a specific
295 file;
296 @item tests
297 return a true or false value, depending on the file's attributes;
298 @item actions
299 have side effects and return a true or false value; and
300 @item operators
301 connect the other arguments and affect when and whether they are
302 evaluated.
303 @end table
305 You can omit the operator between two primaries; it defaults to
306 @samp{-and}.  @xref{Combining Primaries With Operators}, for ways to
307 connect primaries into more complex expressions.  If the expression
308 contains no actions other than @samp{-prune}, @samp{-print} is
309 performed on all files for which the entire expression is true
310 (@pxref{Print File Name}).
312 Options take effect immediately, rather than being evaluated for each
313 file when their place in the expression is reached.  Therefore, for
314 clarity, it is best to place them at the beginning of the expression.
316 Many of the primaries take arguments, which immediately follow them in
317 the next command line argument to @code{find}.  Some arguments are
318 file names, patterns, or other strings; others are numbers.  Numeric
319 arguments can be specified as
321 @table @code
322 @item +@var{n}
323 for greater than @var{n},
324 @item -@var{n}
325 for less than @var{n},
326 @item @var{n}
327 for exactly @var{n}.
328 @end table
330 @node Finding Files, Actions, Introduction, Top
331 @chapter Finding Files
333 By default, @code{find} prints to the standard output the names of the
334 files that match the given criteria.  @xref{Actions}, for how to get
335 more information about the matching files.
338 @menu
339 * Name::
340 * Links::
341 * Time::
342 * Size::
343 * Type::
344 * Owner::
345 * Permissions::
346 * Contents::
347 * Directories::
348 * Filesystems::
349 * Combining Primaries With Operators::
350 @end menu
352 @node Name
353 @section Name
355 Here are ways to search for files whose name matches a certain
356 pattern.  @xref{Shell Pattern Matching}, for a description of the
357 @var{pattern} arguments to these tests.
359 Each of these tests has a case-sensitive version and a
360 case-insensitive version, whose name begins with @samp{i}.  In a
361 case-insensitive comparison, the patterns @samp{fo*} and @samp{F??}
362 match the file names @file{Foo}, @samp{FOO}, @samp{foo}, @samp{fOo},
363 etc.
365 @menu
366 * Base Name Patterns::
367 * Full Name Patterns::
368 * Fast Full Name Search::
369 * Shell Pattern Matching::      Wildcards used by these programs.
370 @end menu
372 @node Base Name Patterns
373 @subsection Base Name Patterns
375 @deffn Test -name pattern
376 @deffnx Test -iname pattern
377 True if the base of the file name (the path with the leading
378 directories removed) matches shell pattern @var{pattern}.  For
379 @samp{-iname}, the match is case-insensitive.@footnote{Because we
380 need to perform case-insensitive matching, the GNU fnmatch
381 implementation is always used; if the C library includes the GNU
382 implementation, we use that and otherwise we use the one from gnulib}
383 To ignore a whole directory tree, use @samp{-prune}
384 (@pxref{Directories}).  As an example, to find Texinfo source files in
385 @file{/usr/local/doc}:
387 @example
388 find /usr/local/doc -name '*.texi'
389 @end example
391 Notice that the wildcard must be enclosed in quotes in order to
392 protect it from expansion by the shell.
394 As of findutils version 4.2.2, patterns for @samp{-name} and
395 @samp{-iname} will match a file name with a leading @samp{.}.  For
396 example the command @samp{find /tmp -name \*bar} will match the file
397 @file{/tmp/.foobar}.  Braces within the pattern (@samp{@{@}}) are not
398 considered to be special (that is, @code{find . -name 'foo@{1,2@}'}
399 matches a file named @file{foo@{1,2@}}, not the files @file{foo1} and
400 @file{foo2}.
401 @end deffn
404 @node Full Name Patterns
405 @subsection Full Name Patterns
407 @deffn Test -wholename pattern
408 @deffnx Test -iwholename pattern
409 True if the entire file name, starting with the command line argument
410 under which the file was found, matches shell pattern @var{pattern}.
411 For @samp{-iwholename}, the match is case-insensitive.  To ignore a
412 whole directory tree, use @samp{-prune} rather than checking every
413 file in the tree (@pxref{Directories}).  The ``entire file name'' as
414 used by @code{find} starts with the starting-point specified on the
415 command line, and is not converted to an absolute pathname, so for
416 example @code{cd /; find tmp -wholename /tmp} will never match
417 anything.
418 @end deffn
420 @deffn Test -path pattern
421 @deffnx Test -ipath pattern
422 These tests are deprecated, but work as for @samp{-wholename} and
423 @samp{-iwholename}, respectively.  The @samp{-ipath} test is a GNU
424 extension, but @samp{-path} is also provided by HP-UX @code{find}.
425 @end deffn
427 @deffn Test -regex expr
428 @deffnx Test -iregex expr
429 True if the entire file name matches regular expression @var{expr}.
430 This is a match on the whole path, not a search.  For example, to
431 match a file named @file{./fubar3}, you can use the regular expression
432 @samp{.*bar.} or @samp{.*b.*3}, but not @samp{f.*r3}.  @xref{Regexps,
433 , Syntax of Regular Expressions, emacs, The GNU Emacs Manual}, for a
434 description of the syntax of regular expressions.  For @samp{-iregex},
435 the match is case-insensitive.  There are several varieties of regular
436 expressions; by default this test uses POSIX basic regular
437 expressions, but this can be changed with the option
438 @samp{-regextype}.
439 @end deffn
441 @deffn Option -regextype name
442 This option controls the variety of regular expression syntax
443 understood by the @samp{-regex} and @samp{-iregex} tests.  This option
444 is positional; that is, it only affects regular expressions which
445 occur later in the command line.  If this option is not given, GNU
446 Emacs regular expressions are assumed.  Currently-implemented types
450 @table @samp
451 @item emacs
452 Regular expressions compatible with GNU Emacs; this is also the
453 default behaviour if this option is not used.
454 @item posix-awk
455 Regular expressions compatible with the POSIX awk command (not GNU awk)
456 @item posix-basic
457 POSIX Basic Regular Expressions.
458 @item posix-egrep
459 Regular expressions compatible with the POSIX egrep command
460 @item posix-extended
461 POSIX Extended Regular Expressions
462 @end table
464 @ref{Regular Expressions} for more information on the regular
465 expression dialects understood by GNU findutils.
468 @end deffn
470 @node Fast Full Name Search
471 @subsection Fast Full Name Search
473 To search for files by name without having to actually scan the
474 directories on the disk (which can be slow), you can use the
475 @code{locate} program.  For each shell pattern you give it,
476 @code{locate} searches one or more databases of file names and
477 displays the file names that contain the pattern.  @xref{Shell Pattern
478 Matching}, for details about shell patterns.
480 If a pattern is a plain string---it contains no
481 metacharacters---@code{locate} displays all file names in the database
482 that contain that string.  If a pattern contains
483 metacharacters, @code{locate} only displays file names that match the
484 pattern exactly.  As a result, patterns that contain metacharacters
485 should usually begin with a @samp{*}, and will most often end with one
486 as well.  The exceptions are patterns that are intended to explicitly
487 match the beginning or end of a file name.
489 If you only want @code{locate} to match against the last component of
490 the file names (the ``base name'' of the files) you can use the
491 @samp{--basename} option.  The opposite behaviour is the default, but
492 can be selected explicitly by using the option @samp{--wholename}.
494 The command
495 @example
496 locate @var{pattern}
497 @end example
499 is almost equivalent to
500 @example
501 find @var{directories} -name @var{pattern}
502 @end example
504 where @var{directories} are the directories for which the file name
505 databases contain information.  The differences are that the
506 @code{locate} information might be out of date, and that @code{locate}
507 handles wildcards in the pattern slightly differently than @code{find}
508 (@pxref{Shell Pattern Matching}).
510 The file name databases contain lists of files that were on the system
511 when the databases were last updated.  The system administrator can
512 choose the file name of the default database, the frequency with which
513 the databases are updated, and the directories for which they contain
514 entries.
516 Here is how to select which file name databases @code{locate}
517 searches.  The default is system-dependent.
519 @table @code
520 @item --database=@var{path}
521 @itemx -d @var{path}
522 Instead of searching the default file name database, search the file
523 name databases in @var{path}, which is a colon-separated list of
524 database file names.  You can also use the environment variable
525 @code{LOCATE_PATH} to set the list of database files to search.  The
526 option overrides the environment variable if both are used.
527 @end table
529 @node Shell Pattern Matching
530 @subsection Shell Pattern Matching
532 @code{find} and @code{locate} can compare file names, or parts of file
533 names, to shell patterns.  A @dfn{shell pattern} is a string that may
534 contain the following special characters, which are known as
535 @dfn{wildcards} or @dfn{metacharacters}.
537 You must quote patterns that contain metacharacters to prevent the
538 shell from expanding them itself.  Double and single quotes both work;
539 so does escaping with a backslash.
541 @table @code
542 @item *
543 Matches any zero or more characters.
545 @item ?
546 Matches any one character.
548 @item [@var{string}]
549 Matches exactly one character that is a member of the string
550 @var{string}.  This is called a @dfn{character class}.  As a
551 shorthand, @var{string} may contain ranges, which consist of two
552 characters with a dash between them.  For example, the class
553 @samp{[a-z0-9_]} matches a lowercase letter, a number, or an
554 underscore.  You can negate a class by placing a @samp{!} or @samp{^}
555 immediately after the opening bracket.  Thus, @samp{[^A-Z@@]} matches
556 any character except an uppercase letter or an at sign.
558 @item \
559 Removes the special meaning of the character that follows it.  This
560 works even in character classes.
561 @end table
563 In the @code{find} tests that do shell pattern matching (@samp{-name},
564 @samp{-wholename}, etc.), wildcards in the pattern will match a
565 @samp{.}  at the beginning of a file name.  This is also the case for
566 @code{locate}.  Thus, @samp{find -name '*macs'} will match a file
567 named @file{.emacs}, as will @samp{locate '*macs'}.
569 Slash characters have no special significance in the shell pattern
570 matching that @code{find} and @code{locate} do, unlike in the shell,
571 in which wildcards do not match them.  Therefore, a pattern
572 @samp{foo*bar} can match a file name @samp{foo3/bar}, and a pattern
573 @samp{./sr*sc} can match a file name @samp{./src/misc}.
575 If you want to locate some files with the @samp{locate} command but
576 don't need to see the full list you can use the @samp{--limit} option
577 to see just a small number of results, or the @samp{--count} option to
578 display only the total number of matches.
580 @node Links
581 @section Links
583 There are two ways that files can be linked together.  @dfn{Symbolic
584 links} are a special type of file whose contents are a portion of the
585 name of another file.  @dfn{Hard links} are multiple directory entries
586 for one file; the file names all have the same index node
587 (@dfn{inode}) number on the disk.
589 @menu
590 * Symbolic Links::
591 * Hard Links::
592 @end menu
594 @node Symbolic Links
595 @subsection Symbolic Links
597 Symbolic links are names that reference other files.  GNU @code{find}
598 will handle symbolic links in one of two ways; firstly, it can
599 dereference the links for you - this means that if it comes across a
600 symbolic link, it examines the file that the link points to, in order
601 to see if it matches the criteria you have specified.  Secondly, it
602 can check the link itself in case you might be looking for the actual
603 link.  If the file that the symbolic link points to is also within the
604 directory hierarchy you are searching with the @code{find} command,
605 you may not see a great deal of difference between these two
606 alternatives.
608 By default, @code{find} examines symbolic links themselves when it
609 finds them (and, if it later comes across the linked-to file, it will
610 examine that, too).  If you would prefer @code{find} to dereference
611 the links and examine the file that each link points to, specify the
612 @samp{-L} option to @code{find}.  You can explicitly specify the
613 default behaviour by using the @samp{-P} option.  The @samp{-H}
614 option is a half-way-between option which ensures that any symbolic
615 links listed on the command line are dereferenced, but other symbolic
616 links are not.
618 Symbolic links are different to ``hard links'' in the sense that you
619 need permissions upon the linked-to file in order to be able to
620 dereference the link.  This can mean that even if you specify the
621 @samp{-L} option, @code{find} may not be able to determine the
622 properties of the file that the link points to (because you don't have
623 sufficient permissions).  In this situation, @code{find} uses the
624 properties of the link itself.  This also occurs if a symbolic link
625 exists but points to a file that is missing.
627 The options controlling the behaviour of @code{find} with respect to
628 links are as follows :-
630 @table @samp
631 @item -P
632 @code{find} does not dereference symbolic links at all.  This is the
633 default behaviour.  This option must be specified before any of the
634 file names on the command line.
635 @item -H
636 @code{find} does not dereference symbolic links (except in the case of
637 file names on the command line, which are dereferenced).  If a
638 symbolic link cannot be dereferenced, the information for the symbolic
639 link itself is used.  This option must be specified before any of the
640 file names on the command line.
641 @item -L
642 @code{find} dereferences symbolic links where possible, and where this
643 is not possible it uses the properties of the symbolic link itself.
644 This option must be specified before any of the file names on the
645 command line.  Use of this option also implies the same behaviour as
646 the @samp{-noleaf} option.  If you later use the @samp{-H} or
647 @samp{-P} options, this does not turn off @samp{-noleaf}.
649 @item -follow
650 This option forms part of the ``expression'' and must be specified
651 after the file names, but it is otherwise equivalent to @samp{-L}.
652 The @samp{-follow} option affects only those tests which appear after
653 it on the command line.  This option is deprecated.  Where possible,
654 you should use @samp{-L} instead.
655 @end table
657 The following differences in behavior occur when the @samp{-L} option
658 is used:
660 @itemize @bullet
661 @item
662 @code{find} follows symbolic links to directories when searching
663 directory trees.
664 @item
665 @samp{-lname} and @samp{-ilname} always return false (unless they
666 happen to match broken symbolic links).
667 @item
668 @samp{-type} reports the types of the files that symbolic links point
669 to.  This means that in combination with @samp{-L}, @samp{-type l}
670 will be true only for broken symbolic links.  To check for symbolic
671 links when @samp{-L} has been specified, use @samp{-xtype l}.
672 @item
673 Implies @samp{-noleaf} (@pxref{Directories}).
674 @end itemize
676 If the @samp{-L} option or the @samp{-H} option is used,
677 the file names used as arguments to @samp{-newer}, @samp{-anewer}, and
678 @samp{-cnewer} are dereferenced and the timestamp from the pointed-to
679 file is used instead (if possible -- otherwise the timestamp from the
680 symbolic link is used).
682 @deffn Test -lname pattern
683 @deffnx Test -ilname pattern
684 True if the file is a symbolic link whose contents match shell pattern
685 @var{pattern}.  For @samp{-ilname}, the match is case-insensitive.
686 @xref{Shell Pattern Matching}, for details about the @var{pattern}
687 argument.  If the @samp{-L} option is in effect, this test will always
688 return false for symbolic links unless they are broken.  So, to list
689 any symbolic links to @file{sysdep.c} in the current directory and its
690 subdirectories, you can do:
692 @example
693 find . -lname '*sysdep.c'
694 @end example
695 @end deffn
697 @node Hard Links
698 @subsection Hard Links
700 Hard links allow more than one name to refer to the same file.  To
701 find all the names which refer to the same file as NAME, use
702 @samp{-samefile NAME}.  If you are not using the @samp{-L} option, you
703 can confine your search to one filesystem using the @samp{-xdev}
704 option.  This is useful because hard links cannot point outside a
705 single filesystem, so this can cut down on needless searching.
707 If the @samp{-L} option is in effect, and NAME is in fact a symbolic
708 link, the symbolic link will be dereferenced.  Hence you are searching
709 for other links (hard or symbolic) to the file pointed to by NAME.  If
710 @samp{-L} is in effect but NAME is not itself a symbolic link, other
711 symbolic links to the file NAME will be matched.
713 You can also search for files by inode number.  This can occasionally
714 be useful in diagnosing problems with filesystems for example, because
715 @code{fsck} tends to print inode numbers.  Inode numbers also
716 occasionally turn up in log messages for some types of software, and
717 are used to support the @code{ftok()} library function.
719 You can learn a file's inode number and the number of links to it by
720 running @samp{ls -li} or @samp{find -ls}.
722 You can search for hard links to inode number NUM by using @samp{-inum
723 NUM}. If there are any filesystem mount points below the directory
724 where you are starting the search, use the @samp{-xdev} option unless
725 you are also using the @samp{-L} option.  Using @samp{-xdev} this
726 saves needless searching, since hard links to a file must be on the
727 same filesystem.  @xref{Filesystems}.
729 @deffn Test -samefile NAME
730 File is a hard link to the same inode as NAME.  If the @samp{-L}
731 option is in effect, symbolic links to the same file as NAME points to
732 are also matched.
733 @end deffn
735 @deffn Test -inum n
736 File has inode number @var{n}.  The @samp{+} and @samp{-} qualifiers
737 also work, though these are rarely useful.  Much of the time it is
738 easier to use @samp{-samefile} rather than this option.
739 @end deffn
741 You can also search for files that have a certain number of links,
742 with @samp{-links}.  Directories normally have at least two hard
743 links; their @file{.} entry is the second one.  If they have
744 subdirectories, each of those also has a hard link called @file{..} to
745 its parent directory.  The @file{.} and @file{..} directory entries
746 are not normally searched unless they are mentioned on the @code{find}
747 command line.
749 @deffn Test -links n
750 File has @var{n} hard links.
751 @end deffn
753 @deffn Test -links +n
754 File has more than @var{n} hard links.
755 @end deffn
757 @deffn Test -links -n
758 File has fewer than @var{n} hard links.
759 @end deffn
761 @node Time
762 @section Time
764 Each file has three time stamps, which record the last time that
765 certain operations were performed on the file:
767 @enumerate
768 @item
769 access (read the file's contents)
770 @item
771 change the status (modify the file or its attributes)
772 @item
773 modify (change the file's contents)
774 @end enumerate
776 There is no timestamp that indicates when a file was @emph{created}.
778 You can search for files whose time stamps are within a certain age
779 range, or compare them to other time stamps.
781 @menu
782 * Age Ranges::
783 * Comparing Timestamps::
784 @end menu
786 @node Age Ranges
787 @subsection Age Ranges
789 These tests are mainly useful with ranges (@samp{+@var{n}} and
790 @samp{-@var{n}}).
792 @deffn Test -atime n
793 @deffnx Test -ctime n
794 @deffnx Test -mtime n
795 True if the file was last accessed (or its status changed, or it was
796 modified) @var{n}*24 hours ago.  The number of 24-hour periods since
797 the file's timestamp is always rounded down; therefore 0 means ``less
798 than 24 hours ago'', 1 means ``between 24 and 48 hours ago'', and so
799 forth.
800 @end deffn
802 @deffn Test -amin n
803 @deffnx Test -cmin n
804 @deffnx Test -mmin n
805 True if the file was last accessed (or its status changed, or it was
806 modified) @var{n} minutes ago.  These tests provide finer granularity
807 of measurement than @samp{-atime} et al., but rounding is done in a
808 similar way.  For example, to list files in @file{/u/bill} that were
809 last read from 2 to 6 minutes ago:
811 @example
812 find /u/bill -amin +2 -amin -6
813 @end example
814 @end deffn
816 @deffn Option -daystart
817 Measure times from the beginning of today rather than from 24 hours
818 ago.  So, to list the regular files in your home directory that were
819 modified yesterday, do
821 @example
822 find ~ -daystart -type f -mtime 1
823 @end example
825 The @samp{-daystart} option is unlike most other options in that it
826 has an effect on the way that other tests are performed.  The affected
827 tests are @samp{-amin}, @samp{-cmin}, @samp{-mmin}, @samp{-atime},
828 @samp{-ctime} and @samp{-mtime}.  The @samp{-daystart} option only
829 affects the behaviour of any tests which appear after it on the
830 command line.
831 @end deffn
833 @node Comparing Timestamps
834 @subsection Comparing Timestamps
836 As an alternative to comparing timestamps to the current time, you can
837 compare them to another file's timestamp.  That file's timestamp could
838 be updated by another program when some event occurs.  Or you could
839 set it to a particular fixed date using the @code{touch} command.  For
840 example, to list files in @file{/usr} modified after February 1 of the
841 current year:
843 @c Idea from Rick Sladkey.
844 @example
845 touch -t 02010000 /tmp/stamp$$
846 find /usr -newer /tmp/stamp$$
847 rm -f /tmp/stamp$$
848 @end example
850 @deffn Test -anewer file
851 @deffnx Test -cnewer file
852 @deffnx Test -newer file
853 True if the file was last accessed (or its status changed, or it was
854 modified) more recently than @var{file} was modified.  These tests are
855 affected by @samp{-follow} only if @samp{-follow} comes before them on
856 the command line.  @xref{Symbolic Links}, for more information on
857 @samp{-follow}.  As an example, to list any files modified since
858 @file{/bin/sh} was last modified:
860 @example
861 find . -newer /bin/sh
862 @end example
863 @end deffn
865 @deffn Test -used n
866 True if the file was last accessed @var{n} days after its status was
867 last changed.  Useful for finding files that are not being used, and
868 could perhaps be archived or removed to save disk space.
869 @end deffn
871 @node Size
872 @section Size
874 @deffn Test -size n@r{[}bckwMG@r{]}
875 True if the file uses @var{n} units of space, rounding up.  The units
876 are 512-byte blocks by default, but they can be changed by adding a
877 one-character suffix to @var{n}:
879 @table @code
880 @item b
881 512-byte blocks (never 1024)
882 @item c
883 bytes
884 @item k
885 kilobytes (1024 bytes)
886 @item w
887 2-byte words
888 @item M
889 Megabytes (units of 1048576 bytes)
890 @item G
891 Gigabytes (units of 1073741824 bytes)
892 @end table
894 The `b' suffix always considers blocks to be 512 bytes.  This is not
895 affected by the setting (or non-setting) of the POSIXLY_CORRECT
896 environment variable.  This behaviour is different to the behaviour of
897 the @samp{-ls} action).  If you want to use 1024-byte units, use the
898 `k' suffix instead.
900 The number can be prefixed with a `+' or a `-'.  A plus sign indicates
901 that the test should succeed if the file uses at least @var{n} units
902 of storage (a common use of this test) and a minus sign
903 indicates that the test should succeed if the file uses less than
904 @var{n} units of storage.  There is no `=' prefix, because that's the
905 default anyway.
907 The size does not count indirect blocks, but it does count blocks in
908 sparse files that are not actually allocated.  In other words, it's
909 consistent with the result you get for @samp{ls -l} or @samp{wc -c}.
910 This handling of sparse files differs from the output of the @samp{%k}
911 and @samp{%b} format specifiers for the @samp{-printf} predicate.
913 @end deffn
915 @deffn Test -empty
916 True if the file is empty and is either a regular file or a directory.
917 This might help determine good candidates for deletion.  This test is
918 useful with @samp{-depth} (@pxref{Directories}) and @samp{-delete}
919 (@pxref{Single File}).
920 @end deffn
922 @node Type
923 @section Type
925 @deffn Test -type c
926 True if the file is of type @var{c}:
928 @table @code
929 @item b
930 block (buffered) special
931 @item c
932 character (unbuffered) special
933 @item d
934 directory
935 @item p
936 named pipe (FIFO)
937 @item f
938 regular file
939 @item l
940 symbolic link; if @samp{-L} is in effect, this is true only for broken
941 symbolic links.  If you want to search for symbolic links when
942 @samp{-L} is in effect, use @samp{-xtype} instead of @samp{-type}.
943 @item s
944 socket
945 @item D
946 door (Solaris)
947 @end table
948 @end deffn
950 @deffn Test -xtype c
951 This test behaves the same as @samp{-type} unless the file is a
952 symbolic link.  If the file is a symbolic link, the result is as
953 follows (in the table below, @samp{X} should be understood to
954 represent any letter except @samp{l}):
956 @table @samp
957 @item @samp{-P -xtype l}
958 True if the symbolic link is broken
959 @item @samp{-P -xtype X}
960 True if the (ultimate) target file is of type @samp{X}.
961 @item @samp{-L -xtype l}
962 Always true
963 @item @samp{-L -xtype X}
964 False unless the symbolic link is broken
965 @end table
967 In other words, for symbolic links, @samp{-xtype} checks the type of
968 the file that @samp{-type} does not check.  
970 The @samp{-H} option also affects the behaviour of @samp{-xtype}.
971 When @samp{-H} is in effect, @samp{-xtype} behaves as if @samp{-L} had
972 been specified when examining files listed on the command line, and as
973 if @samp{-P} had been specified otherwise.  If neither @samp{-H} nor
974 @samp{-L} was specified, @samp{-xtype} behaves as if @samp{-P} had
975 been specified.
977 @xref{Symbolic Links}, for more information on @samp{-follow} and
978 @samp{-L}.
979 @end deffn
981 @node Owner
982 @section Owner
984 @deffn Test -user uname
985 @deffnx Test -group gname
986 True if the file is owned by user @var{uname} (belongs to group
987 @var{gname}).  A numeric ID is allowed.
988 @end deffn
990 @deffn Test -uid n
991 @deffnx Test -gid n
992 True if the file's numeric user ID (group ID) is @var{n}.  These tests
993 support ranges (@samp{+@var{n}} and @samp{-@var{n}}), unlike
994 @samp{-user} and @samp{-group}.
995 @end deffn
997 @deffn Test -nouser
998 @deffnx Test -nogroup
999 True if no user corresponds to the file's numeric user ID (no group
1000 corresponds to the numeric group ID).  These cases usually mean that
1001 the files belonged to users who have since been removed from the
1002 system.  You probably should change the ownership of such files to an
1003 existing user or group, using the @code{chown} or @code{chgrp}
1004 program.
1005 @end deffn
1007 @node Permissions
1008 @section Permissions
1010 @xref{File Permissions}, for information on how file permissions are
1011 structured and how to specify them.
1013 Four tests determine what users can do with files.  These are
1014 @samp{-readable}, @samp{-writable}, @samp{-executable} and
1015 @samp{-perm}.  The first three tests ask the operating system if the
1016 current user can perform the relevant operation on a file, while
1017 @samp{-perm} just examines the file's mode.  The file mode may give
1018 a misleading impression of what the user can actually do, because the
1019 file may have an access control list, or exist on a read-only
1020 filesystem, for example.  Of these four tests though, only
1021 @samp{-perm} is specified by the POSIX standard.
1023 The @samp{-readable}, @samp{-writable} and @samp{-executable} tests
1024 are implemented via the @code{access} system call.  This is
1025 implemented within the operating system itself.  If the file being
1026 considered is on an NFS filesystem, the remote system may allow or
1027 forbid read or write operations for reasons of which the NFS client
1028 cannot take account.  This includes user-ID mapping, either in the
1029 general sense or the more restricted sense in which remote superusers
1030 are treated by the NFS server as if they are the local user
1031 @samp{nobody} on the NFS server.
1033 None of the tests in this section should be used to verify that a user
1034 is authorised to perform any operation (on the file being tested or
1035 any other file) because of the possibility of a race condition.  That
1036 is, the situation may change between the test and an action being
1037 taken on the basis of the result of that test.
1040 @deffn Test -readable 
1041 True if the file can be read by the invoking user.
1042 @end deffn
1044 @deffn Test -writable
1045 True if the file can be written by the invoking user.  This is an
1046 in-principle check, and other things may prevent a successful write
1047 operation; for example, the filesystem might be full.
1048 @end deffn
1050 @deffn Test -executable
1051 True if the file can be executed by the invoking user.
1052 @end deffn
1054 @deffn Test -perm mode
1056 True if the file's permissions are exactly @var{mode}, which can be
1057 numeric or symbolic.
1059 If @var{mode} starts with @samp{-}, true if
1060 @emph{all} of the permissions set in @var{mode} are set for the file;
1061 permissions not set in @var{mode} are ignored.
1063 If @var{mode} starts with @samp{/}, true if
1064 @emph{any} of the permissions set in @var{mode} are set for the file;
1065 permissions not set in @var{mode} are ignored.
1066 This is a GNU extension.
1068 If you don't use the @samp{/} or @samp{-} form with a symbolic mode
1069 string, you may have to specify a rather complex mode string.  For
1070 example @samp{-perm g=w} will only match files which have mode 0020
1071 (that is, ones for which group write permission is the only permission
1072 set).  It is more likely that you will want to use the @samp{/} or
1073 @samp{-} forms, for example @samp{-perm -g=w}, which matches any file
1074 with group write permission.
1077 @table @samp
1078 @item -perm 664
1079 Match files which have read and write permission for their owner,
1080 and group, but which the rest of the world can read but not write to.
1081 Files which meet these criteria but have other permissions bits set
1082 (for example if someone can execute the file) will not be matched.
1084 @item -perm -664
1085 Match files which have read and write permission for their owner,
1086 and group, but which the rest of the world can read but not write to,
1087 without regard to the presence of any extra permission bits (for
1088 example the executable bit).  This will match a file which has mode
1089 0777, for example.
1091 @item -perm /222
1092 Match files which are writeable by somebody (their owner, or
1093 their group, or anybody else).
1095 @item -perm /022
1096 Match files which are writeable by either their owner or their
1097 group.  The files don't have to be writeable by both the owner and
1098 group to be matched; either will do.
1100 @item -perm /g+w,o+w
1101 As above.
1103 @item -perm /g=w,o=w
1104 As above
1106 @item -perm -022
1107 Search for files which are writeable by both their owner and their
1108 group.
1110 @item -perm -444 -perm /222 ! -perm /111
1111 Search for files which are readable for everybody, have at least one
1112 write bit set (i.e. somebody can write to them), but which cannot be
1113 executed by anybody.  Note that in some shells the @samp{!} must be
1114 escaped;.
1116 @item -perm -a+r -perm /a+w ! -perm /a+x
1117 As above.
1120 @item -perm -g+w,o+w
1121 As above.
1122 @end table
1124 @quotation Warning
1125 If you specify @samp{-perm /000} or @samp{-perm /mode} where the
1126 symbolic mode @samp{mode} has no bits set, the test currently matches
1127 no files.  This differs from the behaviour of @samp{-perm -000}, which
1128 matches all files.  The behaviour of @samp{-perm /000} will be changed
1129 to be consistent with the behaviour of @samp{-perm -000}.  The change
1130 will probably be made in early 2006.
1131 @end quotation
1133 @end deffn
1135 @node Contents
1136 @section Contents
1138 To search for files based on their contents, you can use the
1139 @code{grep} program.  For example, to find out which C source files in
1140 the current directory contain the string @samp{thing}, you can do:
1142 @example
1143 grep -l thing *.[ch]
1144 @end example
1146 If you also want to search for the string in files in subdirectories,
1147 you can combine @code{grep} with @code{find} and @code{xargs}, like
1148 this:
1150 @example
1151 find . -name '*.[ch]' | xargs grep -l thing
1152 @end example
1154 The @samp{-l} option causes @code{grep} to print only the names of
1155 files that contain the string, rather than the lines that contain it.
1156 The string argument (@samp{thing}) is actually a regular expression,
1157 so it can contain metacharacters.  This method can be refined a little
1158 by using the @samp{-r} option to make @code{xargs} not run @code{grep}
1159 if @code{find} produces no output, and using the @code{find} action
1160 @samp{-print0} and the @code{xargs} option @samp{-0} to avoid
1161 misinterpreting files whose names contain spaces:
1163 @example
1164 find . -name '*.[ch]' -print0 | xargs -r -0 grep -l thing
1165 @end example
1167 For a fuller treatment of finding files whose contents match a
1168 pattern, see the manual page for @code{grep}.
1170 @node Directories
1171 @section Directories
1173 Here is how to control which directories @code{find} searches, and how
1174 it searches them.  These two options allow you to process a horizontal
1175 slice of a directory tree.
1177 @deffn Option -maxdepth levels
1178 Descend at most @var{levels} (a non-negative integer) levels of
1179 directories below the command line arguments.  @samp{-maxdepth 0}
1180 means only apply the tests and actions to the command line arguments.
1181 @end deffn
1183 @deffn Option -mindepth levels
1184 Do not apply any tests or actions at levels less than @var{levels} (a
1185 non-negative integer).  @samp{-mindepth 1} means process all files
1186 except the command line arguments.
1187 @end deffn
1189 @deffn Option -depth
1190 Process each directory's contents before the directory itself.  Doing
1191 this is a good idea when producing lists of files to archive with
1192 @code{cpio} or @code{tar}.  If a directory does not have write
1193 permission for its owner, its contents can still be restored from the
1194 archive since the directory's permissions are restored after its
1195 contents.
1196 @end deffn
1198 @deffn Option -d
1199 This is a deprecated synonym for @samp{-depth}, for compatibility with
1200 Mac OS X, FreeBSD and OpenBSD.  The @samp{-depth} option is a POSIX
1201 feature, so it is better to use that.
1202 @end deffn
1204 @deffn Action -prune
1205 If the file is a directory, do not descend into it.  The result is
1206 true.  For example, to skip the directory @file{src/emacs} and all
1207 files and directories under it, and print the names of the other files
1208 found:
1210 @example
1211 find . -wholename './src/emacs' -prune -o -print
1212 @end example
1214 The above command will not print @file{./src/emacs} among its list of
1215 results.  This however is not due to the effect of the @samp{-prune}
1216 action (which only prevents further descent, it doesn't make sure we
1217 ignore that item).  Instead, this effect is due to the use of
1218 @samp{-o}.  Since the left hand side of the ``or'' condition has
1219 succeeded for @file{./src/emacs}, it is not necessary to evaluate the
1220 right-hand-side (@samp{-print}) at all for this particular file.  If
1221 you wanted to print that directory name you could use either an extra
1222 @samp{-print} action:
1224 @example
1225 find . -wholename './src/emacs' -prune -print -o -print
1226 @end example
1228 or use the comma operator:
1230 @example
1231 find . -wholename './src/emacs' -prune , -print
1232 @end example
1234 If the @samp{-depth} option is in effect, the subdirectories will have
1235 already been visited in any case.  Hence @samp{-prune} has no effect
1236 and returns false.
1237 @end deffn
1240 @deffn Action -quit
1241 Exit immediately (with return value zero if no errors have occurred).
1242 No child processes will be left running, but no more files specified
1243 on the command line will be processed.  For example, @code{find
1244 /tmp/foo /tmp/bar -print -quit} will print only @samp{/tmp/foo}.  Any
1245 command lines which have been built by @samp{-exec ... \+} or
1246 @samp{-execdir ... \+} are invoked before the program is executed.
1247 @end deffn
1249 @deffn Option -noleaf
1250 Do not optimize by assuming that directories contain 2 fewer
1251 subdirectories than their hard link count.  This option is needed when
1252 searching filesystems that do not follow the Unix directory-link
1253 convention, such as CD-ROM or MS-DOS filesystems or AFS volume mount
1254 points.  Each directory on a normal Unix filesystem has at least 2
1255 hard links: its name and its @file{.}  entry.  Additionally, its
1256 subdirectories (if any) each have a @file{..}  entry linked to that
1257 directory.  When @code{find} is examining a directory, after it has
1258 statted 2 fewer subdirectories than the directory's link count, it
1259 knows that the rest of the entries in the directory are
1260 non-directories (@dfn{leaf} files in the directory tree).  If only the
1261 files' names need to be examined, there is no need to stat them; this
1262 gives a significant increase in search speed.
1263 @end deffn
1265 @deffn Option -ignore_readdir_race
1266 If a file disappears after its name has been read from a directory but
1267 before @code{find} gets around to examining the file with @code{stat},
1268 don't issue an error message.  If you don't specify this option, an
1269 error message will be issued.  This option can be useful in system
1270 scripts (cron scripts, for example) that examine areas of the
1271 filesystem that change frequently (mail queues, temporary directories,
1272 and so forth), because this scenario is common for those sorts of
1273 directories.  Completely silencing error messages from @code{find} is
1274 undesirable, so this option neatly solves the problem.  There is no
1275 way to search one part of the filesystem with this option on and part
1276 of it with this option off, though.  When this option is turned on and 
1277 find discovers that one of the start-point files specified on the
1278 command line does not exist, no error message will be issued.
1280 @end deffn
1282 @deffn Option -noignore_readdir_race
1283 This option reverses the effect of the @samp{-ignore_readdir_race}
1284 option.
1285 @end deffn
1288 @node Filesystems
1289 @section Filesystems
1291 A @dfn{filesystem} is a section of a disk, either on the local host or
1292 mounted from a remote host over a network.  Searching network
1293 filesystems can be slow, so it is common to make @code{find} avoid
1294 them.
1296 There are two ways to avoid searching certain filesystems.  One way is
1297 to tell @code{find} to only search one filesystem:
1299 @deffn Option -xdev
1300 @deffnx Option -mount
1301 Don't descend directories on other filesystems.  These options are
1302 synonyms.
1303 @end deffn
1305 The other way is to check the type of filesystem each file is on, and
1306 not descend directories that are on undesirable filesystem types:
1308 @deffn Test -fstype type
1309 True if the file is on a filesystem of type @var{type}.  The valid
1310 filesystem types vary among different versions of Unix; an incomplete
1311 list of filesystem types that are accepted on some version of Unix or
1312 another is:
1313 @example
1314 ext2 ext3 proc sysfs ufs 4.2 4.3 nfs tmp mfs S51K S52K
1315 @end example
1316 You can use @samp{-printf} with the @samp{%F} directive to see the
1317 types of your filesystems.  The @samp{%D} directive shows the device
1318 number.  @xref{Print File Information}.  @samp{-fstype} is usually
1319 used with @samp{-prune} to avoid searching remote filesystems
1320 (@pxref{Directories}).
1321 @end deffn
1323 @node Combining Primaries With Operators
1324 @section Combining Primaries With Operators
1326 Operators build a complex expression from tests and actions.
1327 The operators are, in order of decreasing precedence:
1329 @table @code
1330 @item @asis{( @var{expr} )}
1331 @findex ()
1332 Force precedence.  True if @var{expr} is true.
1334 @item @asis{! @var{expr}}
1335 @itemx @asis{-not @var{expr}}
1336 @findex !
1337 @findex -not
1338 True if @var{expr} is false.  In some shells, it is necessary to
1339 protect the @samp{!} from shell interpretation by quoting it.
1341 @item @asis{@var{expr1 expr2}}
1342 @itemx @asis{@var{expr1} -a @var{expr2}}
1343 @itemx @asis{@var{expr1} -and @var{expr2}}
1344 @findex -a
1345 @findex -and
1346 And; @var{expr2} is not evaluated if @var{expr1} is false.
1348 @item @asis{@var{expr1} -o @var{expr2}}
1349 @itemx @asis{@var{expr1} -or @var{expr2}}
1350 @findex -o
1351 @findex -or
1352 Or; @var{expr2} is not evaluated if @var{expr1} is true.
1354 @item @asis{@var{expr1} , @var{expr2}}
1355 @findex ,
1356 List; both @var{expr1} and @var{expr2} are always evaluated.  True if
1357 @var{expr2} is true.  The value of @var{expr1} is discarded.  This
1358 operator lets you do multiple independent operations on one traversal,
1359 without depending on whether other operations succeeded.  The two
1360 operations @var{expr1} and @var{expr2} are not always fully
1361 independent, since @var{expr1} might have side effects like touching
1362 or deleting files, or it might use @samp{-prune} which would also
1363 affect @var{expr2}.
1364 @end table
1366 @code{find} searches the directory tree rooted at each file name by
1367 evaluating the expression from left to right, according to the rules
1368 of precedence, until the outcome is known (the left hand side is false
1369 for @samp{-and}, true for @samp{-or}), at which point @code{find}
1370 moves on to the next file name.
1372 There are two other tests that can be useful in complex expressions:
1374 @deffn Test -true
1375 Always true.
1376 @end deffn
1378 @deffn Test -false
1379 Always false.
1380 @end deffn
1382 @node Actions, Databases, Finding Files, Top
1383 @chapter Actions
1385 There are several ways you can print information about the files that
1386 match the criteria you gave in the @code{find} expression.  You can
1387 print the information either to the standard output or to a file that
1388 you name.  You can also execute commands that have the file names as
1389 arguments.  You can use those commands as further filters to select
1390 files.
1392 @menu
1393 * Print File Name::
1394 * Print File Information::
1395 * Run Commands::
1396 * Delete Files::
1397 * Adding Tests::
1398 @end menu
1400 @node Print File Name
1401 @section Print File Name
1403 @deffn Action -print
1404 True; print the entire file name on the standard output, followed by a
1405 newline.  If there is the faintest possibility that one of the files
1406 for which you are searching might contain a newline, you should use
1407 @samp{-print0} instead.
1408 @end deffn
1410 @deffn Action -fprint file
1411 True; print the entire file name into file @var{file}, followed by a
1412 newline.  If @var{file} does not exist when @code{find} is run, it is
1413 created; if it does exist, it is truncated to 0 bytes.  The named
1414 output file is always created, even if no output is sent to it.  The
1415 file names @file{/dev/stdout} and @file{/dev/stderr} are handled
1416 specially; they refer to the standard output and standard error
1417 output, respectively.
1419 If there is the faintest possibility that one of the files for which
1420 you are searching might contain a newline, you should use
1421 @samp{-fprint0} instead.
1422 @end deffn
1424 @node Print File Information
1425 @section Print File Information
1427 @deffn Action -ls
1428 True; list the current file in @samp{ls -dils} format on the standard
1429 output.  The output looks like this:
1431 @smallexample
1432 204744   17 -rw-r--r--   1 djm      staff       17337 Nov  2  1992 ./lwall-quotes
1433 @end smallexample
1435 The fields are:
1437 @enumerate
1438 @item
1439 The inode number of the file.  @xref{Hard Links}, for how to find
1440 files based on their inode number.
1442 @item
1443 the number of blocks in the file.  The block counts are of 1K blocks,
1444 unless the environment variable @code{POSIXLY_CORRECT} is set, in
1445 which case 512-byte blocks are used.  @xref{Size}, for how to find
1446 files based on their size.
1448 @item
1449 The file's type and permissions.  The type is shown as a dash for a
1450 regular file; for other file types, a letter like for @samp{-type} is
1451 used (@pxref{Type}).  The permissions are read, write, and execute for
1452 the file's owner, its group, and other users, respectively; a dash
1453 means the permission is not granted.  @xref{File Permissions}, for
1454 more details about file permissions.  @xref{Permissions}, for how to
1455 find files based on their permissions.
1457 @item
1458 The number of hard links to the file.
1460 @item
1461 The user who owns the file.
1463 @item
1464 The file's group.
1466 @item
1467 The file's size in bytes.
1469 @item
1470 The date the file was last modified.
1472 @item
1473 The file's name.  @samp{-ls} quotes non-printable characters in the
1474 file names using C-like backslash escapes.  This may change soon, as
1475 the treatment of unprintable characters is harmonised for @samp{-ls},
1476 @samp{-fls}, @samp{-print}, @samp{-fprint}, @samp{-printf} and
1477 @samp{-fprintf}.
1478 @end enumerate
1479 @end deffn
1481 @deffn Action -fls file
1482 True; like @samp{-ls} but write to @var{file} like @samp{-fprint}
1483 (@pxref{Print File Name}).  The named output file is always created,
1484 even if no output is sent to it.
1485 @end deffn
1487 @deffn Action -printf format
1488 True; print @var{format} on the standard output, interpreting @samp{\}
1489 escapes and @samp{%} directives.  Field widths and precisions can be
1490 specified as with the @code{printf} C function.  Format flags (like
1491 @samp{#} for example) may not work as you expect because many of the
1492 fields, even numeric ones, are printed with %s.  Numeric flags which
1493 are affected in this way include G, U, b, D, k and n.  This difference
1494 in behaviour means though that the format flag @samp{-} will work; it
1495 forces left-alignment of the field.  Unlike @samp{-print},
1496 @samp{-printf} does not add a newline at the end of the string.  If
1497 you want a newline at the end of the string, add a @samp{\n}.
1498 @end deffn
1500 @deffn Action -fprintf file format
1501 True; like @samp{-printf} but write to @var{file} like @samp{-fprint}
1502 (@pxref{Print File Name}).  The output file is always created, even if
1503 no output is ever sent to it.
1504 @end deffn
1506 @menu
1507 * Escapes::
1508 * Format Directives::
1509 * Time Formats::
1510 @end menu
1512 @node Escapes
1513 @subsection Escapes
1515 The escapes that @samp{-printf} and @samp{-fprintf} recognize are:
1517 @table @code
1518 @item \a
1519 Alarm bell.
1520 @item \b
1521 Backspace.
1522 @item \c
1523 Stop printing from this format immediately and flush the output.
1524 @item \f
1525 Form feed.
1526 @item \n
1527 Newline.
1528 @item \r
1529 Carriage return.
1530 @item \t
1531 Horizontal tab.
1532 @item \v
1533 Vertical tab.
1534 @item \\
1535 A literal backslash (@samp{\}).
1536 @item \0
1537 ASCII NUL.
1538 @item \NNN
1539 The character whose ASCII code is NNN (octal).
1540 @end table
1542 A @samp{\} character followed by any other character is treated as an
1543 ordinary character, so they both are printed, and a warning message is
1544 printed to the standard error output (because it was probably a typo).
1546 @node Format Directives
1547 @subsection Format Directives
1549 @samp{-printf} and @samp{-fprintf} support the following format
1550 directives to print information about the file being processed.  The C
1551 @code{printf} function, field width and precision specifiers are
1552 supported, as applied to string (%s) types. That is, you can specify
1553 "minimum field width"."maximum field width" for each directive.
1554 Format flags (like @samp{#} for example) may not work as you expect
1555 because many of the fields, even numeric ones, are printed with %s.
1556 The format flag @samp{-} does work; it forces left-alignment of the
1557 field.
1559 @samp{%%} is a literal percent sign.  A @samp{%} character followed by
1560 an unrecognised character (i.e. not a known directive or printf field
1561 width and precision specifier), is discarded (but the unrecognised
1562 character is printed), and a warning message is printed to the
1563 standard error output (because it was probably a typo).
1565 @menu
1566 * Name Directives::
1567 * Ownership Directives::
1568 * Size Directives::
1569 * Location Directives::
1570 * Time Directives::
1571 * Formatting Flags::
1572 @end menu
1574 @node Name Directives
1575 @subsubsection Name Directives
1577 @table @code
1578 @item %p
1579 @c supports %-X.Yp
1580 File's name (not the absolute path name, but the name of the file as
1581 it was encountered by @code{find} - that is, as a relative path from
1582 one of the starting points).
1583 @item %f
1584 File's name with any leading directories removed (only the last
1585 element).
1586 @c supports %-X.Yf
1587 @item %h
1588 Leading directories of file's name (all but the last element and the
1589 slash before it).  If the file's name contains no slashes (for example
1590 because it was named on the command line and is in the current working
1591 directory), then ``%h'' expands to ``.''.  This prevents ``%h/%f''
1592 expanding to ``/foo'', which would be surprising and probably not
1593 desirable.
1594 @c supports %-X.Yh
1595 @item %P
1596 File's name with the name of the command line argument under which
1597 it was found removed from the beginning.
1598 @c supports %-X.YP
1599 @item %H
1600 Command line argument under which file was found.
1601 @c supports %-X.YH
1602 @end table
1604 @node Ownership Directives
1605 @subsubsection Ownership Directives
1607 @table @code
1608 @item %g
1609 @c supports %-X.Yg
1610 File's group name, or numeric group ID if the group has no name.
1611 @item %G
1612 @c supports %-X.Yg
1613 @c TODO: Needs to support # flag and 0 flag
1614 File's numeric group ID.
1615 @item %u
1616 @c supports %-X.Yu
1617 File's user name, or numeric user ID if the user has no name.
1618 @item %U
1619 @c supports %-X.Yu
1620 @c TODO: Needs to support # flag
1621 File's numeric user ID.
1622 @item %m
1623 @c full support, including # and 0.
1624 File's permissions (in octal).  If you always want to have a leading
1625 zero on the number, use the '#' format flag, for example '%#m'.  
1627 The permisison numbers used are the traditional Unix permission
1628 numbers, which will be as expected on most systems, but if your
1629 system's permission bit layout differs from the traditional Unix
1630 semantics, you will see a difference between the mode as printed by
1631 @samp{%m} and the mode as it appears in @code{struct stat}.
1633 @item %M
1634 File's permissions (in symbolic form, as for @code{ls}).  This
1635 directive is supported in findutils 4.2.5 and later.
1636 @end table
1638 @node Size Directives
1639 @subsubsection Size Directives
1641 @table @code
1642 @item %k
1643 The amount of disk space used for this file in 1K blocks. Since disk
1644 space is allocated in multiples of the filesystem block size this is
1645 usually greater than %s/1024, but it can also be smaller if the file
1646 is a sparse file (that is, it has ``holes'').
1647 @item %b
1648 The amount of disk space used for this file in 512-byte blocks. Since
1649 disk space is allocated in multiples of the filesystem block size this
1650 is usually greater than %s/1024, but it can also be smaller if the
1651 file is a sparse file (that is, it has ``holes'').
1652 @item %s
1653 File's size in bytes.
1654 @end table
1656 @node Location Directives
1657 @subsubsection Location Directives
1659 @table @code
1660 @item %d
1661 File's depth in the directory tree (depth below a file named on the
1662 command line, not depth below the root directory).  Files named on the
1663 command line have a depth of 0.  Subdirectories immediately below them
1664 have a depth of 1, and so on.
1665 @item %D
1666 The device number on which the file exists (the @code{st_dev} field of
1667 @code{struct stat}), in decimal.
1668 @item %F
1669 Type of the filesystem the file is on; this value can be used for
1670 @samp{-fstype} (@pxref{Directories}).
1671 @item %l
1672 Object of symbolic link (empty string if file is not a symbolic link).
1673 @item %i
1674 File's inode number (in decimal).
1675 @item %n
1676 Number of hard links to file.
1677 @item %y
1678 Type of the file as used with @samp{-type}.  If the file is a symbolic
1679 link, @samp{l} will be printed.
1680 @item %Y
1681 Type of the file as used with @samp{-type}.  If the file is a symbolic
1682 link, it is dereferenced.  If the file is a broken symbolic link,
1683 @samp{N} is printed.
1685 @end table
1687 @node Time Directives
1688 @subsubsection Time Directives
1690 Some of these directives use the C @code{ctime} function.  Its output
1691 depends on the current locale, but it typically looks like
1693 @example
1694 Wed Nov  2 00:42:36 1994
1695 @end example
1697 @table @code
1698 @item %a
1699 File's last access time in the format returned by the C @code{ctime}
1700 function.
1701 @item %A@var{k}
1702 File's last access time in the format specified by @var{k}
1703 (@pxref{Time Formats}).
1704 @item %c
1705 File's last status change time in the format returned by the C
1706 @code{ctime} function.
1707 @item %C@var{k}
1708 File's last status change time in the format specified by @var{k}
1709 (@pxref{Time Formats}).
1710 @item %t
1711 File's last modification time in the format returned by the C
1712 @code{ctime} function.
1713 @item %T@var{k}
1714 File's last modification time in the format specified by @var{k}
1715 (@pxref{Time Formats}).
1716 @end table
1718 @node Time Formats
1719 @subsection Time Formats
1721 Below are the formats for the directives @samp{%A}, @samp{%C}, and
1722 @samp{%T}, which print the file's timestamps.  Some of these formats
1723 might not be available on all systems, due to differences in the C
1724 @code{strftime} function between systems.
1726 @menu
1727 * Time Components::
1728 * Date Components::
1729 * Combined Time Formats::
1730 @end menu
1732 @node Time Components
1733 @subsubsection Time Components
1735 The following format directives print single components of the time.
1737 @table @code
1738 @item H
1739 hour (00..23)
1740 @item I
1741 hour (01..12)
1742 @item k
1743 hour ( 0..23)
1744 @item l
1745 hour ( 1..12)
1746 @item p
1747 locale's AM or PM
1748 @item Z
1749 time zone (e.g., EDT), or nothing if no time zone is determinable
1750 @item M
1751 minute (00..59)
1752 @item S
1753 second (00..61)
1754 @item @@
1755 seconds since Jan. 1, 1970, 00:00 GMT.
1756 @end table
1758 @node Date Components
1759 @subsubsection Date Components
1761 The following format directives print single components of the date.
1763 @table @code
1764 @item a
1765 locale's abbreviated weekday name (Sun..Sat)
1766 @item A
1767 locale's full weekday name, variable length (Sunday..Saturday)
1768 @item b
1769 @itemx h
1770 locale's abbreviated month name (Jan..Dec)
1771 @item B
1772 locale's full month name, variable length (January..December)
1773 @item m
1774 month (01..12)
1775 @item d
1776 day of month (01..31)
1777 @item w
1778 day of week (0..6)
1779 @item j
1780 day of year (001..366)
1781 @item U
1782 week number of year with Sunday as first day of week (00..53)
1783 @item W
1784 week number of year with Monday as first day of week (00..53)
1785 @item Y
1786 year (1970@dots{})
1787 @item y
1788 last two digits of year (00..99)
1789 @end table
1791 @node Combined Time Formats
1792 @subsubsection Combined Time Formats
1794 The following format directives print combinations of time and date
1795 components.
1797 @table @code
1798 @item r
1799 time, 12-hour (hh:mm:ss [AP]M)
1800 @item T
1801 time, 24-hour (hh:mm:ss)
1802 @item X
1803 locale's time representation (H:M:S)
1804 @item c
1805 locale's date and time (Sat Nov 04 12:02:33 EST 1989)
1806 @item D
1807 date (mm/dd/yy)
1808 @item x
1809 locale's date representation (mm/dd/yy)
1810 @item +
1811 Date and time, separated by '+', for example `2004-04-28+22:22:05'.
1812 The time is given in the current timezone (which may be affected by
1813 setting the TZ environment variable).  This is a GNU extension.
1814 @end table
1816 @node Formatting Flags
1817 @subsubsection Formatting Flags
1819 The @samp{%m} and @samp{%d} directives support the @samp{#}, @samp{0}
1820 and @samp{+} flags, but the other directives do not, even if they
1821 print numbers.  Numeric directives that do not support these flags
1822 include
1824 @samp{G},
1825 @samp{U},
1826 @samp{b},
1827 @samp{D},
1828 @samp{k} and
1829 @samp{n}.
1831 All fields support the format flag @samp{-}, which makes fields
1832 left-aligned.  That is, if the field width is greater than the actual
1833 contents of the field, the requisite number of spaces are printed
1834 after the field content instead of before it.
1836 @node Run Commands
1837 @section Run Commands
1839 You can use the list of file names created by @code{find} or
1840 @code{locate} as arguments to other commands.  In this way you can
1841 perform arbitrary actions on the files.
1843 @menu
1844 * Single File::
1845 * Multiple Files::
1846 * Querying::
1847 @end menu
1849 @node Single File
1850 @subsection Single File
1852 Here is how to run a command on one file at a time.
1854 @deffn Action -execdir command ;
1855 Execute @var{command}; true if zero status is returned.  @code{find}
1856 takes all arguments after @samp{-exec} to be part of the command until
1857 an argument consisting of @samp{;} is reached.  It replaces the string
1858 @samp{@{@}} by the current file name being processed everywhere it
1859 occurs in the command.  Both of these constructions need to be escaped
1860 (with a @samp{\}) or quoted to protect them from expansion by the
1861 shell.  The command is executed in the directory in which @code{find}
1862 was run.
1864 For example, to compare each C header file in or below the current
1865 directory with the file @file{/tmp/master}:
1867 @example
1868 find . -name '*.h' -execdir diff -u '@{@}' /tmp/master ';'
1869 @end example
1870 @end deffn
1872 If you use`@samp{-execdir}, you must ensure that the current directory
1873 is not on @var{$PATH}, because otherwise an attacker could make
1874 @samp{find} run commands of their choice simply by leaving a
1875 suitably-named file in the right directory.  GNU find will refuse to
1876 run if you use @samp{-execdir} and the current directory is in
1877 @var{$PATH}.
1879 Another similar option, @samp{-exec} is supported, but is less secure.
1880 @xref{Security Considerations}, for a discussion of the security
1881 problems surrounding @samp{-exec}.
1884 @deffn Action -exec command ;
1885 This insecure variant of the @samp{-execdir} action is specified by
1886 POSIX.  The main difference is that the command is executed in the
1887 directory from which @code{find} was invoked, meaning that @samp{@{@}}
1888 is expanded to a relative path starting with the name of one of the
1889 starting directories, rather than just the basename of the matched
1890 file.
1892 While some implementations of @code{find} replace the @samp{@{@}} only
1893 whwre it appears on its own in an argument, GNU @code{find} replaces
1894 @samp{@{@}} wherever it appears.
1895 @end deffn
1898 @node Multiple Files
1899 @subsection Multiple Files
1901 Sometimes you need to process files one of the time.  But usually this
1902 is not necessary, and, it is faster to run a command on as many files
1903 as possible at a time, rather than once per file.  Doing this saves on
1904 the time it takes to start up the command each time.
1906 The @samp{-execdir} and @samp{-exec} actions have variants that build
1907 command lines containing as many matched files as possible.
1909 @deffn Action -execdir command @{@} +
1910 This works as for @samp{-execdir command ;}, except that the
1911 @samp{@{@}} at the end of the command is expanded to a list of names
1912 of matching files.  This expansion is done in such a way as to avoid
1913 exceeding the maximum command line length available on the system.
1914 Only one @samp{@{@}} is allowed within the command, and it must appear
1915 at the end, immediately before the @samp{+}.  A @samp{+} appearing in
1916 any position other than immediately after @samp{@{@}} is not
1917 considered to be special (that is, it does not terminate the command).
1918 @end deffn
1921 @deffn Action -exec command @{@} +
1922 This insecure variant of the @samp{-execdir} action is specified by
1923 POSIX.  The main difference is that the command is executed in the
1924 directory from which @code{find} was invoked, meaning that @samp{@{@}}
1925 is expanded to a relative path starting with the name of one of the
1926 starting directories, rather than just the basename of the matched
1927 file.
1928 @end deffn
1930 Before @code{find} exits, any partially-built command lines are
1931 executed.  This happens even if the exit was caused by the
1932 @samp{-quit} action.  However, some types of error (for example not
1933 being able to invoke @code{stat()} on the current directory) can cause
1934 an immediate fatal exit.  In this situation, any partially-built
1935 command lines will not be invoked (this prevents possible infinite
1936 loops).
1938 Another, but less secure, way to run a command on more than one file
1939 at once, is to use the @code{xargs} command, which is invoked like
1940 this:
1942 @example
1943 xargs @r{[}@var{option}@dots{}@r{]} @r{[}@var{command} @r{[}@var{initial-arguments}@r{]}@r{]}
1944 @end example
1946 @code{xargs} normally reads arguments from the standard input.  These
1947 arguments are delimited by blanks (which can be protected with double
1948 or single quotes or a backslash) or newlines.  It executes the
1949 @var{command} (default is @file{/bin/echo}) one or more times with any
1950 @var{initial-arguments} followed by arguments read from standard
1951 input.  Blank lines on the standard input are ignored.
1953 Instead of blank-delimited names, it is safer to use @samp{find
1954 -print0} or @samp{find -fprint0} and process the output by giving the
1955 @samp{-0} or @samp{--null} option to GNU @code{xargs}, GNU @code{tar},
1956 GNU @code{cpio}, or @code{perl}.  The @code{locate} command also has a
1957 @samp{-0} or @samp{--null} option which does the same thing.
1959 You can use shell command substitution (backquotes) to process a list
1960 of arguments, like this:
1962 @example
1963 grep -l sprintf `find $HOME -name '*.c' -print`
1964 @end example
1966 However, that method produces an error if the length of the @samp{.c}
1967 file names exceeds the operating system's command line length limit.
1968 @code{xargs} avoids that problem by running the command as many times
1969 as necessary without exceeding the limit:
1971 @example
1972 find $HOME -name '*.c' -print | xargs grep -l sprintf
1973 @end example
1975 However, if the command needs to have its standard input be a terminal
1976 (@code{less}, for example), you have to use the shell command
1977 substitution method or use the @samp{--arg-file} option of
1978 @code{xargs}.
1980 The @code{xargs} command will process all its input, building command
1981 lines and executing them, unless one of the commands exits with a
1982 status of 255 (this will cause xargs to issue an error message and
1983 stop) or it reads a line contains the end of file string specified
1984 with the @samp{--eof} option.
1986 @menu
1987 * Unsafe File Name Handling::
1988 * Safe File Name Handling::
1989 * Unusual Characters in File Names::
1990 * Limiting Command Size::
1991 * Interspersing File Names::
1992 @end menu
1994 @node Unsafe File Name Handling
1995 @subsubsection Unsafe File Name Handling
1997 Because file names can contain quotes, backslashes, blank characters,
1998 and even newlines, it is not safe to process them using @code{xargs}
1999 in its default mode of operation.  But since most files' names do not
2000 contain blanks, this problem occurs only infrequently.  If you are
2001 only searching through files that you know have safe names, then you
2002 need not be concerned about it.
2004 @c This example is adapted from:
2005 @c From: pfalstad@stone.Princeton.EDU (Paul John Falstad)
2006 @c Newsgroups: comp.unix.shell
2007 @c Subject: Re: Beware xargs security holes
2008 @c Date: 16 Oct 90 19:12:06 GMT
2010 In many applications, if @code{xargs} botches processing a file
2011 because its name contains special characters, some data might be lost.
2012 The importance of this problem depends on the importance of the data
2013 and whether anyone notices the loss soon enough to correct it.
2014 However, here is an extreme example of the problems that using
2015 blank-delimited names can cause.  If the following command is run
2016 daily from @code{cron}, then any user can remove any file on the
2017 system:
2019 @example
2020 find / -name '#*' -atime +7 -print | xargs rm
2021 @end example
2023 For example, you could do something like this:
2025 @example
2026 eg$ echo > '#
2027 vmunix'
2028 @end example
2030 @noindent
2031 and then @code{cron} would delete @file{/vmunix}, if it ran
2032 @code{xargs} with @file{/} as its current directory.
2034 To delete other files, for example @file{/u/joeuser/.plan}, you could
2035 do this:
2037 @example
2038 eg$ mkdir '#
2040 eg$ cd '#
2042 eg$ mkdir u u/joeuser u/joeuser/.plan'
2044 eg$ echo > u/joeuser/.plan'
2045 /#foo'
2046 eg$ cd ..
2047 eg$ find . -name '#*' -print | xargs echo
2048 ./# ./# /u/joeuser/.plan /#foo
2049 @end example
2051 @node Safe File Name Handling
2052 @subsubsection Safe File Name Handling
2054 Here is how to make @code{find} output file names so that they can be
2055 used by other programs without being mangled or misinterpreted.  You
2056 can process file names generated this way by giving the @samp{-0} or
2057 @samp{--null} option to GNU @code{xargs}, GNU @code{tar}, GNU
2058 @code{cpio}, or @code{perl}.
2060 @deffn Action -print0
2061 True; print the entire file name on the standard output, followed by a
2062 null character.
2063 @end deffn
2065 @deffn Action -fprint0 file
2066 True; like @samp{-print0} but write to @var{file} like @samp{-fprint}
2067 (@pxref{Print File Name}).  The output file is always created.
2068 @end deffn
2070 As of findutils version 4.2.4, the @code{locate} program also has a
2071 @samp{--null} option which does the same thing.  For similarity with
2072 @code{xargs}, the short form of the option @samp{-0} can also be used.
2074 If you want to be able to handle file names safely but need to run
2075 commands which want to be connected to a terminal on their input, you
2076 can use the @samp{--arg-file} option to @code{xargs} like this:
2078 @example
2079 find / -name xyzzy -print0 > list
2080 xargs --null --arg-file=list munge
2081 @end example
2083 The example above runs the @code{munge} program on all the files named
2084 @file{xyzzy} that we can find, but @code{munge}'s input will still be
2085 the terminal (or whatever the shell was using as standard input).  If
2086 your shell has the ``process substitution'' feature @samp{<(...)}, you
2087 can do this in just one step:
2089 @example
2090 xargs --null --arg-file=<(find / -name xyzzy -print0) munge
2091 @end example
2093 @node Unusual Characters in File Names
2094 @subsubsection Unusual Characters in File Names
2095 As discussed above, you often need to be careful about how the names
2096 of files are handled by @code{find} and other programs.  If the output
2097 of @code{find} is not going to another program but instead is being
2098 shown on a terminal, this can still be a problem.  For example, some
2099 character sequences can reprogram the function keys on some terminals.
2100 @xref{Security Considerations}, for a discussion of other security
2101 problems relating to @code{find}.
2103 Unusual characters are handled differently by various
2104 actions, as described below.
2106 @table @samp
2107 @item -print0
2108 @itemx -fprint0
2109 Always print the exact file name, unchanged, even if the output is
2110 going to a terminal.
2111 @item -ok
2112 @itemx -okdir
2113 Always print the exact file name, unchanged.  This will probably
2114 change in a future release.
2115 @item -ls
2116 @itemx -fls
2117 Unusual characters are always escaped.  White space, backslash, and
2118 double quote characters are printed using C-style escaping (for
2119 example @samp{\f}, @samp{\"}).  Other unusual characters are printed
2120 using an octal escape.  Other printable characters (for @samp{-ls} and
2121 @samp{-fls} these are the characters between octal 041 and 0176) are
2122 printed as-is.
2123 @item -printf
2124 @itemx -fprintf
2125 If the output is not going to a terminal, it is printed as-is.
2126 Otherwise, the result depends on which directive is in use:
2128 @table @asis
2129 @item %D, %F, %H, %Y, %y
2130 These expand to values which are not under control of files' owners,
2131 and so are printed as-is.
2132 @item  %a, %b, %c, %d, %g, %G, %i, %k, %m, %M, %n, %s, %t, %u, %U
2133 These have values which are under the control of files' owners but
2134 which cannot be used to send arbitrary data to the terminal, and so
2135 these are printed as-is.
2136 @item %f, %h, %l, %p, %P
2137 The output of these directives is quoted if the output is going to a
2138 terminal.
2140 This quoting is performed in the same way as for GNU @code{ls}.  This
2141 is not the same quoting mechanism as the one used for @samp{-ls} and
2142 @samp{fls}.  If you are able to decide what format to use for the
2143 output of @code{find} then it is normally better to use @samp{\0} as a
2144 terminator than to use newline, as file names can contain white space
2145 and newline characters.
2146 @end table
2147 @item -print
2148 @itemx -fprint
2149 Quoting is handled in the same way as for the @samp{%p} directive of
2150 @samp{-printf} and @samp{-fprintf}.  If you are using @code{find} in a
2151 script or in a situation where the matched files might have arbitrary
2152 names, you should consider using @samp{-print0} instead of
2153 @samp{-print}.
2154 @end table
2157 The @code{locate} program quotes and escapes unusual characters in
2158 file names in the same way as @code{find}'s @samp{-print} action.
2160 The behaviours described above may change soon, as the treatment of
2161 unprintable characters is harmonised for @samp{-ls}, @samp{-fls},
2162 @samp{-print}, @samp{-fprint}, @samp{-printf} and @samp{-fprintf}.
2164 @node Limiting Command Size
2165 @subsubsection Limiting Command Size
2167 @code{xargs} gives you control over how many arguments it passes to
2168 the command each time it executes it.  By default, it uses up to
2169 @code{ARG_MAX} - 2k, or 128k, whichever is smaller, characters per
2170 command.  It uses as many lines and arguments as fit within that
2171 limit.  The following options modify those values.
2173 @table @code
2174 @item --no-run-if-empty
2175 @itemx -r
2176 If the standard input does not contain any nonblanks, do not run the
2177 command.  By default, the command is run once even if there is no
2178 input.  This option is a GNU extension.
2180 @item --max-lines@r{[}=@var{max-lines}@r{]}
2181 @itemx -L @var{max-lines}
2182 @itemx -l@r{[}@var{max-lines}@r{]}
2183 Use at most @var{max-lines} nonblank input lines per command line;
2184 @var{max-lines} defaults to 1 if omitted; omitting the argument is not
2185 allowed in the case of the @samp{-L} option.  Trailing blanks cause an
2186 input line to be logically continued on the next input line, for the
2187 purpose of counting the lines.  Implies @samp{-x}.  The preferred name
2188 for this option is @samp{-L} as this is specified by POSIX.  
2190 @item --max-args=@var{max-args}
2191 @itemx -n @var{max-args}
2192 Use at most @var{max-args} arguments per command line.  Fewer than
2193 @var{max-args} arguments will be used if the size (see the @samp{-s}
2194 option) is exceeded, unless the @samp{-x} option is given, in which
2195 case @code{xargs} will exit.
2197 @item --max-chars=@var{max-chars}
2198 @itemx -s @var{max-chars}
2199 Use at most @var{max-chars} characters per command line, including the
2200 command initial arguments and the terminating nulls at the ends of the
2201 argument strings.  If you specify a value for this option which is too
2202 large or small, a warning message is printed and the appropriate upper
2203 or lower limit is used instead.  You can use @samp{--show-limits}
2204 option to understand the command-line limits applying to @code{xargs}
2205 and how this is affected by any other options.
2207 @item --max-procs=@var{max-procs}
2208 @itemx -P @var{max-procs}
2209 Run up to @var{max-procs} processes at a time; the default is 1.  If
2210 @var{max-procs} is 0, @code{xargs} will run as many processes as
2211 possible at a time.  Use the @samp{-n}, @samp{-s}, or @samp{-L} option
2212 with @samp{-P}; otherwise chances are that the command will be run
2213 only once.
2214 @end table
2216 @node Interspersing File Names
2217 @subsubsection Interspersing File Names
2219 @code{xargs} can insert the name of the file it is processing between
2220 arguments you give for the command.  Unless you also give options to
2221 limit the command size (@pxref{Limiting Command Size}), this mode of
2222 operation is equivalent to @samp{find -exec} (@pxref{Single File}).
2224 @table @code
2225 @item --replace@r{[}=@var{replace-str}@r{]}
2226 @itemx -I @var{replace-str}
2227 @itemx -i @var{replace-str}
2228 Replace occurrences of @var{replace-str} in the initial arguments with
2229 names read from the input.  Also, unquoted blanks do not terminate
2230 arguments; instead, the input is split at newlines only.  For the
2231 @samp{-i} option, if @var{replace-str} is omitted for @samp{--replace}
2232 or @samp{-i}, it defaults to @samp{@{@}} (like for @samp{find -exec}).
2233 Implies @samp{-x} and @samp{-l 1}.  @samp{-i} is deprecated in favour
2234 of @samp{-I}. As an example, to sort each file in the @file{bills}
2235 directory, leaving the output in that file name with @file{.sorted}
2236 appended, you could do:
2238 @example
2239 find bills -type f | xargs -I XX sort -o XX.sorted XX
2240 @end example
2242 @noindent
2243 The equivalent command using @samp{find -execdir} is:
2245 @example
2246 find bills -type f -execdir sort -o '@{@}.sorted' '@{@}' ';'
2247 @end example
2248 @end table
2251 When you use the @samp{-I} option, each line read from the input is
2252 buffered internally.  This means that there is an upper limit on the
2253 length of input line that xargs will accept when used with the
2254 @samp{-I} option.  To work around this limitation, you can use the
2255 @samp{-s} option to increase the amount of buffer space that xargs
2256 uses, and you can also use an extra invocation of xargs to ensure that
2257 very long lines do not occur.  For example:
2259 @example
2260 somecommand | xargs -s 50000 echo | xargs -I '@{@}' -s 100000 rm '@{@}'
2261 @end example
2263 Here, the first invocation of @code{xargs} has no input line length
2264 limit because it doesn't use the @samp{-I} option. The second
2265 invocation of @code{xargs} does have such a limit, but we have ensured
2266 that the it never encounters a line which is longer than it can
2267 handle.  
2269 This is not an ideal solution.  Instead, the @samp{-I} option should
2270 not impose a line length limit (apart from any limit imposed by the
2271 operating system) and so one might consider this limitation to be a
2272 bug.  A better solution would be to allow @code{xargs -I} to
2273 automatically move to a larger value for the @samp{-s} option when
2274 this is needed.
2276 This sort of problem doesn't occur with the output of @code{find}
2277 because it emits just one filename per line.
2279 @node Querying
2280 @subsection Querying
2282 To ask the user whether to execute a command on a single file, you can
2283 use the @code{find} primary @samp{-okdir} instead of @samp{-execdir},
2284 and the @code{find} primary @samp{-ok} instead of @samp{-exec}:
2286 @deffn Action -okdir command ;
2287 Like @samp{-execdir} (@pxref{Single File}), but ask the user first (on
2288 the standard input); if the response does not start with @samp{y} or
2289 @samp{Y}, do not run the command, and return false.  If the command is
2290 run, its standard input is redirected from @file{/dev/null}.
2291 @end deffn
2293 @deffn Action -ok command ;
2294 This insecure variant of the @samp{-okdir} action is specified by
2295 POSIX.  The main difference is that the command is executed in the
2296 directory from which @code{find} was invoked, meaning that @samp{@{@}}
2297 is expanded to a relative path starting with the name of one of the
2298 starting directories, rather than just the basename of the matched
2299 file.  If the command is run, its standard input is redirected from
2300 @file{/dev/null}.
2301 @end deffn
2303 When processing multiple files with a single command, to query the
2304 user you give @code{xargs} the following option.  When using this
2305 option, you might find it useful to control the number of files
2306 processed per invocation of the command (@pxref{Limiting Command
2307 Size}).
2309 @table @code
2310 @item --interactive
2311 @itemx -p
2312 Prompt the user about whether to run each command line and read a line
2313 from the terminal.  Only run the command line if the response starts
2314 with @samp{y} or @samp{Y}.  Implies @samp{-t}.
2315 @end table
2317 @node Delete Files
2318 @section Delete Files
2320 @deffn Action -delete
2321 Delete files or directories; true if removal succeeded.  If the
2322 removal failed, an error message is issued.
2324 The use of the @samp{-delete} action on the command line automatically
2325 turns on the @samp{-depth} option (@pxref{find Expressions}).
2326 @end deffn
2328 @node Adding Tests
2329 @section Adding Tests
2331 You can test for file attributes that none of the @code{find} builtin
2332 tests check.  To do this, use @code{xargs} to run a program that
2333 filters a list of files printed by @code{find}.  If possible, use
2334 @code{find} builtin tests to pare down the list, so the program run by
2335 @code{xargs} has less work to do.  The tests builtin to @code{find}
2336 will likely run faster than tests that other programs perform.
2338 For reasons of efficiency it is often useful to limit the number of
2339 times an external program has to be run.  For this reason, it is often
2340 a good idea to implement ``extended'' tests by using @code{xargs}.
2342 For example, here is a way to print the names of all of the unstripped
2343 binaries in the @file{/usr/local} directory tree.  Builtin tests avoid
2344 running @code{file} on files that are not regular files or are not
2345 executable.
2347 @example
2348 find /usr/local -type f -perm /a=x | xargs file |
2349   grep 'not stripped' | cut -d: -f1
2350 @end example
2352 @noindent
2353 The @code{cut} program removes everything after the file name from the
2354 output of @code{file}.
2356 However, using @code{xargs} can present important security problems
2357 (@pxref{Security Considerations}).  These can be avoided by using
2358 @samp{-execdir}.  The @samp{-execdir} action is also a useful way of
2359 putting your own test in the middle of a set of other tests or actions
2360 for @code{find} (for example, you might want to use @samp{-prune}).
2362 @c Idea from Martin Weitzel.
2363 To place a special test somewhere in the middle of a @code{find}
2364 expression, you can use @samp{-execdir} (or, less securely,
2365 @samp{-exec}) to run a program that performs the test.  Because
2366 @samp{-execdir} evaluates to the exit status of the executed program,
2367 you can use a program (which can be a shell script) that tests for a
2368 special attribute and make it exit with a true (zero) or false
2369 (non-zero) status.  It is a good idea to place such a special test
2370 @emph{after} the builtin tests, because it starts a new process which
2371 could be avoided if a builtin test evaluates to false.
2373 Here is a shell script called @code{unstripped} that checks whether
2374 its argument is an unstripped binary file:
2376 @example
2377 #! /bin/sh
2378 file "$1" | grep -q "not stripped"
2379 @end example
2382 This script relies on the shell exiting with the status of
2383 the last command in the pipeline, in this case @code{grep}.  The
2384 @code{grep} command exits with a true status if it found any matches,
2385 false if not.  Here is an example of using the script (assuming it is
2386 in your search path).  It lists the stripped executables (and shell
2387 scripts) in the file @file{sbins} and the unstripped ones in
2388 @file{ubins}.
2390 @example
2391 find /usr/local -type f -perm /a=x \
2392   \( -execdir unstripped '@{@}' \; -fprint ubins -o -fprint sbins \)
2393 @end example
2396 @node Databases, File Permissions, Actions, Top
2397 @chapter File Name Databases
2399 The file name databases used by @code{locate} contain lists of files
2400 that were in particular directory trees when the databases were last
2401 updated.  The file name of the default database is determined when
2402 @code{locate} and @code{updatedb} are configured and installed.  The
2403 frequency with which the databases are updated and the directories for
2404 which they contain entries depend on how often @code{updatedb} is run,
2405 and with which arguments.
2407 You can obtain some statistics about the databases by using
2408 @samp{locate --statistics}.
2410 @menu
2411 * Database Locations::
2412 * Database Formats::
2413 * Newline Handling::
2414 @end menu
2417 @node Database Locations
2418 @section Database Locations
2420 There can be multiple file name databases.  Users can select which
2421 databases @code{locate} searches using the @code{LOCATE_PATH}
2422 environment variable or a command line option.  The system
2423 administrator can choose the file name of the default database, the
2424 frequency with which the databases are updated, and the directories
2425 for which they contain entries.  File name databases are updated by
2426 running the @code{updatedb} program, typically nightly.
2428 In networked environments, it often makes sense to build a database at
2429 the root of each filesystem, containing the entries for that
2430 filesystem.  @code{updatedb} is then run for each filesystem on the
2431 fileserver where that filesystem is on a local disk, to prevent
2432 thrashing the network.
2434 @xref{Invoking updatedb},
2435 for the description of the options to @code{updatedb}, which specify
2436 which directories would each database contain entries for.
2439 @node Database Formats
2440 @section Database Formats
2442 The file name databases contain lists of files that were in particular
2443 directory trees when the databases were last updated.  The file name
2444 database format changed starting with GNU @code{locate} version 4.0 to
2445 allow machines with different byte orderings to share the databases.
2446 The new GNU @code{locate} can read both the old and new database
2447 formats.  However, old versions of @code{locate} and @code{find}
2448 produce incorrect results if given a new-format database.
2450 Support for the old database format will eventually be discontinued,
2451 first in @code{updatedb} and later in @code{xargs}.
2453 If you run @samp{locate --statistics}, the resulting summary indicates
2454 the type of each @code{locate} database.
2457 @menu
2458 * New Database Format::
2459 * Sample Database::
2460 * Old Database Format::
2461 @end menu
2463 @node New Database Format
2464 @subsection New Database Format
2466 @code{updatedb} runs a program called @code{frcode} to
2467 @dfn{front-compress} the list of file names, which reduces the
2468 database size by a factor of 4 to 5.  Front-compression (also known as
2469 incremental encoding) works as follows.
2471 The database entries are a sorted list (case-insensitively, for users'
2472 convenience).  Since the list is sorted, each entry is likely to share
2473 a prefix (initial string) with the previous entry.  Each database
2474 entry begins with an offset-differential count byte, which is the
2475 additional number of characters of prefix of the preceding entry to
2476 use beyond the number that the preceding entry is using of its
2477 predecessor.  (The counts can be negative.)  Following the count is a
2478 null-terminated ASCII remainder---the part of the name that follows
2479 the shared prefix.
2481 If the offset-differential count is larger than can be stored in a
2482 byte (+/-127), the byte has the value 0x80 and the count follows in a
2483 2-byte word, with the high byte first (network byte order).
2485 Every database begins with a dummy entry for a file called
2486 @file{LOCATE02}, which @code{locate} checks for to ensure that the
2487 database file has the correct format; it ignores the entry in doing
2488 the search.
2490 Databases cannot be concatenated together, even if the first (dummy)
2491 entry is trimmed from all but the first database.  This is because the
2492 offset-differential count in the first entry of the second and
2493 following databases will be wrong.
2495 In the output of @samp{locate --statistics}, the new database format
2496 is referred to as @samp{LOCATE02}.
2498 @node Sample Database
2499 @subsection Sample Database
2501 Sample input to @code{frcode}:
2502 @c with nulls changed to newlines:
2504 @example
2505 /usr/src
2506 /usr/src/cmd/aardvark.c
2507 /usr/src/cmd/armadillo.c
2508 /usr/tmp/zoo
2509 @end example
2511 Length of the longest prefix of the preceding entry to share:
2513 @example
2514 0 /usr/src
2515 8 /cmd/aardvark.c
2516 14 rmadillo.c
2517 5 tmp/zoo
2518 @end example
2520 Output from @code{frcode}, with trailing nulls changed to newlines
2521 and count bytes made printable:
2523 @example
2524 0 LOCATE02
2525 0 /usr/src
2526 8 /cmd/aardvark.c
2527 6 rmadillo.c
2528 -9 tmp/zoo
2529 @end example
2531 (6 = 14 - 8, and -9 = 5 - 14)
2533 @node Old Database Format
2534 @subsection Old Database Format
2536 The old database format is used by Unix @code{locate} and @code{find}
2537 programs and earlier releases of the GNU ones.  @code{updatedb}
2538 produces this format if given the @samp{--old-format} option.
2540 @code{updatedb} runs programs called @code{bigram} and @code{code} to
2541 produce old-format databases.  The old format differs from the new one
2542 in the following ways.  Instead of each entry starting with an
2543 offset-differential count byte and ending with a null, byte values
2544 from 0 through 28 indicate offset-differential counts from -14 through
2545 14.  The byte value indicating that a long offset-differential count
2546 follows is 0x1e (30), not 0x80.  The long counts are stored in host
2547 byte order, which is not necessarily network byte order, and host
2548 integer word size, which is usually 4 bytes.  They also represent a
2549 count 14 less than their value.  The database lines have no
2550 termination byte; the start of the next line is indicated by its first
2551 byte having a value <= 30.
2553 In addition, instead of starting with a dummy entry, the old database
2554 format starts with a 256 byte table containing the 128 most common
2555 bigrams in the file list.  A bigram is a pair of adjacent bytes.
2556 Bytes in the database that have the high bit set are indexes (with the
2557 high bit cleared) into the bigram table.  The bigram and
2558 offset-differential count coding makes these databases 20-25% smaller
2559 than the new format, but makes them not 8-bit clean.  Any byte in a
2560 file name that is in the ranges used for the special codes is replaced
2561 in the database by a question mark, which not coincidentally is the
2562 shell wildcard to match a single character.
2564 The old format therefore cannot faithfully store entries with
2565 non-ASCII characters. It therefore should not be used in
2566 internationalized environments.
2568 The output of @samp{locate --statistics} will give an incorrect count
2569 of the number of file names containing newlines or high-bit characters
2570 for old-format databases.
2572 @node Newline Handling
2573 @section Newline Handling
2575 Within the database, file names are terminated with a null character.
2576 This is the case for both the old and the new format.
2578 When the new database format is being used, the compression technique
2579 used to generate the database though relies on the ability to sort the
2580 list of files before they are presented to @code{frcode}.
2582 If the system's sort command allows its input list of files to be
2583 separated with null characters via the @samp{-z} option, this option
2584 is used and therefore @code{updatedb} and @code{locate} will both
2585 correctly handle file names containing newlines.  If the @code{sort}
2586 command lacks support for this, the list of files is delimited with
2587 the newline character, meaning that parts of file names containing
2588 newlines will be incorrectly sorted.  This can result in both
2589 incorrect matches and incorrect failures to match.
2591 On the other hand, if you are using the old database format, file
2592 names with embedded newlines are not correctly handled.  There is no
2593 technical limitation which enforces this, it's just that the
2594 @code{bigram} program has not been updated to support lists of file
2595 names separated by nulls.
2597 So, if you are using the new database format (this is the default) and
2598 your system uses GNU @code{sort}, newlines will be correctly handled
2599 at all times.  Otherwise, newlines may not be correctly handled.
2601 @node File Permissions, Reference, Databases, Top
2602 @chapter File Permissions
2604 @include perm.texi
2606 @node Reference, Common Tasks, File Permissions, Top
2607 @chapter Reference
2609 Below are summaries of the command line syntax for the programs
2610 discussed in this manual.
2612 @menu
2613 * Invoking find::
2614 * Invoking locate::
2615 * Invoking updatedb::
2616 * Invoking xargs::
2617 * Regular Expressions::
2618 * Environment Variables::
2619 @end menu
2621 @node Invoking find, Invoking locate, , Reference
2622 @section Invoking @code{find}
2624 @example
2625 find @r{[-H] [-L] [-P]} @r{[}@var{file}@dots{}@r{]} @r{[}@var{expression}@r{]}
2626 @end example
2628 @code{find} searches the directory tree rooted at each file name
2629 @var{file} by evaluating the @var{expression} on each file it finds in
2630 the tree.
2632 The options @samp{-H}, @samp{-L} or @samp{-P} may be specified at the
2633 start of the command line (if none of these is specified, @samp{-P} is
2634 assumed).  If you specify more than one of these options, the last one
2635 specified takes effect (but note that the @samp{-follow} option is
2636 equivalent to @samp{-L}).  The arguments after these are a list of
2637 files or directories that should be searched.
2639 This list of files to search is followed by a list of expressions
2640 describing the files we wish to search for.  The first part of the
2641 expression is recognised by the fact that it begins with @samp{-},
2642 @samp{(}, @samp{)}, @samp{,}, or @samp{!}.  Any arguments after it are
2643 the rest of the expression.  If no files are given, the current
2644 directory is used.  If no expression is given, the expression
2645 @samp{-print} is used.
2647 @code{find} exits with status zero if all files matched are processed
2648 successfully, greater than 0 if errors occur.
2650 Three options can precede the list of files.  They determine the
2651 way that symbolic links are handled.
2653 @table @code
2654 @item -P
2655 Never follow symbolic links (this is the default), except in the case
2656 of the @samp{-xtype} predicate.
2657 @item -L
2658 Always follow symbolic links, except in the case of the @samp{-xtype}
2659 predicate.
2660 @item -H
2661 Follow symbolic links specified in the list of files to search, or
2662 which are otherwise specified on the command line.
2663 @end table
2665 If @code{find} would follow a symbolic link, but cannot for any reason
2666 (for example, because it has insufficient permissions or the link is
2667 broken), it falls back on using the properties of the symbolic link
2668 itself.  @ref{Symbolic Links} for a more complete description of how
2669 symbolic links are handled.
2671 @xref{Primary Index}, for a summary of all of the tests, actions, and
2672 options that the expression can contain.  If the expression is
2673 missing, @samp{-print} is assumed.
2676 @code{find} also recognizes two options for administrative use:
2678 @table @code
2679 @item --help
2680 Print a summary of the command line usage and exit.
2681 @item --version
2682 @itemx -version
2683 Print the version number of @code{find} and exit.
2684 @end table
2687 @menu
2688 * Warning Messages::
2689 @end menu
2692 @node Warning Messages,,, Invoking find
2693 @subsection Warning Messages
2695 If there is an error on the @code{find} command line, an error message
2696 is normally issued.  However, there are some usages that are
2697 inadvisable but which @code{find} should still accept.  Under these
2698 circumstances, @code{find} may issue a warning message.  By default,
2699 warnings are enabled only if @code{find} is being run interactively
2700 (specifically, if the standard input is a terminal).  Warning messages
2701 can be controlled explicitly by the use of options on the command
2702 line:
2704 @table @code
2705 @item -warn
2706 Issue warning messages where appropriate.
2707 @item -nowarn
2708 Do not issue warning messages.
2709 @end table
2711 These options take effect at the point on the command line where they
2712 are specified.  Therefore if you specify @samp{-nowarn} at the end of
2713 the command line, you will not see warning messages for any problems
2714 occurring before that.  The warning messages affected by the above
2715 options are triggered by:
2717 @itemize @minus
2718 @item
2719 Use of the @samp{-d} option which is deprecated; please use
2720 @samp{-depth} instead, since the latter is POSIX-compliant.
2721 @item
2722 Use of the @samp{-ipath} option which is deprecated; please use
2723 @samp{-iwholename} instead.
2724 @item
2725 Specifying an option (for example @samp{-mindepth}) after a non-option
2726 (for example @samp{-type} or @samp{-print}) on the command line.
2727 @end itemize
2730 The default behaviour above is designed to work in that way so that
2731 existing shell scripts which use such constructs don't generate
2732 spurious errors, but people will be made aware of the problem.
2734 Some warning messages are issued for less common or more serious
2735 problems, and consequently cannot be turned off:
2737 @itemize @minus
2738 @item
2739 Use of an unrecognised backslash escape sequence with @samp{-fprintf}
2740 @item
2741 Use of an unrecognised formatting directive with @samp{-fprintf}
2742 @end itemize
2744 @node Invoking locate, Invoking updatedb, Invoking find, Reference
2745 @section Invoking @code{locate}
2747 @example
2748 locate @r{[}@var{option}@dots{}@r{]} @var{pattern}@dots{}
2749 @end example
2751 For each @var{pattern} given @code{locate} searches one or more file
2752 name databases returning each match of @var{pattern}.
2754 For each @var{pattern} given @code{locate} searches one or more file
2755 name databases returning each match of @var{pattern}.
2757 @table @code
2758 @item --all
2759 @itemx -A
2760 Print only names which match all non-option arguments, not those
2761 matching one or more non-option arguments.
2763 @item --basename
2764 @itemx -b
2765 The specified pattern is matched against just the last component of
2766 the name of a file in the @code{locate} database.  This last
2767 component is also called the ``base name''.  For example, the base
2768 name of @file{/tmp/mystuff/foo.old.c} is @file{foo.old.c}.  If the
2769 pattern contains metacharacters, it must match the base name exactly.
2770 If not, it must match part of the base name.
2772 @item --count
2773 @itemx -c
2774 Instead of printing the matched file names, just print the total
2775 number of matches found, unless @samp{--print} (@samp{-p}) is also
2776 present.
2779 @item --database=@var{path}
2780 @itemx -d @var{path}
2781 Instead of searching the default @code{locate} database, @code{locate} search the file
2782 name databases in @var{path}, which is a colon-separated list of
2783 database file names.  You can also use the environment variable
2784 @code{LOCATE_PATH} to set the list of database files to search.  The
2785 option overrides the environment variable if both are used.  Empty
2786 elements in @var{path} (that is, a leading or trailing colon, or two
2787 colons in a row) are taken to stand for the default database.
2788 A database can be supplied on stdin, using @samp{-} as an element
2789 of @samp{path}. If more than one element of @samp{path} is @samp{-},
2790 later instances are ignored (but a warning message is printed).
2792 @item --existing
2793 @itemx -e
2794 Only print out such names which currently exist (instead of such names
2795 which existed when the database was created).  Note that this may slow
2796 down the program a lot, if there are many matches in the database.
2797 The way in which broken symbolic links are treated is affected by the
2798 @samp{-L}, @samp{-P} and @samp{-H} options.  Please note that it is
2799 possible for the file to be deleted after @code{locate} has checked
2800 that it exists, but before you use it.
2802 @item --non-existing
2803 @itemx -E
2804 Only print out such names which currently do not exist (instead of
2805 such names which existed when the database was created).  Note that
2806 this may slow down the program a lot, if there are many matches in the
2807 database.  The way in which broken symbolic links are treated is
2808 affected by the @samp{-L}, @samp{-P} and @samp{-H} options.  Please
2809 note that @code{locate} checks that the file does not exist, but a
2810 file of the same name might be created after @code{locate}'s check but
2811 before you read @code{locate}'s output.
2813 @item --follow
2814 @itemx -L
2815 If testing for the existence of files (with the @samp{-e} or @samp{-E}
2816 options), consider broken symbolic links to be non-existing.  This is
2817 the default behaviour.  
2819 @item --nofollow
2820 @itemx -P
2821 @itemx -H
2822 If testing for the existence of files (with the @samp{-e} or @samp{-E}
2823 options), treat broken symbolic links as if they were existing files.
2824 The @samp{-H} form of this option is provided purely for similarity
2825 with @code{find}; the use of @samp{-P} is recommended over @samp{-H}.
2827 @item --ignore-case
2828 @itemx -i
2829 Ignore case distinctions in both the pattern and the file names.
2831 @item --limit=N
2832 @itemx -l N
2833 Limit the number of results printed to N.  When used with the
2834 @samp{--count} option, the value printed will never be larger than
2835 this limit.
2837 @item --mmap
2838 @itemx -m
2839 Accepted but does nothing.  The option is supported only to provide
2840 compatibility with BSD's @code{locate}.
2842 @item --null
2843 @itemx -0
2844 Results are separated with the ASCII NUL character rather than the
2845 newline character.  To get the full benefit of the use of this option,
2846 use the new @code{locate} database format (that is the default
2847 anyway).
2849 @item --print
2850 @itemx -p
2851 Print search results when they normally would not, because of the
2852 presence of @samp{--statistics} (@samp{-S}) or @samp{--count}
2853 (@samp{-c}).
2855 @item --wholename
2856 @itemx -w
2857 The specified pattern is matched against the whole name of the file in
2858 the @code{locate} database.  If the pattern contains metacharacters,
2859 it must match exactly.  If not, it must match part of the whole file
2860 name.  This is the default behaviour.
2862 @item --regex
2863 @itemx -r
2864 Instead of using substring or shell glob matching, the pattern
2865 specified on the command line is understood to be a regular
2866 expression.  GNU Emacs-style regular expressions are assumed unless
2867 the @samp{--regextype} option is also given.  File names from the
2868 @code{locate} database are matched using the specified regular
2869 expression.  If the @samp{-i} flag is also given, matching is
2870 case-insensitive.  Matches are performed against the whole path name,
2871 and so by default a pathname will be matched if any part of it matches
2872 the specified regular expression.  The regular expression may use
2873 @samp{^} or @samp{$} to anchor a match at the beginning or end of a
2874 pathname.
2876 @item --regextype
2877 This option changes the regular expression syntax and behaviour used
2878 by the @samp{--regex} option.  @ref{Regular Expressions} for more
2879 information on the regular expression dialects understood by GNU
2880 findutils.
2882 @item --stdio
2883 @itemx -s
2884 Accepted but does nothing.  The option is supported only to provide
2885 compatibility with BSD's @code{locate}.
2887 @item --statistics
2888 @itemx -S
2889 Print some summary information for each @code{locate} database.  No
2890 search is performed unless non-option arguments are given.
2892 @item --help
2893 Print a summary of the command line usage for @code{locate} and exit.
2895 @item --version
2896 Print the version number of @code{locate} and exit.
2897 @end table
2899 @node Invoking updatedb, Invoking xargs, Invoking locate, Reference
2900 @section Invoking @code{updatedb}
2902 @example
2903 updatedb @r{[}@var{option}@dots{}@r{]}
2904 @end example
2906 @code{updatedb} creates and updates the database of file names used by
2907 @code{locate}.  @code{updatedb} generates a list of files similar to
2908 the output of @code{find} and then uses utilities for optimizing the
2909 database for performance.  @code{updatedb} is often run periodically
2910 as a @code{cron} job and configured with environment variables or
2911 command options.  Typically, operating systems have a shell script
2912 that ``exports'' configurations for variable definitions and uses
2913 another schell script that ``sources'' the configuration file into the
2914 environment and then executes @code{updatedb} in the environment.
2916 @code{updatedb} creates and updates the database of file names used by
2917 @code{locate}.  @code{updatedb} generates a list of files similar to
2918 the output of @code{find} and then uses utilities for optimizing the
2919 database for performance.  @code{updatedb} is often run periodically
2920 as a @code{cron} job and configured with environment variables or
2921 command options.  Typically, operating systems have a shell script
2922 that ``exports'' configurations for variable definitions and uses
2923 another schell script that ``sources'' the configuration file into the
2924 environment and then executes @code{updatedb} in the environment.
2926 @table @code
2927 @item --findoptions='@var{OPTION}@dots{}'
2928 Global options to pass on to @code{find}.
2929 The environment variable @code{FINDOPTIONS} also sets this value.
2930 Default is none.
2932 @item --localpaths='@var{path}@dots{}'
2933 Non-network directories to put in the database.
2934 Default is @file{/}.
2936 @item --netpaths='@var{path}@dots{}'
2937 Network (NFS, AFS, RFS, etc.) directories to put in the database.
2938 The environment variable @code{NETPATHS} also sets this value.
2939 Default is none.
2941 @item --prunepaths='@var{path}@dots{}'
2942 Directories to omit from the database, which would otherwise be
2943 included.  The environment variable @code{PRUNEPATHS} also sets this
2944 value.  Default is @file{/tmp /usr/tmp /var/tmp /afs}.  The paths are
2945 used as regular expressions (with @code{find ... -regex}, so you need
2946 to specify these paths in the same way that @code{find} will encounter
2947 them.  This means for example that the paths must not include trailing
2948 slashes.
2950 @item --prunefs='@var{path}@dots{}'
2951 Filesystems to omit from the database, which would otherwise be
2952 included.  Note that files are pruned when a filesystem is reached;
2953 Any filesystem mounted under an undesired filesystem will be ignored.
2954 The environment variable @code{PRUNEFS} also sets this value.  Default
2955 is @file{nfs NFS proc}.
2957 @item --output=@var{dbfile}
2958 The database file to build.  Default is system-dependent, but
2959 typically @file{/usr/local/var/locatedb}.
2961 @item --localuser=@var{user}
2962 The user to search the non-network directories as, using @code{su}.
2963 Default is to search the non-network directories as the current user.
2964 You can also use the environment variable @code{LOCALUSER} to set this user.
2966 @item --netuser=@var{user}
2967 The user to search network directories as, using @code{su}.  Default
2968 @code{user} is @code{daemon}.  You can also use the environment variable
2969 @code{NETUSER} to set this user.
2971 @item --old-format
2972 Generate a @code{locate} database in the old format, for compatibility
2973 with versions of @code{locate} other than GNU @code{locate}.  Using
2974 this option means that @code{locate} will not be able to properly
2975 handle non-ASCII characters in file names (that is, file names
2976 containing characters which have the eighth bit set, such as many of
2977 the characters from the ISO-8859-1 character set).
2978 @item --help
2979 Print a summary of the command line usage and exit.
2980 @item --version
2981 Print the version number of @code{updatedb} and exit.
2982 @end table
2984 @node Invoking xargs, Regular Expressions,  Invoking updatedb, Reference
2985 @section Invoking @code{xargs}
2987 @example
2988 xargs @r{[}@var{option}@dots{}@r{]} @r{[}@var{command} @r{[}@var{initial-arguments}@r{]}@r{]}
2989 @end example
2991 @code{xargs} exits with the following status:
2993 @table @asis
2994 @item 0
2995 if it succeeds
2996 @item 123
2997 if any invocation of the command exited with status 1-125
2998 @item 124
2999 if the command exited with status 255
3000 @item 125
3001 if the command is killed by a signal
3002 @item 126
3003 if the command cannot be run
3004 @item 127
3005 if the command is not found
3006 @item 1
3007 if some other error occurred.
3008 @end table
3010 Exit codes greater than 128 are used by the shell to indicate that 
3011 a program died due to a fatal signal.
3012   
3013 @table @code
3014 @item --arg-file@r{=@var{inputfile}}
3015 @itemx -a o@r{@var{inputfile}}
3016 Read names from the file @var{inputfile} instead of standard input.
3017 If you use this option, the standard input stream remains unchanged
3018 when commands are run. Otherwise, stdin is redirected from
3019 @file{/dev/null}.
3021 @item --null
3022 @itemx -0
3023 Input file names are terminated by a null character instead of by
3024 whitespace, and any quotes and backslash characters are not considered
3025 special (every character is taken literally).  Disables the end of
3026 file string, which is treated like any other argument.
3028 @item --delimiter @var{delim}
3029 @itemx -d @var{delim}
3031 Input file names are terminated by the specified character @var{delim}
3032 instead of by whitespace, and any quotes and backslash characters are
3033 not considered special (every character is taken literally).  Disables
3034 the end of file string, which is treated like any other argument.
3036 The specified delimiter may be a single character, a C-style character
3037 escape such as @samp{\n}, or an octal or hexadecimal escape code.
3038 Octal and hexadecimal escape codes are understood as for the
3039 @code{printf} command.  Multibyte characters are not supported.
3042 @item -E @var{eof-str}
3043 @itemx --eof@r{[}=@var{eof-str}@r{]}
3044 @itemx -e@r{[}@var{eof-str}@r{]}
3045 Set the end of file string to @var{eof-str}.  If the end of file
3046 string occurs as a line of input, the rest of the input is ignored.
3047 If @var{eof-str} is omitted (@samp{-e}) or blank (either @samp{-e} or
3048 @samp{-E}), there is no end of file string.  The @samp{-e} form of
3049 this option is deprecated in favour of the POSIX-compliant @samp{-E}
3050 option, which you should use instead.  As of GNU xargs version 4.2.9,
3051 the default behaviour of xargs is not to have a logical end-of-file
3052 marker.  The POSIX standard (IEEE Std 1003.1, 2004 Edition) allows
3053 this.
3055 @item --help
3056 Print a summary of the options to @code{xargs} and exit.
3058 @item -I @var{replace-str}
3059 @itemx --replace@r{[}=@var{replace-str}@r{]}
3060 @itemx -i@r{[}@var{replace-str}@r{]}
3061 Replace occurrences of @var{replace-str} in the initial arguments with
3062 names read from standard input.  Also, unquoted blanks do not
3063 terminate arguments; instead, the input is split at newlines only.  If
3064 @var{replace-str} is omitted (omitting it is allowed only for
3065 @samp{-i}), it defaults to @samp{@{@}} (like for @samp{find -exec}).
3066 Implies @samp{-x} and @samp{-l 1}.  The @samp{-i} option is deprecated
3067 in favour of the @samp{-I} option.
3069 @item -L @var{max-lines}
3070 @itemx --max-lines@r{[}=@var{max-lines}@r{]}
3071 @itemx -l@r{[}@var{max-lines}@r{]}
3072 Use at most @var{max-lines} non-blank input lines per command line.
3073 For @samp{-l}, @var{max-lines} defaults to 1 if omitted.  For
3074 @samp{-L}, the argument is mandatory.  Trailing blanks cause an input
3075 line to be logically continued on the next input line, for the purpose
3076 of counting the lines.  Implies @samp{-x}.  The @samp{-l} form of this
3077 option is deprecared in favour of the POSIX-compliant @samp{-L}
3078 option.
3080 @item --max-args=@var{max-args}
3081 @itemx -n @var{max-args}
3082 Use at most @var{max-args} arguments per command line.  Fewer than
3083 @var{max-args} arguments will be used if the size (see the @samp{-s}
3084 option) is exceeded, unless the @samp{-x} option is given, in which
3085 case @code{xargs} will exit.
3087 @item --interactive
3088 @itemx -p
3089 Prompt the user about whether to run each command line and read a line
3090 from the terminal.  Only run the command line if the response starts
3091 with @samp{y} or @samp{Y}.  Implies @samp{-t}.
3093 @item --no-run-if-empty
3094 @itemx -r
3095 If the standard input is completely empty, do not run the
3096 command.  By default, the command is run once even if there is no
3097 input.
3099 @item --max-chars=@var{max-chars}
3100 @itemx -s @var{max-chars}
3101 Use at most @var{max-chars} characters per command line, including the
3102 command, initial arguments and any terminating nulls at the ends of
3103 the argument strings.
3105 @item --show-limits
3106 Display the limits on the command-line length which are imposed by the
3107 operating system, @code{xargs}' choice of buffer size and the
3108 @samp{-s} option.  Pipe the input from @file{/dev/null} (and perhaps
3109 specify @samp{--no-run-if-empty}) if you don't want @code{xargs} to do
3110 anything.
3112 @item --verbose
3113 @itemx -t
3114 Print the command line on the standard error output before executing
3117 @item --version
3118 Print the version number of @code{xargs} and exit.
3120 @item --exit
3121 @itemx -x
3122 Exit if the size (see the @samp{-s} option) is exceeded.
3125 @item --max-procs=@var{max-procs}
3126 @itemx -P @var{max-procs}
3127 Run simultaneously up to @var{max-procs} processes at once; the default is 1.  If
3128 @var{max-procs} is 0, @code{xargs} will run as many processes as
3129 possible simultaneously.
3130 @end table
3133 @node Regular Expressions, Environment Variables, Invoking xargs, Reference
3134 @section Regular Expressions
3136 The @samp{-regex} and @samp{-iregex} tests of @code{find} allow
3137 matching by regular expression, as does the @samp{--regex} option of
3138 @code{locate}.  There are many different types of Regular Expression,
3139 but the type used by @code{find} and @code{locate} is the same as is
3140 used in GNU Emacs.  Both programs provide an option which allows you
3141 to select an alternative regular expression syntax; for @code{find}
3142 this is the @samp{-regextype} option, and for @code{locate} this is
3143 the @samp{--regextype} option.
3145 These options take a single argument, which indicates the specific
3146 regular expression syntax and behaviour that should be used.  This
3147 should be one of the following:
3149 @include regexprops.texi
3151 @node Environment Variables,, Regular Expressions, Reference
3152 @section Environment Variables
3153 @table @var
3154 @item LANG
3155 Provides a default value for the internationalization variables that
3156 are unset or null.
3157 @item LC_ALL
3158 If set to a non-empty string value, override the values of all the
3159 other internationalization variables.
3160 @item LC_COLLATE
3161 The POSIX standard specifies that this variable affects the pattern
3162 matching to be used for the `\-name' option.  GNU find uses the
3163 GNU version of the @code{fnmatch} library function.
3165 POSIX also specifies that the `LC_COLLATE' environment 
3166 variable affects the interpretation of the user's response to the 
3167 query issued by `\-ok', but this is not the case for GNU find.
3168 @item LC_CTYPE 
3169 This variable affects the treatment of character classes used with 
3170 the @samp{-name} test, if the system's 
3171 @code{fnmatch} library function supports this.   It has no effect on the behaviour 
3172 of the @samp{-ok} expression.
3173 @item LC_MESSAGES
3174 Determines the locale to be used for internationalised messages.
3175 @item NLSPATH
3176 Determines the location of the internationalisation message catalogues.
3177 @item PATH
3178 Affects the directories which are searched to find the executables
3179 invoked by @samp{-exec}, @samp{-execdir} @samp{-ok} and @samp{-okdir}.
3180 If the @var{PATH} environment variable includes the current directory
3181 (by explicitly including @samp{.} or by having an empty element), and
3182 the find command line includes @samp{-execdir} or @samp{-okdir},
3183 @code{find} will refuse to run.  @xref{Security Considerations}, for a
3184 more detailed discussion of security matters.
3186 @item POSIXLY_CORRECT 
3187 Determines the block size used by @samp{-ls} and @samp{-fls}.  
3188 If @var{POSIXLY_CORRECT} is set, blocks are units of 512 bytes.  Otherwise
3189 they are units of 1024 bytes.
3191 @item TZ 
3192 Affects the time zone used for some of the time-related format
3193 directives of @samp{-printf} and @samp{-fprintf}.
3194 @end table
3198 @node Common Tasks, Worked Examples, Reference, Top
3199 @chapter Common Tasks
3201 The sections that follow contain some extended examples that both give
3202 a good idea of the power of these programs, and show you how to solve
3203 common real-world problems.
3205 @menu
3206 * Viewing And Editing::
3207 * Archiving::
3208 * Cleaning Up::
3209 * Strange File Names::
3210 * Fixing Permissions::
3211 * Classifying Files::
3212 @end menu
3214 @node Viewing And Editing
3215 @section Viewing And Editing
3217 To view a list of files that meet certain criteria, simply run your
3218 file viewing program with the file names as arguments.  Shells
3219 substitute a command enclosed in backquotes with its output, so the
3220 whole command looks like this:
3222 @example
3223 less `find /usr/include -name '*.h' | xargs grep -l mode_t`
3224 @end example
3226 @noindent
3227 You can edit those files by giving an editor name instead of a file
3228 viewing program:
3230 @example
3231 emacs `find /usr/include -name '*.h' | xargs grep -l mode_t`
3232 @end example
3234 Because there is a limit to the length of any individual command line,
3235 there is a limit to the number of files that can be handled in this
3236 way.  We can get around this difficulty by using xargs like this:
3238 @example
3239 find /usr/include -name '*.h' | xargs grep -l mode_t > todo
3240 xargs --arg-file=todo emacs
3241 @end example
3243 Here, @code{xargs} will run @code{emacs} as many times as necessary to
3244 visit all of the files listed in the file @file{todo}.
3246 @node Archiving
3247 @section Archiving
3249 You can pass a list of files produced by @code{find} to a file
3250 archiving program.  GNU @code{tar} and @code{cpio} can both read lists
3251 of file names from the standard input---either delimited by nulls (the
3252 safe way) or by blanks (the lazy, risky default way).  To use
3253 null-delimited names, give them the @samp{--null} option.  You can
3254 store a file archive in a file, write it on a tape, or send it over a
3255 network to extract on another machine.
3257 One common use of @code{find} to archive files is to send a list of
3258 the files in a directory tree to @code{cpio}.  Use @samp{-depth} so if
3259 a directory does not have write permission for its owner, its contents
3260 can still be restored from the archive since the directory's
3261 permissions are restored after its contents.  Here is an example of
3262 doing this using @code{cpio}; you could use a more complex @code{find}
3263 expression to archive only certain files.
3265 @example
3266 find . -depth -print0 |
3267   cpio --create --null --format=crc --file=/dev/nrst0
3268 @end example
3270 You could restore that archive using this command:
3272 @example
3273 cpio --extract --null --make-dir --unconditional \
3274   --preserve --file=/dev/nrst0
3275 @end example
3277 Here are the commands to do the same things using @code{tar}:
3279 @example
3280 find . -depth -print0 |
3281   tar --create --null --files-from=- --file=/dev/nrst0
3283 tar --extract --null --preserve-perm --same-owner \
3284   --file=/dev/nrst0
3285 @end example
3287 @c Idea from Rick Sladkey.
3288 Here is an example of copying a directory from one machine to another:
3290 @example
3291 find . -depth -print0 | cpio -0o -Hnewc |
3292   rsh @var{other-machine} "cd `pwd` && cpio -i0dum"
3293 @end example
3295 @node Cleaning Up
3296 @section Cleaning Up
3298 @c Idea from Jim Meyering.
3299 This section gives examples of removing unwanted files in various
3300 situations.  Here is a command to remove the CVS backup files created
3301 when an update requires a merge:
3303 @example
3304 find . -name '.#*' -print0 | xargs -0r rm -f
3305 @end example
3307 The command above works, but the following is safer:
3309 @example
3310 find . -name '.#*' -depth -delete
3311 @end example
3313 @c Idea from Franc,ois Pinard.
3314 You can run this command to clean out your clutter in @file{/tmp}.
3315 You might place it in the file your shell runs when you log out
3316 (@file{.bash_logout}, @file{.logout}, or @file{.zlogout}, depending on
3317 which shell you use).
3319 @example
3320 find /tmp -depth -user "$LOGNAME" -type f -delete
3321 @end example
3323 If your @code{find} command removes directories, you may find that
3324 you get a spurious error message when @code{find} tries to recurse
3325 into a directory that has now been removed.  Using the @samp{-depth}
3326 option will normally resolve this problem.
3328 @c Idea from Noah Friedman.
3329 To remove old Emacs backup and auto-save files, you can use a command
3330 like the following.  It is especially important in this case to use
3331 null-terminated file names because Emacs packages like the VM mailer
3332 often create temporary file names with spaces in them, like
3333 @file{#reply to David J. MacKenzie<1>#}.
3335 @example
3336 find ~ \( -name '*~' -o -name '#*#' \) -print0 |
3337   xargs --no-run-if-empty --null rm -vf
3338 @end example
3340 Removing old files from @file{/tmp} is commonly done from @code{cron}:
3342 @c Idea from Kaveh Ghazi.
3343 @example
3344 find /tmp /var/tmp -not -type d -mtime +3 -delete
3345 find /tmp /var/tmp -depth -mindepth 1 -type d -empty -delete
3346 @end example
3348 The second @code{find} command above uses @samp{-depth} so it cleans
3349 out empty directories depth-first, hoping that the parents become
3350 empty and can be removed too.  It uses @samp{-mindepth} to avoid
3351 removing @file{/tmp} itself if it becomes totally empty.
3353 @node Strange File Names
3354 @section Strange File Names
3356 @c Idea from:
3357 @c From: tmatimar@isgtec.com (Ted Timar)
3358 @c Newsgroups: comp.unix.questions,comp.unix.shell,comp.answers,news.answers
3359 @c Subject: Unix - Frequently Asked Questions (2/7) [Frequent posting]
3360 @c Subject: How do I remove a file with funny characters in the filename ?
3361 @c Date: Thu Mar 18 17:16:55 EST 1993
3362 @code{find} can help you remove or rename a file with strange
3363 characters in its name.  People are sometimes stymied by files whose
3364 names contain characters such as spaces, tabs, control characters, or
3365 characters with the high bit set.  The simplest way to remove such
3366 files is:
3368 @example
3369 rm -i @var{some*pattern*that*matches*the*problem*file}
3370 @end example
3372 @code{rm} asks you whether to remove each file matching the given
3373 pattern.  If you are using an old shell, this approach might not work
3374 if the file name contains a character with the high bit set; the shell
3375 may strip it off.  A more reliable way is:
3377 @example
3378 find . -maxdepth 1 @var{tests} -okdir rm '@{@}' \;
3379 @end example
3381 @noindent
3382 where @var{tests} uniquely identify the file.  The @samp{-maxdepth 1}
3383 option prevents @code{find} from wasting time searching for the file
3384 in any subdirectories; if there are no subdirectories, you may omit
3385 it.  A good way to uniquely identify the problem file is to figure out
3386 its inode number; use
3388 @example
3389 ls -i
3390 @end example
3392 Suppose you have a file whose name contains control characters, and
3393 you have found that its inode number is 12345.  This command prompts
3394 you for whether to remove it:
3396 @example
3397 find . -maxdepth 1 -inum 12345 -okdir rm -f '@{@}' \;
3398 @end example
3400 If you don't want to be asked, perhaps because the file name may
3401 contain a strange character sequence that will mess up your screen
3402 when printed, then use @samp{-execdir} instead of @samp{-okdir}.
3404 If you want to rename the file instead, you can use @code{mv} instead
3405 of @code{rm}:
3407 @example
3408 find . -maxdepth 1 -inum 12345 -okdir mv '@{@}' @var{new-file-name} \;
3409 @end example
3411 @node Fixing Permissions
3412 @section Fixing Permissions
3414 Suppose you want to make sure that everyone can write to the
3415 directories in a certain directory tree.  Here is a way to find
3416 directories lacking either user or group write permission (or both),
3417 and fix their permissions:
3419 @example
3420 find . -type d -not -perm -ug=w | xargs chmod ug+w
3421 @end example
3423 @noindent
3424 You could also reverse the operations, if you want to make sure that
3425 directories do @emph{not} have world write permission.
3427 @node Classifying Files
3428 @section Classifying Files
3430 @c Idea from:
3431 @c From: martin@mwtech.UUCP (Martin Weitzel)
3432 @c Newsgroups: comp.unix.wizards,comp.unix.questions
3433 @c Subject: Advanced usage of 'find' (Re: Unix security automating script)
3434 @c Date: 22 Mar 90 15:05:19 GMT
3435 If you want to classify a set of files into several groups based on
3436 different criteria, you can use the comma operator to perform multiple
3437 independent tests on the files.  Here is an example:
3439 @example
3440 find / -type d \( -perm -o=w -fprint allwrite , \
3441   -perm -o=x -fprint allexec \)
3443 echo "Directories that can be written to by everyone:"
3444 cat allwrite
3445 echo ""
3446 echo "Directories with search permissions for everyone:"
3447 cat allexec
3448 @end example
3450 @code{find} has only to make one scan through the directory tree
3451 (which is one of the most time consuming parts of its work).
3453 @node Worked Examples, Security Considerations, Common Tasks, Top
3454 @chapter Worked Examples
3456 The tools in the findutils package, and in particular @code{find},
3457 have a large number of options.  This means that quite often,
3458 there is more than one way to do things.  Some of the options
3459 and facilities only exist for compatibility with other tools, and
3460 findutils provides improved ways of doing things.
3462 This chapter describes a number of useful tasks that are commonly
3463 performed, and compares the different ways of achieving them.
3465 @menu
3466 * Deleting Files::
3467 * Updating A Timestamp File::
3468 @end menu
3470 @node Deleting Files
3471 @section Deleting Files
3473 One of the most common tasks that @code{find} is used for is locating
3474 files that can be deleted.  This might include:
3476 @itemize
3477 @item 
3478 Files last modified more than 3 years ago which haven't been accessed
3479 for at least 2 years
3480 @item
3481 Files belonging to a certain user
3482 @item
3483 Temporary files which are no longer required
3484 @end itemize
3486 This example concentrates on the actual deletion task rather than on
3487 sophisticated ways of locatng the files that need to be deleted.
3488 We'll assume that the files we want to delete are old files underneath
3489 @file{/var/tmp/stuff}.
3491 @subsection The Traditional Way
3493 The traditional way to delete files in @file{var/tmp/stuff} that have
3494 not been modified in over 90 days would have been:
3496 @smallexample
3497 find /var/tmp/stuff -mtime +90 -exec /bin/rm @{@} \;
3498 @end smallexample
3500 The above command uses @samp{-exec} to run the @code{/bin/rm} command
3501 to remove each file.  This approach works and in fact would have
3502 worked in Version 7 Unix in 1979.  However, there are a number of
3503 problems with this approach.
3506 The most obvious problem with the approach above is that it causes
3507 @code{find} to fork every time it finds a file that needs to delete,
3508 and the child process then has to use the @code{exec} system call to
3509 launch @code{/bin/rm}.   All this is quite inefficient.  If we are
3510 going to use @code{/bin/rm} to do this job, it is better to make it
3511 delete more than one file at a time.  
3513 The most obvious way of doing this is to use the shell's command
3514 expansion feature:
3516 @smallexample
3517 /bin/rm `find /var/tmp/stuff -mtime +90 -print`
3518 @end smallexample
3519 or you could use the more modern form
3520 @smallexample
3521 /bin/rm $(find /var/tmp/stuff -mtime +90 -print)
3522 @end smallexample
3524 The commands above are much more efficient than the first attempt.
3525 However, there is a problem with them.  The shell has a maximum
3526 command length which is imposed by the operating system (the actual
3527 limit varies between systems).  This means that while the command
3528 expansion technique will usually work, it will suddenly fail when
3529 there are lots of files to delete.  Since the task is to delete
3530 unwanted files, this is precisely the time we don't want things to go
3531 wrong.
3533 @subsection Making Use of xargs
3535 So, is there a way to be more efficient in the use of @code{fork()}
3536 and @code{exec()} without running up against this limit?
3537 Yes, we can be almost optimally efficient by making use
3538 of the @code{xargs} command.  The @code{xargs} command reads arguments
3539 from its standard input and builds them into command lines.  We can
3540 use it like this:
3542 @smallexample
3543 find /var/tmp/stuff -mtime +90 -print | xargs /bin/rm 
3544 @end smallexample
3546 For example if the files found by @code{find} are
3547 @file{/var/tmp/stuff/A}, 
3548 @file{/var/tmp/stuff/B} and 
3549 @file{/var/tmp/stuff/C} then @code{xargs} might issue the commands 
3551 @smallexample
3552 /bin/rm /var/tmp/stuff/A /var/tmp/stuff/B
3553 /bin/rm /var/tmp/stuff/C
3554 @end smallexample
3556 The above assumes that @code{xargs} has a very small maximum command
3557 line length.  The real limit is much larger but the idea is that
3558 @code{xargs} will run @code{/bin/rm} as many times as necessary to get
3559 the job done, given the limits on command line length.
3561 This usage of @code{xargs} is pretty efficient, and the @code{xargs}
3562 command is widely implemented (all modern versions of Unix offer it).
3563 So far then, the news is all good.  However, there is bad news too.
3565 @subsection Unusual characters in filenames
3567 Unix-like systems allow any characters to appear in file names with
3568 the exception of the ASCII NUL character and the backslash.
3569 Backslashes can occur in path names (as the directory separator) but
3570 not in the names of actual directory entries.  This means that the
3571 list of files that @code{xargs} reads could in fact contain white space
3572 characters --- spaces, tabs and newline characters.  Since by default,
3573 @code{xargs} assumes that the list of files it is reading uses white
3574 space as an argument separator, it cannot correctly handle the case
3575 where a filename actually includes white space.  This makes the
3576 default behaviour of @code{xargs} almost useless for handling
3577 arbitrary data.
3579 To solve this problem, GNU findutils introduced the @samp{-print0}
3580 action for @code{find}.  This uses the ASCII NUL character to separate
3581 the entries in the file list that it produces.  This is the ideal
3582 choice of separator since it is the only character that cannot appear
3583 within a path name.  The @samp{-0} option to @code{xargs} makes it
3584 assume that arguments are separated with ASCII NUL instead of white
3585 space.  It also turns off another misfeature in the default behaviour
3586 of @code{xargs}, which is that it pays attention to quote characters
3587 in its input.  Some versions of @code{xargs} also terminate when they
3588 see a lone @samp{_} in the input, but GNU @code{find} no longer does
3589 that (since it has become an optional behaviour in the Unix standard).
3591 So, putting @code{find -print0} together with @code{xargs -0} we get
3592 this command:
3594 @smallexample
3595 find /var/tmp/stuff -mtime +90 -print0 | xargs -0 /bin/rm 
3596 @end smallexample
3598 The result is an efficient way of proceeding that
3599 correctly handles all the possible characters that could appear in the
3600 list of files to delete.  This is good news.  However, there is, as
3601 I'm sure you're expecting, also more bad news.  The problem is that
3602 this is not a portable construct; although other versions of Unix
3603 (notable BSD-derived ones) support @samp{-print0}, it's not
3604 universal.  So, is there a more universal mechanism?
3606 @subsection Going back to -exec
3608 There is indeed a more universal mechanism, which is a slight
3609 modification to the @samp{-exec} action.  The normal @samp{-exec}
3610 action assumes that the command to run is terminated with a semicolon
3611 (the semicolon normally has to be quoted in order to protect it from
3612 interpretation as the shell command separator).  The SVR4 edition of
3613 Unix introduced a slight variation, which involves terminating the
3614 command with @samp{+} instead:
3616 @smallexample
3617 find /var/tmp/stuff -mtime +90 -exec /bin/rm @{@} \+
3618 @end smallexample
3620 The above use of @samp{-exec} causes @code{find} to build up a long
3621 command line and then issue it.  This can be less efficient than some
3622 uses of @code{xargs}; for example @code{xargs} allows new command
3623 lines to be built up while the previous command is still executing, and
3624 allows you to specify a number of commands to run in parallel.
3625 However, the @code{find @dots{} -exec @dots{} +} construct has the advantage
3626 of wide portability.  GNU findutils did not support @samp{-exec @dots{} +}
3627 until version 4.2.12; one of the reasons for this is that it already
3628 had the @samp{-print0} action in any case.
3631 @subsection A more secure version of -exec
3633 The command above seems to be efficient and portable.  However,
3634 within it lurks a security problem.  The problem is shared with
3635 all the commands we've tried in this worked example so far, too.  The
3636 security problem is a race condition; that is, if it is possible for
3637 somebody to manipulate the filesystem that you are searching while you
3638 are searching it, it is possible for them to persuade your @code{find}
3639 command to cause the deletion of a file that you can delete but they
3640 normally cannot.  
3642 The problem occurs because the @samp{-exec} action is defined by the
3643 @acronym{POSIX} standard to invoke its command with the same working directory
3644 as @code{find} had when it was started.  This means that the arguments
3645 which replace the @{@} include a relative path from @code{find}'s
3646 starting point down the file that needs to be deleted.  For example,
3648 @smallexample
3649 find /var/tmp/stuff -mtime +90 -exec /bin/rm @{@} \+
3650 @end smallexample
3652 might actually issue the command:
3654 @smallexample
3655 /bin/rm /var/tmp/stuff/A /var/tmp/stuff/B /var/tmp/stuff/passwd
3656 @end smallexample
3658 Notice the file @file{/var/tmp/stuff/passwd}.  Likewise, the command:
3660 @smallexample
3661 cd /var/tmp && find stuff -mtime +90 -exec /bin/rm @{@} \+
3662 @end smallexample
3664 might actually issue the command:
3666 @smallexample
3667 /bin/rm stuff/A stuff/B stuff/passwd
3668 @end smallexample
3670 If an attacker can rename @file{stuff} to something else (making use
3671 of their write permissions in @file{/var/tmp}) they can replace it
3672 with a symbolic link to @file{/etc}.  That means that the
3673 @code{/bin/rm} command will be invoked on @file{/etc/passwd}.  If you
3674 are running your @code{find} command as root, the attacker has just managed
3675 to delete a vital file.  All they needed to do to achieve this was
3676 replace a subdirectory with a symbolic link at the vital moment.
3678 There is however, a simple solution to the problem.  This is an action
3679 which works a lot like @code{-exec} but doesn't need to traverse a
3680 chain of directories to reach the file that it needs to work on.  This
3681 is the @samp{-execdir} action, which was introduced by the BSD family
3682 of operating systems.   The command,
3684 @smallexample
3685 find /var/tmp/stuff -mtime +90 -execdir /bin/rm @{@} \+
3686 @end smallexample
3688 might delete a set of files by performing these actions:
3690 @enumerate
3691 @item 
3692 Change directory to /var/tmp/stuff/foo
3693 @item 
3694 Invoke @code{/bin/rm ./file1 ./file2 ./file3}
3695 @item
3696 Change directory to /var/tmp/stuff/bar
3697 @item 
3698 Invoke @code{/bin/rm ./file99 ./file100 ./file101}
3699 @end enumerate
3701 This is a much more secure method.  We are no longer exposed to a race
3702 condition.  For many typical uses of @code{find}, this is the best
3703 strategy.   It's reasonably efficient, but the length of the command
3704 line is limited not just by the operating system limits, but also by
3705 how many files we actually need to delete from each directory.
3707 Is it possible to do any better?   In the case of general file
3708 processing, no.  However, in the specific case of deleting files it is
3709 indeed possible to do better.  
3711 @subsection Using the -delete action
3713 The most efficient and secure method of solving this problem is to use
3714 the @samp{-delete} action:
3716 @smallexample
3717 find /var/tmp/stuff -mtime +90 -delete
3718 @end smallexample
3720 This alternative is more efficient than any of the @samp{-exec} or
3721 @samp{-execdir} actions, since it entirely avoids the overhead of
3722 forking a new process and using @code{exec} to run @code{/bin/rm}.  It
3723 is also normally more efficient than @code{xargs} for the same
3724 reason.   The file deletion is performed from the directory containing
3725 the entry to be deleted, so the @samp{-delete} action has the same
3726 security advantages as the @samp{-execdir} action has.  
3728 The @samp{-delete} action was introduced by the BSD family of
3729 operating systems.
3731 @subsection Improving things still further
3733 Is it possible to improve things still further?  Not without either
3734 modifying the system library to the operating system or having more specific
3735 knowledge of the layout of the filesystem and disk I/O subsystem, or
3736 both.
3738 The @code{find} command traverses the filesystem, reading
3739 directories.  It then issues a separate system call for each file to
3740 be deleted.  If we could modify the operating system, there are
3741 potential gains that could be made:
3743 @itemize
3744 @item
3745 We could have a system call to which we pass more than one filename
3746 for deletion
3747 @item
3748 Alternatively, we could pass in a list of inode numbers (on GNU/Linux
3749 systems, @code{readdir()} also returns the inode number of each
3750 directory entry) to be deleted.
3751 @end itemize
3753 The above possibilities sound interesting, but from the kernel's point
3754 of view it is difficult to enforce standard Unix access controls for
3755 such processing by inode number.  Such a facility would probably
3756 need to be restricted to the superuser.
3758 Another way of improving performance would be to increase the
3759 parallelism of the process.  For example if the directory hierarchy we
3760 are searching is actually spread across a number of disks, we might
3761 somehow be able to arrange for @code{find} to process each disk in
3762 parallel.  In practice GNU @code{find} doesn't have such an intimate
3763 understanding of the system's filesystem layout and disk I/O
3764 subsystem.
3766 However, since the system administrator can have such an understanding
3767 they can take advantage of it like so:
3769 @smallexample
3770 find /var/tmp/stuff1 -mtime +90 -delete &
3771 find /var/tmp/stuff2 -mtime +90 -delete &
3772 find /var/tmp/stuff3 -mtime +90 -delete &
3773 find /var/tmp/stuff4 -mtime +90 -delete &
3774 wait
3775 @end smallexample
3777 In the example above, four spearate instances of @code{find} are used
3778 to search four subdirectories in parallel.  The @code{wait} command
3779 simply waits for all of these to complete.  Whether this approach is
3780 more or less efficient than a single instance of @code{find} depends
3781 on a number of things:
3783 @itemize
3784 @item
3785 Are the directories being searched in parallel actually on separate
3786 disks?  If not, this parallel search might just result in a lot of
3787 disk head movement and so the speed might even be slower.
3788 @item
3789 Other activity - are other programs also doing things on those disks?
3790 @end itemize
3793 @subsection Conclusion
3795 The fastest and most secure way to delete files with the help of
3796 @code{find} is to use @samp{-delete}.  Using @code{xargs -0 -P N} can
3797 also make effective use of the disk, but it is not as secure.
3799 In the case where we're doing things other than deleting files, the
3800 most secure alternative is @samp{-execdir @dots{} +}, but this is not as
3801 portable as the insecure action @samp{-exec @dots{} +}.
3803 The @samp{-delete} action is not completely portable, but the only
3804 other possiblility which is as secure (@samp{-execdir}) is no more
3805 portable.  The most efficient portable alternative is @samp{-exec
3806 @dots{}+}, but this is insecure and isn't supported by versions of GNU
3807 findutils prior to 4.2.12.
3810 @node Updating A Timestamp File
3811 @section Updating A Timestamp File
3813 Suppose we have a directory full of files which is maintained with a
3814 set of automated tools; perhaps one set of tools updates them and
3815 another set of tools uses the result.  In this situation, it might be
3816 useful for the second set of tools to know if the files have recently
3817 been changed.  It might be useful, for example, to have a 'timestamp'
3818 file which gives the timestamp on the newest file in the collection.
3820 We can use @code{find} to achieve this, but there are several
3821 different ways to do it.
3823 @subsection Updating the Timestamp The Wrong Way
3825 The obvious but wrong answer is just to use @samp{-newer}:-
3827 @smallexample
3828 find subdir -newer timestamp -exec touch -r @{@} timestamp \; 
3829 @end smallexample
3831 This does the right sort of thing but has a bug.  Suppose that two
3832 files in the subdirectory have been updated, and that these are called
3833 @file{file1} and @file{file2}.  The command above will update
3834 @file{timestamp} with the modification time of @file{file1} or that of
3835 @file{file2}, but we don't know which one.  Since the timestamps on
3836 @file{file1} and @file{file2} will in general be different, this could
3837 well be the wrong value.
3839 One solution to this problem is to modify @code{find} to recheck the
3840 modification time of @file{timestamp} every time a file is to be
3841 compared against it, but that will reduce the performence of
3842 @code{find}.
3844 @subsection Using the test utlity to compare timestamps
3846 The @code{test} command can be used to compare timestamps:
3848 @smallexample
3849 find subdir -exec test @{@} -nt timestamp \; -exec touch -r @{@} timestamp \; 
3850 @end smallexample
3852 This will ensure that any changes made to the modification time of
3853 @file{timestamp} that take place during the execution of @code{find}
3854 are taken into account.  This resolves our earlier problem, but
3855 unfortunately this runs much more slowly.
3857 @subsection A combined approach
3859 We can of course still use @samp{-newer} to cut down on the number of
3860 calls to @code{test}:
3862 @smallexample
3863 find subdir -newer timestamp -a \
3864      -exec test @{@} -nt timestamp \; -a \
3865      -exec touch -r @{@} timestamp \; 
3866 @end smallexample
3868 Here, the @samp{-newer} test excludes all the files which are
3869 definitely older than the timestamp, but all the files which are newer
3870 than the old value of the timestamp are compared against the current
3871 updated timestamp.
3873 This is indeed faster in general, but the speed difference will depend
3874 on how many updated files there are.
3876 @subsection Using -printf and sort to compare timestamps
3878 It is possible to use the @samp{-printf} action to abandon the use of
3879 @code{test} entirely:
3881 @smallexample
3882 newest=$(find subdir -newer timestamp -printf "%A@:%p\n" | 
3883            sort -n | 
3884            tail -1 | 
3885            cut -d: -f2- ) 
3886 touch -r "$@{newest:-timestamp@}" timestamp
3887 @end smallexample
3889 The command above works by generating a list of the timestamps and
3890 names of all the files which are newer than the timestamp.  The
3891 @code{sort}, @code{tail} and @code{cut} comands simply pull out the
3892 name of the file with the largest timestamp value (that is, the latest
3893 file).  The @code{touch} command is then used to update the timestamp,
3895 The @code{"$@{newest:-timestamp@}"} expression simply expands to the
3896 value of @code{$newest} if that variable is set, but to
3897 @file{timestamp} otherwise.  This ensures that an argument is always
3898 given to the @samp{-r} option of the @code{touch} command.
3900 This approach seems quite efficient, but unfortunately it has a bug.
3901 Many operating systems now keep file modification time information at
3902 a granularity which is finer than one second.  Unfortunately the
3903 @samp{%A@@} format for @samp{-printf} only prints a whole-number value
3904 currently; that is, these values are at a one-second granularity.
3905 This means that in our example above, @samp{$newest} wil be the name
3906 of a file which is no more than one second older than the newest file,
3907 but may indeed be older.
3909 It would be possible to solve this problem with some kind of loop:
3911 @smallexample
3912 while true; do
3913         newest=$(find subdir -newer timestamp -printf "%A@@:%p\n" | 
3914            sort -n | 
3915            tail -1 | 
3916            cut -d: -f2- ) 
3917         if test -z "$newest" ; then
3918                 break
3919         else
3920                 touch -r "$newest" timestamp
3921         fi
3922 done
3923 @end smallexample
3925 A better fix for this problem would be to allow the @samp{%A@@} format
3926 to produce a result having a fractional part, too.  While this is
3927 planned for GNU @code{find}, it hasn't been done yet.
3929 @subsection Coping with sub-second timestamp resolution
3931 Another tool which often works with timestamps is @code{make}.  We can
3932 use @code{find} to generate a @file{Makefile} file on the fly and then
3933 use @code{make} to update the timestamps:
3935 @smallexample
3936 makefile=$(mktemp)
3937 find subdir \
3938         \( \! -xtype l \) \
3939         -newer timestamp \
3940         -printf "timestamp:: %p\n\ttouch -r %p timestamp\n\n" > "$makefile"
3941 make -f "$makefile"
3942 rm   -f "$makefile"
3943 @end smallexample
3945 Unfortunately although the solution above is quite elegant, it fails
3946 to cope with white space within file names, and adjusting it to do so
3947 would require a rather complex shell script.
3950 @subsection Coping with odd filenames too
3952 We can fix both of these problems (looping and problems with white
3953 space), and do things more efficiently too.  The following command
3954 works with newlines and doesn't need to sort the list of filenames.
3956 @smallexample
3957 find subdir -newer timestamp -printf "%A@@:%p\0" | 
3958    perl -0 newest.pl |
3959    xargs --no-run-if-empty --null -i \
3960       find @{@} -maxdepth 0 -newer timestamp -exec touch -r @{@} timestamp \;
3961 @end smallexample
3963 The first @code{find} command generates a list of files which are
3964 newer than the original timestamp file, and prints a list of them with
3965 their timestamps.  The @file{newest.pl} script simply filters out all
3966 the filenames which have timestamps which are older than whatever the
3967 newest file is:-
3969 @smallexample
3970 @verbatim
3971 #! /usr/bin/perl -0
3972 my @newest = ();
3973 my $latest_stamp = undef;
3974 while (<>) {
3975     my ($stamp, $name) = split(/:/);
3976     if (!defined($latest_stamp) || ($tstamp > $latest_stamp)) {
3977         $latest_stamp = $stamp;
3978         @newest = ();
3979     }
3980     if ($tstamp >= $latest_stamp) {
3981         push @newest, $name;
3982     }
3984 print join("\0", @newest);
3985 @end verbatim
3986 @end smallexample
3988 This prints a list of zero or more files, all of which are newer than
3989 the original timestamp file, and which have the same timestamp as each
3990 other, to the nearest second.  The second @code{find} command takes
3991 each resulting file one at a time, and if that is newer than the
3992 timestamp file, the timestamp is updated.
3994 @node Security Considerations, Error Messages, Worked Examples, Top
3995 @chapter Security Considerations
3997 Security considerations are important if you are using @code{find} or
3998 @code{xargs} to search for or process files that don't belong to you
3999 or which other people have control.  Security considerations
4000 relating to @code{locate} may also apply if you have files which you
4001 do not want others to see.
4003 The most severe forms of security problems affecting
4004 @code{find} and related programs are when third parties bring
4005 about a situation allowing them to do something
4006 they would normally not be able to accomplish.  This is called @emph{privilege
4007 elevation}.  This might include deleting files they would not normally
4008 be able to delete.  It is common for the operating system to periodically
4009 invoke @code{find} for self-maintenance purposes.  These invocations of
4010 @code{find} are particularly problematic from a security point of view
4011 as these are often invoked by the superuser and search the entire
4012 filesystem hierarchy.  Generally, the severity of any associated problem depends
4013 on what the system is going to do with the files found by @code{find}.
4015 @menu
4016 * Levels of Risk::      What is your level of exposure to security problems?
4017 * Security Considerations for find::  Security problems with find
4018 * Security Considerations for xargs:: Security problems with xargs
4019 * Security Considerations for locate:: Security problems with locate
4020 * Security Summary:: That was all very complex, what does it boil down to?
4021 @end menu
4024 @node Levels of Risk
4025 @section Levels of Risk
4027 There are some security risks inherent in the use of @code{find},
4028 @code{xargs} and (to a lesser extent) @code{locate}.  The severity of
4029 these risks depends on what sort of system you are using:
4031 @table @strong
4032 @item High risk
4033 Multi-user systems where you do not control (or trust) the other
4034 users, and on which you execute @code{find}, including areas where
4035 those other users can manipulate the filesystem (for example beneath
4036 @file{/home} or @file{/tmp}).
4038 @item Medium Risk
4039 Systems where the actions of other users can create file names chosen
4040 by them, but to which they don't have access while @code{find} is
4041 being run.  This access might include leaving programs running (shell
4042 background jobs, @code{at} or @code{cron} tasks, for example).  On
4043 these sorts of systems, carefully written commands (avoiding use of
4044 @samp{-print} for example) should not expose you to a high degree of
4045 risk.  Most systems fall into this category.
4047 @item Low Risk
4048 Systems to which untrusted parties do not have access, cannot create
4049 file names of their own choice (even remotely) and which contain no
4050 security flaws which might enable an untrusted third party to gain
4051 access.  Most systems do not fall into this category because there are
4052 many ways in which external parties can affect the names of files that
4053 are created on your system.  The system on which I am writing this for
4054 example automatically downloads software updates from the Internet;
4055 the names of the files in which these updates exist are chosen by
4056 third parties@footnote{Of course, I trust these parties to a large
4057 extent anyway, because I install software provided by them; I choose
4058 to trust them in this way, and that's a deliberate choice}.
4059 @end table
4061 In the discussion above, ``risk'' denotes the likelihood that someone
4062 can cause @code{find}, @code{xargs}, @code{locate} or some other
4063 program which is controlled by them to do something you did not
4064 intend.  The levels of risk suggested do not take any account of the
4065 consequences of this sort of event.  That is, if you operate a ``low
4066 risk'' type system, but the consequences of a security problem are
4067 disastrous, then you should still give serious thought to all the
4068 possible security problems, many of which of course will not be
4069 discussed here -- this section of the manual is intended to be
4070 informative but not comprehensive or exhaustive.
4072 If you are responsible for the operation of a system where the
4073 consequences of a security problem could be very important, you should
4074 do two things:-
4076 @enumerate
4077 @item Define a security policy which defines who is allowed to do what
4078 on your system.
4079 @item Seek competent advice on how to enforce your policy, detect
4080 breaches of that policy, and take account of any potential problems
4081 that might fall outside the scope of your policy.
4082 @end enumerate
4085 @node Security Considerations for find
4086 @section Security Considerations for @code{find}
4089 Some of the actions @code{find} might take have a direct effect;
4090 these include @code{-exec} and @code{-delete}.  However, it is also
4091 common to use @code{-print} explicitly or implicitly, and so if
4092 @code{find} produces the wrong list of file names, that can also be a
4093 security problem; consider the case for example where @code{find} is
4094 producing a list of files to be deleted.
4096 We normally assume that the @code{find} command line expresses the
4097 file selection criteria and actions that the user had in mind -- that
4098 is, the command line is ``trusted'' data.
4100 From a security analysis point of view, the output of @code{find}
4101 should be correct; that is, the output should contain only the names
4102 of those files which meet the user's criteria specified on the command
4103 line.  This applies for the @code{-exec} and @code{-delete} actions;
4104 one can consider these to be part of the output.
4106 On the other hand, the contents of the filesystem can be manipulated
4107 by other people, and hence we regard this as ``untrusted'' data.  This
4108 implies that the @code{find} command line is a filter which converts
4109 the untrusted contents of the filesystem into a correct list of output
4110 files.
4112 The filesystem will in general change while @code{find} is searching
4113 it; in fact, most of the potential security problems with @code{find}
4114 relate to this issue in some way.
4116 @dfn{Race conditions} are a general class of security problem where the
4117 relative ordering of actions taken by @code{find} (for example) and
4118 something else are critically important in getting the correct and expected result@footnote{This is more or less the
4119 definition of the term ``race condition''} .
4121 For @code{find}, an attacker might move or rename files or directories in
4122 the hope that an action might be taken against a file which was not
4123 normally intended to be affected.  Alternatively, this sort of attack
4124 might be intended to persuade @code{find} to search part of the
4125 filesystem which would not normally be included in the search
4126 (defeating the @code{-prune} action for example).
4128 @menu
4129 * Changing the Current Working Directory::
4130 * Race Conditions with -exec::
4131 * Race Conditions with -print and -print0::
4132 @end menu
4135 @node Changing the Current Working Directory
4136 @subsection Changing the Current Working Directory
4138 As @code{find} searches the filesystem, it finds subdirectories and
4139 then searches within them by changing its working directory.  First,
4140 @code{find} reaches and recognizes a subdirectory.  It then decides if that
4141 subdirectory meets the criteria for being searched; that is, any
4142 @samp{-xdev} or @samp{-prune} expressions are taken into account.  The
4143 @code{find} program will then change working directory and proceed to
4144 search the directory.
4146 A race condition attack might take the form that once the checks
4147 relevant to @samp{-xdev} and @samp{-prune} have been done, an attacker
4148 might rename the directory that was being considered, and put in its
4149 place a symbolic link that actually points somewhere else.
4151 The idea behind this attack is to fool @code{find} into going into the
4152 wrong directory.  This would leave @code{find} with a working
4153 directory chosen by an attacker, bypassing any protection apparently
4154 provided by @samp{-xdev} and @samp{-prune}, and any protection
4155 provided by being able to @emph{not} list particular directories on
4156 the @code{find} command line.  This form of attack is particularly
4157 problematic if the attacker can predict when the @code{find} command
4158 will be run, as is the case with @code{cron} tasks for example.
4160 GNU @code{find} has specific safeguards to prevent this general class
4161 of problem.  The exact form of these safeguards depends on the
4162 properties of your system.
4164 @menu
4165 * O_NOFOLLOW::                     Safely changing directory using fchdir().
4166 * Systems without O_NOFOLLOW::     Checking for symbolic links after chdir().
4167 @end menu
4169 @node O_NOFOLLOW
4170 @subsubsection O_NOFOLLOW
4172 If your system supports the O_NOFOLLOW flag @footnote{GNU/Linux
4173 (kernel version 2.1.126 and later) and FreeBSD (3.0-CURRENT and later)
4174 support this} to the @code{open(2)} system call, @code{find} uses it
4175 when safely changing directory.  The target directory is first opened
4176 and then @code{find} changes working directory with the
4177 @code{fchdir()} system call.  This ensures that symbolic links are not
4178 followed, preventing the sort of race condition attack in which use
4179 is made of symbolic links.
4181 If for any reason this approach does not work, @code{find} will fall
4182 back on the method which is normally used if O_NOFOLLOW is not
4183 supported.
4185 You can tell if your system supports O_NOFOLLOW by running
4187 @example
4188 find --version
4189 @end example
4191 This will tell you the version number and which features are enabled.
4192 For example, if I run this on my system now, this gives:
4193 @example
4194 GNU find version 4.2.18-CVS
4195 Features enabled: D_TYPE O_NOFOLLOW(enabled)
4196 @end example
4198 Here, you can see that I am running a version of @code{find} which was
4199 built from the development (CVS) code prior to the release of
4200 findutils-4.2.18, and that the D_TYPE and O_NOFOLLOW features are
4201 present.  O_NOFOLLOW is qualified with ``enabled''.  This simply means
4202 that the current system seems to support O_NOFOLLOW.  This check is
4203 needed because it is possible to build @code{find} on a system that
4204 defines O_NOFOLLOW and then run it on a system that ignores the
4205 O_NOFOLLOW flag.  We try to detect such cases at startup by checking
4206 the operating system and version number; when this happens you will
4207 see ``O_NOFOLLOW(disabled)'' instead.
4209 @node Systems without O_NOFOLLOW
4210 @subsubsection Systems without O_NOFOLLOW
4212 The strategy for preventing this type of problem on systems that lack
4213 support for the O_NOFOLLOW flag is more complex.  Each time
4214 @code{find} changes directory, it examines the directory it is about
4215 to move to, issues the @code{chdir()} system call, and then checks
4216 that it has ended up in the subdirectory it expected.  If all is as
4217 expected, processing continues as normal.  However, there are two main
4218 reasons why the directory might change: the use of an automounter and
4219 the someone removing the old directory and replacing it with something
4220 else while @code{find} is trying to descend into it.
4222 Where a filesystem ``automounter'' is in use it can be the case that
4223 the use of the @code{chdir()} system call can itself cause a new
4224 filesystem to be mounted at that point.  On systems that do not
4225 support O_NOFOLLOW, this will cause @code{find}'s security check to
4226 fail.
4228 However, this does not normally represent a security problem, since
4229 the automounter configuration is normally set up by the system
4230 administrator.  Therefore, if the @code{chdir()} sanity check fails,
4231 @code{find} will make one more attempt.  If that succeeds, execution
4232 carries on as normal.  This is the usual case for automounters.
4234 Where an attacker is trying to exploit a race condition, the problem
4235 may not have gone away on the second attampt.  If this is the case,
4236 @code{find} will issue a warning message and then ignore that
4237 subdirectory.  When this happens, actions such as @samp{-exec} or
4238 @samp{-print} may already have taken place for the problematic
4239 subdirectory.  This is because @code{find} applies tests and actions
4240 to directories before searching within them (unless @samp{-depth} was
4241 specified).
4243 Because of the nature of the directory-change operation and security
4244 check, in the worst case the only things that @code{find} would have
4245 done with the directory are to move into it and back out to the
4246 original parent.  No operations would have been performed within that
4247 directory.
4249 @node Race Conditions with -exec
4250 @subsection Race Conditions with -exec
4252 The @samp{-exec} action causes another program to be run.  It passes
4253 to the program the name of the file which is being considered at the
4254 time.  The invoked program will typically then perform some action
4255 on that file.  Once again, there is a race condition which can be
4256 exploited here.  We shall take as a specific example the command
4258 @example
4259 find /tmp -path /tmp/umsp/passwd -exec /bin/rm
4260 @end example
4262 In this simple example, we are identifying just one file to be deleted
4263 and invoking @code{/bin/rm} to delete it.  A problem exists because
4264 there is a time gap between the point where @code{find} decides that
4265 it needs to process the @samp{-exec} action and the point where the
4266 @code{/bin/rm} command actually issues the @code{unlink()} system
4267 call to delete the file from the filesystem.  Within this time period, an attacker can rename the
4268 @file{/tmp/umsp} directory, replacing it with a symbolic link to
4269 @file{/etc}.  There is no way for @code{/bin/rm} to determine that it
4270 is working on the same file that @code{find} had in mind.  Once the
4271 symbolic link is in place, the attacker has persuaded @code{find} to
4272 cause the deletion of the @file{/etc/passwd} file, which is not the
4273 effect intended by the command which was actually invoked.
4275 One possible defence against this type of attack is to modify the
4276 behaviour of @samp{-exec} so that the @code{/bin/rm} command is run
4277 with the argument @file{./passwd} and a suitable choice of working
4278 directory.  This would allow the normal sanity check that @code{find}
4279 performs to protect against this form of attack too.  Unfortunately,
4280 this strategy cannot be used as the POSIX standard specifies that the
4281 current working directory for commands invoked with @samp{-exec} must
4282 be the same as the current working directory from which @code{find}
4283 was invoked.  This means that the @samp{-exec} action is inherently
4284 insecure and can't be fixed.
4286 GNU @code{find} implements a more secure variant of the @samp{-exec}
4287 action, @samp{-execdir}.  The @samp{-execdir} action
4288 ensures that it is not necessary to dereference subdirectories to
4289 process target files.  The current directory used to invoke programs
4290 is the same as the directory in which the file to be processed exists
4291 (@file{/tmp/umsp} in our example, and only the basename of the file to
4292 be processed is passed to the invoked command, with a @samp{./}
4293 prepended (giving @file{./passwd} in our example).
4295 The @samp{-execdir} action refuses to do anything if the current
4296 directory is included in the @var{$PATH} environment variable.  This
4297 is necessary because @samp{-execdir} runs programs in the same
4298 directory in which it finds files -- in general, such a directory
4299 might be writable by untrusted users.  For similar reasons,
4300 @samp{-execdir} does not allow @samp{@{@}} to appear in the name of
4301 the command to be run.
4303 @node Race Conditions with -print and -print0
4304 @subsection Race Conditions with -print and -print0
4306 The @samp{-print} and @samp{-print0} actions can be used to produce a
4307 list of files matching some criteria, which can then be used with some
4308 other command, perhaps with @code{xargs}.  Unfortunately, this means
4309 that there is an unavoidable time gap between @code{find} deciding
4310 that one or more files meet its criteria and the relevant command
4311 being executed.  For this reason, the @samp{-print} and @samp{-print0}
4312 actions are just as insecure as @samp{-exec}.
4314 In fact, since the construction
4316 @example
4317 find @dots{}  -print | xargs @enddots{}
4318 @end example
4320 does not cope correctly with newlines or other ``white space'' in
4321 file names, and copes poorly with file names containing quotes, the
4322 @samp{-print} action is less secure even than @samp{-print0}.
4325 @comment  node-name,  next,  previous,  up
4326 @comment @node Security Considerations for xargs
4327 @node Security Considerations for xargs
4328 @section Security Considerations for @code{xargs}
4330 The description of the race conditions affecting the @samp{-print}
4331 action of @code{find} shows that @code{xargs} cannot be secure if it
4332 is possible for an attacker to modify a filesystem after @code{find}
4333 has started but before @code{xargs} has completed all its actions.
4335 However, there are other security issues that exist even if it is not
4336 possible for an attacker to have access to the filesystem in real
4337 time.  Firstly, if it is possible for an attacker to create files with
4338 names of their choice on the filesystem, then @code{xargs} is
4339 insecure unless the @samp{-0} option is used.  If a file with the name
4340 @file{/home/someuser/foo/bar\n/etc/passwd} exists (assume that
4341 @samp{\n} stands for a newline character), then @code{find @dots{} -print}
4342 can be persuaded to print three separate lines:
4344 @example
4345 /home/someuser/foo/bar
4347 /etc/passwd
4348 @end example
4350 If it finds a blank line in the input, @code{xargs} will ignore it.
4351 Therefore, if some action is to be taken on the basis of this list of
4352 files, the @file{/etc/passwd} file would be included even if this was
4353 not the intent of the person running find.  There are circumstances in
4354 which an attacker can use this to their advantage.  The same
4355 consideration applies to file names containing ordinary spaces rather
4356 than newlines, except that of course the list of file names will no
4357 longer contain an ``extra'' newline.
4359 This problem is an unavoidable consequence of the default behaviour of
4360 the @code{xargs} command, which is specified by the POSIX standard.
4361 The only ways to avoid this problem are either to avoid all use of
4362 @code{xargs} in favour for example of @samp{find -exec} or (where
4363 available) @samp{find -execdir}, or to use the @samp{-0} option, which
4364 ensures that @code{xargs} considers file names to be separated by
4365 ASCII NUL characters rather than whitespace.  However, useful as this
4366 option is, the POSIX standard does not make it mandatory.
4368 @comment  node-name,  next,  previous,  up
4369 @node Security Considerations for locate
4370 @section Security Considerations for @code{locate}
4372 It is fairly unusual for the output of @code{locate} to be fed into
4373 another command.  However, if this were to be done, this would raise
4374 the same set of security issues as the use of @samp{find @dots{} -print}.
4375 Although the problems relating to whitespace in file names can be
4376 resolved by using @code{locate}'s @samp{-0} option, this still leaves
4377 the race condition problems associated with @samp{find @dots{} -print0}.
4378 There is no way to avoid these problems in the case of @code{locate}.
4380 @node Security Summary
4381 @section Summary
4383 Where untrusted parties can create files on the system, or affect the
4384 names of files that are created, all uses for @code{find},
4385 @code{locate} and @code{xargs} have known security problems except the
4386 following:
4388 @table @asis
4389 @item Informational use only
4390 Uses where the programs are used to prepare lists of file names upon
4391 which no further action will ever be taken.
4393 @item @samp{-delete}
4394 Use of the @samp{-delete} action with @code{find} to delete files
4395 which meet specified criteria
4397 @item @samp{-execdir}
4398 Use of the @samp{-execdir} action with @code{find} where the
4399 @env{PATH} environment variable contains directories which contain
4400 only trusted programs.
4401 @end table
4403 @comment  node-name,  next,  previous,  up
4404 @node Error Messages, Primary Index, Security Considerations, Top
4405 @chapter Error Messages
4407 This section describes some of the error messages sometimes made by
4408 @code{find}, @code{xargs}, or @code{locate}, explains them and in some
4409 cases provides advice as to what you should do about this.
4411 This manual is written in English.  The GNU findutils software
4412 features translations of error messages for many languages.  For this
4413 reason the error messages produced by
4414 the programs are made to be as self-explanatory as possible.  This approach avoids leaving people to
4415 figure out which test an English-language error message
4416 corresponds to. Error messages which are self-explanatory
4417 will not normally be mentioned in this document.  For
4418 those messages mentioned in this document, only the
4419 English-language version of the message will be listed.
4421 @menu
4422 * Error Messages From find::
4423 * Error Messages From xargs::
4424 * Error Messages From locate::
4425 * Error Messages From updatedb::
4426 @end menu
4428 @node Error Messages From find, Error Messages From xargs, , Error Messages
4429 @section Error Messages From @code{find}
4431 @table @samp
4432 @item invalid predicate `-foo'
4433 This means that the @code{find} command line included something that
4434 started with a dash or other special character.  The @code{find}
4435 program tried to interpret this as a test, action or option, but
4436 didn't recognise it.  If it was intended to be a test, check what was
4437 specified against the documentation.  If, on the other hand, the
4438 string is the name of a file which has been expanded from a wildcard
4439 (for example because you have a @samp{*} on the command line),
4440 consider using @samp{./*} or just @samp{.} instead.
4442 @item unexpected extra predicate
4443 This usually happens if you have an extra bracket on the command line
4444 (for example @samp{find . -print \)}).
4446 @item Warning: filesystem /path/foo has recently been mounted
4447 @itemx Warning: filesystem /path/foo has recently been unmounted
4448 These messages might appear when @code{find} moves into a directory
4449 and finds that the device number and inode are different to what it
4450 expected them to be.  If the directory @code{find} has moved into is
4451 on an network filesystem (NFS), it will not issue this message, because
4452 @code{automount} frequently mounts new filesystems on directories as
4453 you move into them (that is how it knows you want to use the
4454 filesystem).  So, if you do see this message, be wary ---
4455 @code{automount} may not have been responsible.  Consider the
4456 possibility that someone else is manipulating the filesystem while
4457 @code{find} is running.  Some people might do this in order to mislead
4458 @code{find} or persuade it to look at one set of files when it thought
4459 it was looking at another set.
4461 @item /path/foo changed during execution of find (old device number 12345, new device number 6789, filesystem type is <whatever>) [ref XXX]
4462 This message is issued when @code{find} moves into a directory and ends up
4463 somewhere it didn't expect to be.  This happens in one of two
4464 circumstances.  Firstly, this happens when @code{automount} intervenes
4465 on a system where @code{find} doesn't know how to determine what
4466 the current set of mounted filesystems is.
4468 Secondly, this can happen when the device number of a directory
4469 appears to change during a change of current directory, but
4470 @code{find} is moving up the filesystem hierarchy rather than down into it.
4471 In order to prevent @code{find} wandering off into some unexpected
4472 part of the filesystem, we stop it at this point.
4474 @item Don't know how to use getmntent() to read `/etc/mtab'.  This is a bug.
4475 This message is issued when a problem similar to the above occurs on a
4476 system where @code{find} doesn't know how to figure out the current
4477 list of mount points.  Ask for help on @email{bug-findutils@@gnu.org}.
4479 @item /path/foo/bar changed during execution of find (old inode number 12345, new inode number 67893, filesystem type is <whatever>) [ref XXX]"),
4480 This message is issued when @code{find} moves into a directory and
4481 discovers that the inode number of that directory
4482 is different from the inode number that it obtained when it examined the
4483 directory previously.  This usually means that while
4484 @code{find} was deep in a directory hierarchy doing a
4485 time consuming operation, somebody has moved one of the parent directories to
4486 another location in the same filesystem.  This may or may not have been done
4487 maliciously.  In any case, @code{find} stops at this point
4488 to avoid traversing parts of the filesystem that it wasn't
4489 intended.  You can use @code{ls -li} or @code{find /path -inum
4490 12345 -o -inum 67893} to find out more about what has happened.
4492 @item sanity check of the fnmatch() library function failed.
4493 Please submit a bug report.  You may well be asked questions about
4494 your system, and if you compiled the @code{findutils} code yourself,
4495 you should keep your copy of the build tree around.  The likely
4496 explanation is that your system has a buggy implementation of
4497 @code{fnmatch} that looks enough like the GNU version to fool
4498 @code{configure}, but which doesn't work properly.
4500 @item cannot fork
4501 This normally happens if you use the @code{-exec} action or
4502 something similar (@code{-ok} and so forth) but the system has run out
4503 of free process slots.  This is either because the system is very busy
4504 and the system has reached its maximum process limit, or because you
4505 have a resource limit in place and you've reached it.  Check the
4506 system for runaway processes (with @code{ps}, if possible).  Some process
4507 slots are normally reserved for use by @samp{root}.
4509 @item some-program terminated by signal 99
4510 Some program which was launched with @code{-exec} or similar was killed
4511 with a fatal signal.  This is just an advisory message.
4512 @end table
4515 @node Error Messages From xargs, Error Messages From locate, Error Messages From find, Error Messages
4516 @section Error Messages From xargs
4518 @table @samp
4519 @item environment is too large for exec
4520 This message means that you have so many environment variables set (or
4521 such large values for them) that there is no room within the
4522 system-imposed limits on program command line argument length to
4523 invoke any program.  This is an unlikely situation and is more likely
4524 result of an attempt to test the limits of @code{xargs}, or break it.
4525 Please try unsetting some environment variables, or exiting the
4526 current shell.  You can also use @samp{xargs --show-limits} to
4527 understand the relevant sizes.
4529 @item can not fit single argument within argument list size limit
4530 You are using the @samp{-I} option and @code{xargs} doesn't have
4531 enough space to build a command line because it has read a really
4532 large item and it doesn't fit.  You can probably work around this
4533 problem with the @samp{-s} option, but the default size is pretty
4534 large.  This is a rare situation and is more likely an attempt to test
4535 the limits of @code{xargs}, or break it.  Otherwise, you will need to
4536 try to shorten the problematic argument or not use @code{xargs}.
4538 @item cannot fork
4539 See the description of the similar message for @code{find}.
4541 @item <program>: exited with status 255; aborting
4542 When a command run by @code{xargs} exits with status 255, @code{xargs}
4543 is supposed to stop.  If this is not what you intended, wrap the
4544 program you are trying to invoke in a shell script which doesn't
4545 return status 255.
4547 @item <program>: terminated by signal 99
4548 See the description of the similar message for @code{find}.
4549 @end table
4551 @node Error Messages From locate, Error Messages From updatedb, Error Messages From xargs, Error Messages
4552 @section Error Messages From @code{locate}
4554 @table @samp
4555 @item warning: database `/usr/local/var/locatedb' is more than 8 days old
4556 The @code{locate} program relies on a database which is periodically
4557 built by the @code{updatedb} program.  That hasn't happened in a long
4558 time.  To fix this problem, run @code{updatedb} manually.  This can
4559 often happen on systems that are generally not left on, so the
4560 periodic ``cron'' task which normally does this doesn't get a chance
4561 to run.
4563 @item locate database `/usr/local/var/locatedb' is corrupt or invalid
4564 This should not happen.  Re-run @code{updatedb}.  If that works, but
4565 @code{locate} still produces this error, run @code{locate --version}
4566 and @code{updatedb --version}.  These should produce the same output.
4567 If not, you are using a mixed toolset; check your @samp{$PATH}
4568 environment variable and your shell aliases (if you have any).  If
4569 both programs claim to be GNU versions, this is a bug; all versions of
4570 these programs should interoperate without problem.  Ask for help on
4571 @email{bug-findutils@@gnu.org}.
4572 @end table
4575 @node Error Messages From updatedb, , Error Messages From locate, Error Messages
4576 @section Error Messages From updatedb
4578 The @code{updatedb} program (and the programs it invokes) do issue
4579 error messages, but none seem to be candidates for guidance.  If
4580 you are having a problem understanding one of these, ask for help on
4581 @email{bug-findutils@@gnu.org}.
4584 @node Primary Index, , Error Messages, Top
4585 @unnumbered @code{find} Primary Index
4587 This is a list of all of the primaries (tests, actions, and options)
4588 that make up @code{find} expressions for selecting files.  @xref{find
4589 Expressions}, for more information on expressions.
4591 @printindex fn
4593 @bye
4595 @comment texi related words used by Emacs' spell checker ispell.el
4597 @comment LocalWords: texinfo setfilename settitle setchapternewpage
4598 @comment LocalWords: iftex finalout ifinfo DIR titlepage vskip pt
4599 @comment LocalWords: filll dir samp dfn noindent xref pxref
4600 @comment LocalWords: var deffn texi deffnx itemx emph asis
4601 @comment LocalWords: findex smallexample subsubsection cindex
4602 @comment LocalWords: dircategory direntry itemize
4604 @comment other words used by Emacs' spell checker ispell.el
4605 @comment LocalWords: README fred updatedb xargs Plett Rendell akefile
4606 @comment LocalWords: args grep Filesystems fo foo fOo wildcards iname
4607 @comment LocalWords: ipath regex iregex expr fubar regexps
4608 @comment LocalWords: metacharacters macs sr sc inode lname ilname
4609 @comment LocalWords: sysdep noleaf ls inum xdev filesystems usr atime
4610 @comment LocalWords: ctime mtime amin cmin mmin al daystart Sladkey rm
4611 @comment LocalWords: anewer cnewer bckw rf xtype uname gname uid gid
4612 @comment LocalWords: nouser nogroup chown chgrp perm ch maxdepth
4613 @comment LocalWords: mindepth cpio src CD AFS statted stat fstype ufs
4614 @comment LocalWords: nfs tmp mfs printf fprint dils rw djm Nov lwall
4615 @comment LocalWords: POSIXLY fls fprintf strftime locale's EDT GMT AP
4616 @comment LocalWords: EST diff perl backquotes sprintf Falstad Oct cron
4617 @comment LocalWords: eg vmunix mkdir afs allexec allwrite ARG bigram
4618 @comment LocalWords: bigrams cd chmod comp crc CVS dbfile dum eof
4619 @comment LocalWords: fileserver filesystem fn frcode Ghazi Hnewc iXX
4620 @comment LocalWords: joeuser Kaveh localpaths localuser LOGNAME
4621 @comment LocalWords: Meyering mv netpaths netuser nonblank nonblanks
4622 @comment LocalWords: ois ok Pinard printindex proc procs prunefs
4623 @comment LocalWords: prunepaths pwd RFS rmadillo rmdir rsh sbins str
4624 @comment LocalWords: su Timar ubins ug unstripped vf VM Weitzel
4625 @comment LocalWords: wildcard zlogout basename execdir wholename iwholename
4626 @comment LocalWords: timestamp timestamps Solaris FreeBSD OpenBSD POSIX