Deprecate -path and -ipath in favour of -wholename and -iwholename
[findutils.git] / doc / find.texi
blob285087e55de0b7729a7bd4c142807529ff9e8c37
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 @ifinfo
16 @format
17 START-INFO-DIR-ENTRY
18 * Finding Files: (find).        Listing and operating on files
19                                 that match certain criteria.
20 END-INFO-DIR-ENTRY
21 @end format
23 This file documents the GNU utilities for finding files that match
24 certain criteria and performing various operations on them.
26 Copyright (C) 1994 Free Software Foundation, Inc.
28 Permission is granted to make and distribute verbatim copies of
29 this manual provided the copyright notice and this permission notice
30 are preserved on all copies.
32 @ignore
33 Permission is granted to process this file through TeX and print the
34 results, provided the printed document carries copying permission
35 notice identical to this one except for the removal of this paragraph
36 (this paragraph not being relevant to the printed manual).
38 @end ignore
39 Permission is granted to copy and distribute modified versions of this
40 manual under the conditions for verbatim copying, provided that the entire
41 resulting derived work is distributed under the terms of a permission
42 notice identical to this one.
44 Permission is granted to copy and distribute translations of this manual
45 into another language, under the above conditions for modified versions,
46 except that this permission notice may be stated in a translation approved
47 by the Foundation.
48 @end ifinfo
50 @titlepage
51 @title Finding Files
52 @subtitle Edition @value{EDITION}, for GNU @code{find} version @value{VERSION}
53 @subtitle @value{UPDATED}
54 @author by David MacKenzie
56 @page
57 @vskip 0pt plus 1filll
58 Copyright @copyright{} 1994 Free Software Foundation, Inc.
60 Permission is granted to make and distribute verbatim copies of
61 this manual provided the copyright notice and this permission notice
62 are preserved on all copies.
64 Permission is granted to copy and distribute modified versions of this
65 manual under the conditions for verbatim copying, provided that the entire
66 resulting derived work is distributed under the terms of a permission
67 notice identical to this one.
69 Permission is granted to copy and distribute translations of this manual
70 into another language, under the above conditions for modified versions,
71 except that this permission notice may be stated in a translation approved
72 by the Foundation.
73 @end titlepage
75 @node Top, Introduction, , (dir)
76 @comment  node-name,  next,  previous,  up
78 @ifinfo
79 This file documents the GNU utilities for finding files that match
80 certain criteria and performing various actions on them.
81 This is edition @value{EDITION}, for @code{find} version @value{VERSION}.
82 @end ifinfo
84 @c The master menu, created with texinfo-master-menu, goes here.
86 @menu
87 * Introduction::                Summary of the tasks this manual describes.
88 * Finding Files::               Finding files that match certain criteria.
89 * Actions::                     Doing things to files you have found.
90 * Common Tasks::                Solutions to common real-world problems.
91 * Databases::                   Maintaining file name databases.
92 * File Permissions::            How to control access to files.
93 * Reference::                   Summary of how to invoke the programs.
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, and
101 how to perform various actions on the files that you find.  The
102 principal programs that you use to perform these tasks are @code{find},
103 @code{locate}, and @code{xargs}.  Some of the examples in this manual
104 use capabilities specific to the GNU versions of those programs.
106 GNU @code{find} was originally written by Eric Decker, with enhancements
107 by David MacKenzie, Jay Plett, and Tim Wood.  GNU @code{xargs} was
108 originally written by Mike Rendell, with enhancements by David
109 MacKenzie.  GNU @code{locate} and its associated utilities were
110 originally written by James Woods, with enhancements by David MacKenzie.
111 The idea for @samp{find -print0} and @samp{xargs -0} came from Dan
112 Bernstein.  Many other people have contributed bug fixes, small
113 improvements, and helpful suggestions.  Thanks!
115 Mail suggestions and bug reports for these programs to
116 @code{bug-findutils@@gnu.org}.  Please include the version
117 number, which you can get by running @samp{find --version}.
119 @menu
120 * Scope::
121 * Overview::
122 * find Expressions::
123 @end menu
125 @node Scope
126 @section Scope
128 For brevity, the word @dfn{file} in this manual means a regular file, a
129 directory, a symbolic link, or any other kind of node that has a
130 directory entry.  A directory entry is also called a @dfn{file name}.  A
131 file name may contain some, all, or none of the directories in a path
132 that leads to the file.  These are all examples of what this manual
133 calls ``file names'':
135 @example
136 parser.c
137 README
138 ./budget/may-94.sc
139 fred/.cshrc
140 /usr/local/include/termcap.h
141 @end example
143 A @dfn{directory tree} is a directory and the files it contains, all of
144 its subdirectories and the files they contain, etc.  It can also be a
145 single non-directory file.
147 These programs enable you to find the files in one or more directory
148 trees that:
150 @itemize @bullet
151 @item
152 have names that contain certain text or match a certain pattern;
153 @item
154 are links to certain files;
155 @item
156 were last used during a certain period of time;
157 @item
158 are within a certain size range;
159 @item
160 are of a certain type (regular file, directory, symbolic link, etc.);
161 @item
162 are owned by a certain user or group;
163 @item
164 have certain access permissions;
165 @item
166 contain text that matches a certain pattern;
167 @item
168 are within a certain depth in the directory tree;
169 @item
170 or some combination of the above.
171 @end itemize
173 Once you have found the files you're looking for (or files that are
174 potentially the ones you're looking for), you can do more to them than
175 simply list their names.  You can get any combination of the files'
176 attributes, or process the files in many ways, either individually or in
177 groups of various sizes.  Actions that you might want to perform on the
178 files you have found include, but are not limited to:
180 @itemize @bullet
181 @item
182 view or edit
183 @item
184 store in an archive
185 @item
186 remove or rename
187 @item
188 change access permissions
189 @item
190 classify into groups
191 @end itemize
193 This manual describes how to perform each of those tasks, and more.
195 @node Overview
196 @section Overview
198 The principal programs used for making lists of files that match given
199 criteria and running commands on them are @code{find}, @code{locate},
200 and @code{xargs}.  An additional command, @code{updatedb}, is used by
201 system administrators to create databases for @code{locate} to use.
203 @code{find} searches for files in a directory hierarchy and prints
204 information about the files it found.  It is run like this:
206 @example
207 find @r{[}@var{file}@dots{}@r{]} @r{[}@var{expression}@r{]}
208 @end example
210 @noindent
211 Here is a typical use of @code{find}.  This example prints the names of
212 all files in the directory tree rooted in @file{/usr/src} whose name
213 ends with @samp{.c} and that are larger than 100 Kilobytes.
214 @example
215 find /usr/src -name '*.c' -size +100k -print
216 @end example
218 @code{locate} searches special file name databases for file names that
219 match patterns.  The system administrator runs the @code{updatedb}
220 program to create the databases.  @code{locate} is run like this:
222 @example
223 locate @r{[}@var{option}@dots{}@r{]} @var{pattern}@dots{}
224 @end example
226 @noindent
227 This example prints the names of all files in the default file name
228 database whose name ends with @samp{Makefile} or @samp{makefile}.  Which
229 file names are stored in the database depends on how the system
230 administrator ran @code{updatedb}.
231 @example
232 locate '*[Mm]akefile'
233 @end example
235 The name @code{xargs}, pronounced EX-args, means ``combine arguments.''
236 @code{xargs} builds and executes command lines by gathering together
237 arguments it reads on the standard input.  Most often, these arguments
238 are lists of file names generated by @code{find}.  @code{xargs} is run
239 like this:
241 @example
242 xargs @r{[}@var{option}@dots{}@r{]} @r{[}@var{command} @r{[}@var{initial-arguments}@r{]}@r{]}
243 @end example
245 @noindent
246 The following command searches the files listed in the file
247 @file{file-list} and prints all of the lines in them that contain the
248 word @samp{typedef}.
249 @example
250 xargs grep typedef < file-list
251 @end example
253 @node find Expressions
254 @section @code{find} Expressions
256 The expression that @code{find} uses to select files consists of one or
257 more @dfn{primaries}, each of which is a separate command line argument
258 to @code{find}.  @code{find} evaluates the expression each time it
259 processes a file.  An expression can contain any of the following types
260 of primaries:
262 @table @dfn
263 @item options
264 affect overall operation rather than the processing of a specific file;
265 @item tests
266 return a true or false value, depending on the file's attributes;
267 @item actions
268 have side effects and return a true or false value; and
269 @item operators
270 connect the other arguments and affect when and whether they are
271 evaluated.
272 @end table
274 You can omit the operator between two primaries; it defaults to
275 @samp{-and}.  @xref{Combining Primaries With Operators}, for ways to
276 connect primaries into more complex expressions.  If the expression
277 contains no actions other than @samp{-prune}, @samp{-print} is performed
278 on all files for which the entire expression is true (@pxref{Print File
279 Name}).
281 Options take effect immediately, rather than being evaluated for each
282 file when their place in the expression is reached.  Therefore, for
283 clarity, it is best to place them at the beginning of the expression.
285 Many of the primaries take arguments, which immediately follow them in
286 the next command line argument to @code{find}.  Some arguments are file
287 names, patterns, or other strings; others are numbers.  Numeric
288 arguments can be specified as
290 @table @code
291 @item +@var{n}
292 for greater than @var{n},
293 @item -@var{n}
294 for less than @var{n},
295 @item @var{n}
296 for exactly @var{n}.
297 @end table
299 @node Finding Files, Actions, Introduction, Top
300 @chapter Finding Files
302 By default, @code{find} prints to the standard output the names of the
303 files that match the given criteria.  @xref{Actions}, for how to get more
304 information about the matching files.
306 @menu
307 * Name::
308 * Links::
309 * Time::
310 * Size::
311 * Type::
312 * Owner::
313 * Permissions::
314 * Contents::
315 * Directories::
316 * Filesystems::
317 * Combining Primaries With Operators::
318 @end menu
320 @node Name
321 @section Name
323 Here are ways to search for files whose name matches a certain pattern.
324 @xref{Shell Pattern Matching}, for a description of the @var{pattern}
325 arguments to these tests.
327 Each of these tests has a case-sensitive version and a case-insensitive
328 version, whose name begins with @samp{i}.  In a case-insensitive
329 comparison, the patterns @samp{fo*} and @samp{F??} match the file names
330 @file{Foo}, @samp{FOO}, @samp{foo}, @samp{fOo}, etc.
332 @menu
333 * Base Name Patterns::
334 * Full Name Patterns::
335 * Fast Full Name Search::
336 * Shell Pattern Matching::      Wildcards used by these programs.
337 @end menu
339 @node Base Name Patterns
340 @subsection Base Name Patterns
342 @deffn Test -name pattern
343 @deffnx Test -iname pattern
344 True if the base of the file name (the path with the leading directories
345 removed) matches shell pattern @var{pattern}.  For @samp{-iname}, the
346 match is case-insensitive.  To ignore a whole directory tree, use
347 @samp{-prune} (@pxref{Directories}).  As an example, to find Texinfo
348 source files in @file{/usr/local/doc}:
350 @example
351 find /usr/local/doc -name '*.texi'
352 @end example
353 @end deffn
355 @node Full Name Patterns
356 @subsection Full Name Patterns
358 @deffn Test -wholename pattern
359 @deffnx Test -iwholename pattern
360 True if the entire file name, starting with the command line argument
361 under which the file was found, matches shell pattern @var{pattern}.
362 For @samp{-iwholename}, the match is case-insensitive.  To ignore a whole
363 directory tree, use @samp{-prune} rather than checking every file in the
364 tree (@pxref{Directories}).
365 @end deffn
367 @deffn Test -path pattern
368 @deffnx Test -ipath pattern
369 These tests are deprecated, but work as for @samp{-wholename} and @samp{-iwholename},
370 respectively.  The @samp{-ipath} test is a GNU extension, but @samp{-path} is also 
371 provided by HP-UX @code{find}.
372 @end deffn
374 @deffn Test -regex expr
375 @deffnx Test -iregex expr
376 True if the entire file name matches regular expression @var{expr}.
377 This is a match on the whole path, not a search.  For example, to match
378 a file named @file{./fubar3}, you can use the regular expression
379 @samp{.*bar.} or @samp{.*b.*3}, but not @samp{b.*r3}.  @xref{Regexps, ,
380 Syntax of Regular Expressions, emacs, The GNU Emacs Manual}, for a
381 description of the syntax of regular expressions.  For @samp{-iregex},
382 the match is case-insensitive.
383 @end deffn
385 @node Fast Full Name Search
386 @subsection Fast Full Name Search
388 To search for files by name without having to actually scan the
389 directories on the disk (which can be slow), you can use the
390 @code{locate} program.  For each shell pattern you give it,
391 @code{locate} searches one or more databases of file names and displays
392 the file names that contain the pattern.  @xref{Shell Pattern Matching},
393 for details about shell patterns.
395 If a pattern is a plain string---it contains no
396 metacharacters---@code{locate} displays all file names in the database
397 that contain that string.  If a pattern contains
398 metacharacters, @code{locate} only displays file names that match the
399 pattern exactly.  As a result, patterns that contain metacharacters
400 should usually begin with a @samp{*}, and will most often end with one
401 as well.  The exceptions are patterns that are intended to explicitly
402 match the beginning or end of a file name.
404 The command
405 @example
406 locate @var{pattern}
407 @end example
409 is almost equivalent to
410 @example
411 find @var{directories} -name @var{pattern}
412 @end example
414 where @var{directories} are the directories for which the file name
415 databases contain information.  The differences are that the
416 @code{locate} information might be out of date, and that @code{locate}
417 handles wildcards in the pattern slightly differently than @code{find}
418 (@pxref{Shell Pattern Matching}).
420 The file name databases contain lists of files that were on the system
421 when the databases were last updated.  The system administrator can
422 choose the file name of the default database, the frequency with which
423 the databases are updated, and the directories for which they contain
424 entries.
426 Here is how to select which file name databases @code{locate} searches.
427 The default is system-dependent.
429 @table @code
430 @item --database=@var{path}
431 @itemx -d @var{path}
432 Instead of searching the default file name database, search the file
433 name databases in @var{path}, which is a colon-separated list of
434 database file names.  You can also use the environment variable
435 @code{LOCATE_PATH} to set the list of database files to search.  The
436 option overrides the environment variable if both are used.
437 @end table
439 @node Shell Pattern Matching
440 @subsection Shell Pattern Matching
442 @code{find} and @code{locate} can compare file names, or parts of file
443 names, to shell patterns.  A @dfn{shell pattern} is a string that may
444 contain the following special characters, which are known as
445 @dfn{wildcards} or @dfn{metacharacters}.
447 You must quote patterns that contain metacharacters to prevent the shell
448 from expanding them itself.  Double and single quotes both work; so does
449 escaping with a backslash.
451 @table @code
452 @item *
453 Matches any zero or more characters.
455 @item ?
456 Matches any one character.
458 @item [@var{string}]
459 Matches exactly one character that is a member of the string
460 @var{string}.  This is called a @dfn{character class}.  As a shorthand,
461 @var{string} may contain ranges, which consist of two characters with a
462 dash between them.  For example, the class @samp{[a-z0-9_]} matches a
463 lowercase letter, a number, or an underscore.  You can negate a class by
464 placing a @samp{!} or @samp{^} immediately after the opening bracket.
465 Thus, @samp{[^A-Z@@]} matches any character except an uppercase letter
466 or an at sign.
468 @item \
469 Removes the special meaning of the character that follows it.  This
470 works even in character classes.
471 @end table
473 In the @code{find} tests that do shell pattern matching (@samp{-name},
474 @samp{-wholename}, etc.), wildcards in the pattern do not match a @samp{.}
475 at the beginning of a file name.  This is not the case for
476 @code{locate}.  Thus, @samp{find -name '*macs'} does not match a file
477 named @file{.emacs}, but @samp{locate '*macs'} does.
479 Slash characters have no special significance in the shell pattern
480 matching that @code{find} and @code{locate} do, unlike in the shell, in
481 which wildcards do not match them.  Therefore, a pattern @samp{foo*bar}
482 can match a file name @samp{foo3/bar}, and a pattern @samp{./sr*sc} can
483 match a file name @samp{./src/misc}.
485 @node Links
486 @section Links
488 There are two ways that files can be linked together.  @dfn{Symbolic
489 links} are a special type of file whose contents are a portion of the
490 name of another file.  @dfn{Hard links} are multiple directory entries
491 for one file; the file names all have the same index node (@dfn{inode})
492 number on the disk.
494 @menu
495 * Symbolic Links::
496 * Hard Links::
497 @end menu
499 @node Symbolic Links
500 @subsection Symbolic Links
502 @deffn Test -lname pattern
503 @deffnx Test -ilname pattern
504 True if the file is a symbolic link whose contents match shell pattern
505 @var{pattern}.  For @samp{-ilname}, the match is case-insensitive.
506 @xref{Shell Pattern Matching}, for details about the @var{pattern}
507 argument.  So, to list any symbolic links to @file{sysdep.c} in the
508 current directory and its subdirectories, you can do:
510 @example
511 find . -lname '*sysdep.c'
512 @end example
513 @end deffn
515 @deffn Option -follow
516 Dereference symbolic links.  The following differences in behavior occur
517 when this option is given:
519 @itemize @bullet
520 @item
521 @code{find} follows symbolic links to directories when searching
522 directory trees.
523 @item
524 @samp{-lname} and @samp{-ilname} always return false.
525 @item
526 @samp{-type} reports the types of the files that symbolic links point
528 @item
529 Implies @samp{-noleaf} (@pxref{Directories}).
530 @end itemize
531 @end deffn
533 @node Hard Links
534 @subsection Hard Links
536 To find hard links, first get the inode number of the file whose links
537 you want to find.  You can learn a file's inode number and the number of
538 links to it by running @samp{ls -i} or @samp{find -ls}.  If the file has
539 more than one link, you can search for the other links by passing that
540 inode number to @samp{-inum}.  Add the @samp{-xdev} option if you are
541 starting the search at a directory that has other filesystems mounted on
542 it, such as @file{/usr} on many systems.  Doing this saves needless
543 searching, since hard links to a file must be on the same filesystem.
544 @xref{Filesystems}.
546 @deffn Test -inum n
547 File has inode number @var{n}.
548 @end deffn
550 You can also search for files that have a certain number of links, with
551 @samp{-links}.  Directories normally have at least two hard links; their
552 @file{.} entry is the second one.  If they have subdirectories, each of
553 those also has a hard link called @file{..} to its parent directory.
555 @deffn Test -links n
556 File has @var{n} hard links.
557 @end deffn
559 @node Time
560 @section Time
562 Each file has three time stamps, which record the last time that certain
563 operations were performed on the file:
565 @enumerate
566 @item
567 access (read the file's contents)
568 @item
569 change the status (modify the file or its attributes)
570 @item
571 modify (change the file's contents)
572 @end enumerate
574 You can search for files whose time stamps are within a certain age
575 range, or compare them to other time stamps.
577 @menu
578 * Age Ranges::
579 * Comparing Timestamps::
580 @end menu
582 @node Age Ranges
583 @subsection Age Ranges
585 These tests are mainly useful with ranges (@samp{+@var{n}} and
586 @samp{-@var{n}}).
588 @deffn Test -atime n
589 @deffnx Test -ctime n
590 @deffnx Test -mtime n
591 True if the file was last accessed (or its status changed, or it was
592 modified) @var{n}*24 hours ago.
593 @end deffn
595 @deffn Test -amin n
596 @deffnx Test -cmin n
597 @deffnx Test -mmin n
598 True if the file was last accessed (or its status changed, or it was
599 modified) @var{n} minutes ago.  These tests provide finer granularity of
600 measurement than @samp{-atime} et al.  For example, to list files in
601 @file{/u/bill} that were last read from 2 to 6 minutes ago:
603 @example
604 find /u/bill -amin +2 -amin -6
605 @end example
606 @end deffn
608 @deffn Option -daystart
609 Measure times from the beginning of today rather than from 24 hours ago.
610 So, to list the regular files in your home directory that were modified
611 yesterday, do
613 @example
614 find ~ -daystart -type f -mtime 1
615 @end example
616 @end deffn
618 @node Comparing Timestamps
619 @subsection Comparing Timestamps
621 As an alternative to comparing timestamps to the current time, you can
622 compare them to another file's timestamp.  That file's timestamp could
623 be updated by another program when some event occurs.  Or you could set
624 it to a particular fixed date using the @code{touch} command.  For
625 example, to list files in @file{/usr} modified after February 1 of the
626 current year:
628 @c Idea from Rick Sladkey.
629 @example
630 touch -t 02010000 /tmp/stamp$$
631 find /usr -newer /tmp/stamp$$
632 rm -f /tmp/stamp$$
633 @end example
635 @deffn Test -anewer file
636 @deffnx Test -cnewer file
637 @deffnx Test -newer file
638 True if the file was last accessed (or its status changed, or it was
639 modified) more recently than @var{file} was modified.  These tests are
640 affected by @samp{-follow} only if @samp{-follow} comes before them on
641 the command line.  @xref{Symbolic Links}, for more information on
642 @samp{-follow}.  As an example, to list any files modified since
643 @file{/bin/sh} was last modified:
645 @example
646 find . -newer /bin/sh
647 @end example
648 @end deffn
650 @deffn Test -used n
651 True if the file was last accessed @var{n} days after its status was
652 last changed.  Useful for finding files that are not being used, and
653 could perhaps be archived or removed to save disk space.
654 @end deffn
656 @node Size
657 @section Size
659 @deffn Test -size n@r{[}bckwMG@r{]}
660 True if the file uses @var{n} units of space, rounding up.  The units
661 are 512-byte blocks by default, but they can be changed by adding a
662 one-character suffix to @var{n}:
664 @table @code
665 @item b
666 512-byte blocks (never 1024)
667 @item c
668 bytes
669 @item k
670 kilobytes (1024 bytes)
671 @item w
672 2-byte words
673 @item M
674 Megabytes
675 @item G
676 Gigabytes
677 @end table
679 The `b' suffix always considers blocks to be 512 bytes.  This is not
680 affected by the setting (or non-setting) of the POSIXLY_CORRECT
681 environment variable.  This behaviour is different to the behaviour of
682 the @samp{-ls} action).  If you want to use 1024-byte units, use the
683 `k' suffix instead.
685 The number can be prefixed with a `+' or a `-'.  A plus sign indicates
686 that the test should succeed if the file uses at least @var{n} units
687 of storage (this is the way I normally use this test) and a minus sign
688 indicates that the test should succeed if the file uses less than
689 @var{n} units of storage.   There is no `=' prefix, because that's the 
690 default anyway.  
692 The size does not count indirect blocks, but it does count blocks in
693 sparse files that are not actually allocated.  This handling of sparse
694 files differs from the output of the @samp{%k} and @samp{%b} format
695 specifiers for the @samp{-printf} predicate.
697 @end deffn
699 @deffn Test -empty
700 True if the file is empty and is either a regular file or a directory.
701 This might make it a good candidate for deletion.  This test is useful
702 with @samp{-depth} (@pxref{Directories}) and @samp{-exec rm -rf '@{@}' ';'}
703 (@pxref{Single File}).
704 @end deffn
706 @node Type
707 @section Type
709 @deffn Test -type c
710 True if the file is of type @var{c}:
712 @table @code
713 @item b
714 block (buffered) special
715 @item c
716 character (unbuffered) special
717 @item d
718 directory
719 @item p
720 named pipe (FIFO)
721 @item f
722 regular file
723 @item l
724 symbolic link
725 @item s
726 socket
727 @item D
728 door (Solaris)
729 @end table
730 @end deffn
732 @deffn Test -xtype c
733 The same as @samp{-type} unless the file is a symbolic link.  For
734 symbolic links: if @samp{-follow} has not been given, true if the file
735 is a link to a file of type @var{c}; if @samp{-follow} has been given,
736 true if @var{c} is @samp{l}.  In other words, for symbolic links,
737 @samp{-xtype} checks the type of the file that @samp{-type} does not
738 check.  @xref{Symbolic Links}, for more information on @samp{-follow}.
739 @end deffn
741 @node Owner
742 @section Owner
744 @deffn Test -user uname
745 @deffnx Test -group gname
746 True if the file is owned by user @var{uname} (belongs to group @var{gname}).
747 A numeric ID is allowed.
748 @end deffn
750 @deffn Test -uid n
751 @deffnx Test -gid n
752 True if the file's numeric user ID (group ID) is @var{n}.  These tests
753 support ranges (@samp{+@var{n}} and @samp{-@var{n}}), unlike
754 @samp{-user} and @samp{-group}.
755 @end deffn
757 @deffn Test -nouser
758 @deffnx Test -nogroup
759 True if no user corresponds to the file's numeric user ID (no group
760 corresponds to the numeric group ID).  These cases usually mean that the
761 files belonged to users who have since been removed from the system.
762 You probably should change the ownership of such files to an existing
763 user or group, using the @code{chown} or @code{chgrp} program.
764 @end deffn
766 @node Permissions
767 @section Permissions
769 @xref{File Permissions}, for information on how file permissions are
770 structured and how to specify them.
772 @deffn Test -perm mode
773 True if the
774 file's permissions are exactly @var{mode} (which can be numeric or symbolic).
775 Symbolic modes use mode 0 as a point of departure.
776 If @var{mode} starts with @samp{-}, true if
777 @emph{all} of the permissions set in @var{mode} are set for the file;
778 permissions not set in @var{mode} are ignored.
779 If @var{mode} starts with @samp{+}, true if
780 @emph{any} of the permissions set in @var{mode} are set for the file;
781 permissions not set in @var{mode} are ignored.
782 @end deffn
784 @node Contents
785 @section Contents
787 To search for files based on their contents, you can use the @code{grep}
788 program.  For example, to find out which C source files in the current
789 directory contain the string @samp{thing}, you can do:
791 @example
792 grep -l thing *.[ch]
793 @end example
795 If you also want to search for the string in files in subdirectories,
796 you can combine @code{grep} with @code{find} and @code{xargs}, like
797 this:
799 @example
800 find . -name '*.[ch]' | xargs grep -l thing
801 @end example
803 The @samp{-l} option causes @code{grep} to print only the names of files
804 that contain the string, rather than the lines that contain it.  The
805 string argument (@samp{thing}) is actually a regular expression, so it
806 can contain metacharacters.  This method can be refined a little by
807 using the @samp{-r} option to make @code{xargs} not run @code{grep} if
808 @code{find} produces no output, and using the @code{find} action
809 @samp{-print0} and the @code{xargs} option @samp{-0} to avoid
810 misinterpreting files whose names contain spaces:
812 @example
813 find . -name '*.[ch]' -print0 | xargs -r -0 grep -l thing
814 @end example
816 For a fuller treatment of finding files whose contents match a pattern,
817 see the manual page for @code{grep}.
819 @node Directories
820 @section Directories
822 Here is how to control which directories @code{find} searches, and how
823 it searches them.  These two options allow you to process a horizontal
824 slice of a directory tree.
826 @deffn Option -maxdepth levels
827 Descend at most @var{levels} (a non-negative integer) levels of
828 directories below the command line arguments.  @samp{-maxdepth 0} means
829 only apply the tests and actions to the command line arguments.
830 @end deffn
832 @deffn Option -mindepth levels
833 Do not apply any tests or actions at levels less than @var{levels} (a
834 non-negative integer).  @samp{-mindepth 1} means process all files
835 except the command line arguments.
836 @end deffn
838 @deffn Option -depth
839 Process each directory's contents before the directory itself.  Doing
840 this is a good idea when producing lists of files to archive with
841 @code{cpio} or @code{tar}.  If a directory does not have write
842 permission for its owner, its contents can still be restored from the
843 archive since the directory's permissions are restored after its contents.
844 @end deffn
846 @deffn Action -prune
847 If @samp{-depth} is not given, true; do not descend into the current
848 directory.  If @samp{-depth} is given, false; no effect.  @samp{-prune}
849 only affects tests and actions that come after it in the expression, not
850 those that come before.
852 For example, to skip the directory @file{src/emacs} and all files and
853 directories under it, and print the names of the other files found:
855 @example
856 find . -wholename './src/emacs' -prune -o -print
857 @end example
858 @end deffn
860 @deffn Option -noleaf
861 Do not optimize by assuming that directories contain 2 fewer
862 subdirectories than their hard link count.  This option is needed when
863 searching filesystems that do not follow the Unix directory-link
864 convention, such as CD-ROM or MS-DOS filesystems or AFS volume mount
865 points.  Each directory on a normal Unix filesystem has at least 2 hard
866 links: its name and its @file{.}  entry.  Additionally, its
867 subdirectories (if any) each have a @file{..}  entry linked to that
868 directory.  When @code{find} is examining a directory, after it has
869 statted 2 fewer subdirectories than the directory's link count, it knows
870 that the rest of the entries in the directory are non-directories
871 (@dfn{leaf} files in the directory tree).  If only the files' names need
872 to be examined, there is no need to stat them; this gives a significant
873 increase in search speed.
874 @end deffn
876 @deffn Option -ignore_readdir_race
877 If a file disappears after its name has been read from a directory but
878 before @code{find} gets around to examining the file with @code{stat},
879 don't issue an error message.  If you don't specify this option, an
880 error message will be issued.  This option can be useful in system
881 scripts (cron scripts, for example) that examine areas of the
882 filesystem that change frequently (mail queues, temporary directories,
883 and so forth), because this scenario is common for those sorts of
884 directories.  Completely silencing error messages from @code{find} is
885 undesirable, so this option neatly solves the problem.  There is no
886 way to search one part of the filesystem with this option on and part
887 of it with this option off, though.
888 @end deffn
890 @deffn Option -noignore_readdir_race
891 This option reverses the effect of the @samp{-ignore_readdir_race} option.
892 @end deffn
895 @node Filesystems
896 @section Filesystems
898 A @dfn{filesystem} is a section of a disk, either on the local host or
899 mounted from a remote host over a network.  Searching network
900 filesystems can be slow, so it is common to make @code{find} avoid them.
902 There are two ways to avoid searching certain filesystems.  One way is
903 to tell @code{find} to only search one filesystem:
905 @deffn Option -xdev
906 @deffnx Option -mount
907 Don't descend directories on other filesystems.  These options are synonyms.
908 @end deffn
910 The other way is to check the type of filesystem each file is on, and
911 not descend directories that are on undesirable filesystem types:
913 @deffn Test -fstype type
914 True if the file is on a filesystem of type @var{type}.  The valid
915 filesystem types vary among different versions of Unix; an incomplete
916 list of filesystem types that are accepted on some version of Unix or
917 another is:
918 @example
919 ufs 4.2 4.3 nfs tmp mfs S51K S52K
920 @end example
921 You can use @samp{-printf} with the @samp{%F} directive to see the types
922 of your filesystems.  @xref{Print File Information}.  @samp{-fstype} is
923 usually used with @samp{-prune} to avoid searching remote filesystems
924 (@pxref{Directories}). 
925 @end deffn
927 @node Combining Primaries With Operators
928 @section Combining Primaries With Operators
930 Operators build a complex expression from tests and actions.
931 The operators are, in order of decreasing precedence:
933 @table @code
934 @item @asis{( @var{expr} )}
935 @findex ()
936 Force precedence.  True if @var{expr} is true.
938 @item @asis{! @var{expr}}
939 @itemx @asis{-not @var{expr}}
940 @findex !
941 @findex -not
942 True if @var{expr} is false.
944 @item @asis{@var{expr1 expr2}}
945 @itemx @asis{@var{expr1} -a @var{expr2}}
946 @itemx @asis{@var{expr1} -and @var{expr2}}
947 @findex -a
948 @findex -and
949 And; @var{expr2} is not evaluated if @var{expr1} is false.
951 @item @asis{@var{expr1} -o @var{expr2}}
952 @itemx @asis{@var{expr1} -or @var{expr2}}
953 @findex -o
954 @findex -or
955 Or; @var{expr2} is not evaluated if @var{expr1} is true.
957 @item @asis{@var{expr1} , @var{expr2}}
958 @findex ,
959 List; both @var{expr1} and @var{expr2} are always evaluated.  True if
960 @var{expr2} is true.  The value of @var{expr1} is discarded.  This
961 operator lets you do multiple independent operations on one traversal,
962 without depending on whether other operations succeeded.
963 @end table
965 @code{find} searches the directory tree rooted at each file name by
966 evaluating the expression from left to right, according to the rules of
967 precedence, until the outcome is known (the left hand side is false for
968 @samp{-and}, true for @samp{-or}), at which point @code{find} moves on
969 to the next file name.
971 There are two other tests that can be useful in complex expressions:
973 @deffn Test -true
974 Always true.
975 @end deffn
977 @deffn Test -false
978 Always false.
979 @end deffn
981 @node Actions, Common Tasks, Finding Files, Top
982 @chapter Actions
984 There are several ways you can print information about the files that
985 match the criteria you gave in the @code{find} expression.  You can
986 print the information either to the standard output or to a file that
987 you name.  You can also execute commands that have the file names as
988 arguments.  You can use those commands as further filters to select files.
990 @menu
991 * Print File Name::
992 * Print File Information::
993 * Run Commands::
994 * Adding Tests::
995 @end menu
997 @node Print File Name
998 @section Print File Name
1000 @deffn Action -print
1001 True; print the full file name on the standard output, followed by a
1002 newline.
1003 @end deffn
1005 @deffn Action -fprint file
1006 True; print the full file name into file @var{file}, followed by a
1007 newline.  If @var{file} does not exist when @code{find} is run, it is
1008 created; if it does exist, it is truncated to 0 bytes.  The file names
1009 @file{/dev/stdout} and @file{/dev/stderr} are handled specially; they
1010 refer to the standard output and standard error output, respectively.
1011 @end deffn
1013 @node Print File Information
1014 @section Print File Information
1016 @deffn Action -ls
1017 True; list the current file in @samp{ls -dils} format on the standard
1018 output.  The output looks like this:
1020 @smallexample
1021 204744   17 -rw-r--r--   1 djm      staff       17337 Nov  2  1992 ./lwall-quotes
1022 @end smallexample
1024 The fields are:
1026 @enumerate
1027 @item
1028 The inode number of the file.  @xref{Hard Links}, for how to find files
1029 based on their inode number.
1031 @item
1032 the number of blocks in the file.  The block counts are of 1K blocks,
1033 unless the environment variable @code{POSIXLY_CORRECT} is set, in which
1034 case 512-byte blocks are used.  @xref{Size}, for how to find files based
1035 on their size.
1037 @item
1038 The file's type and permissions.  The type is shown as a dash for a
1039 regular file; for other file types, a letter like for @samp{-type} is
1040 used (@pxref{Type}).  The permissions are read, write, and execute for
1041 the file's owner, its group, and other users, respectively; a dash means
1042 the permission is not granted.  @xref{File Permissions}, for more details
1043 about file permissions.  @xref{Permissions}, for how to find files based
1044 on their permissions.
1046 @item
1047 The number of hard links to the file.
1049 @item
1050 The user who owns the file.
1052 @item
1053 The file's group.
1055 @item
1056 The file's size in bytes.
1058 @item
1059 The date the file was last modified.
1061 @item
1062 The file's name.  @samp{-ls} quotes non-printable characters in the file
1063 names using C-like backslash escapes.
1064 @end enumerate
1065 @end deffn
1067 @deffn Action -fls file
1068 True; like @samp{-ls} but write to @var{file} like @samp{-fprint}
1069 (@pxref{Print File Name}).
1070 @end deffn
1072 @deffn Action -printf format
1073 True; print @var{format} on the standard output, interpreting @samp{\}
1074 escapes and @samp{%} directives.  Field widths and precisions can be
1075 specified as with the @code{printf} C function.  Unlike @samp{-print},
1076 @samp{-printf} does not add a newline at the end of the string.
1077 @end deffn
1079 @deffn Action -fprintf file format
1080 True; like @samp{-printf} but write to @var{file} like @samp{-fprint}
1081 (@pxref{Print File Name}).
1082 @end deffn
1084 @menu
1085 * Escapes::
1086 * Format Directives::
1087 * Time Formats::
1088 @end menu
1090 @node Escapes
1091 @subsection Escapes
1093 The escapes that @samp{-printf} and @samp{-fprintf} recognize are:
1095 @table @code
1096 @item \a
1097 Alarm bell.
1098 @item \b
1099 Backspace.
1100 @item \c
1101 Stop printing from this format immediately and flush the output.
1102 @item \f
1103 Form feed.
1104 @item \n
1105 Newline.
1106 @item \r
1107 Carriage return.
1108 @item \t
1109 Horizontal tab.
1110 @item \v
1111 Vertical tab.
1112 @item \\
1113 A literal backslash (@samp{\}).
1114 @item \NNN
1115 The character whose ASCII code is NNN (octal).
1116 @end table
1118 A @samp{\} character followed by any other character is treated as an
1119 ordinary character, so they both are printed, and a warning message is
1120 printed to the standard error output (because it was probably a typo).
1122 @node Format Directives
1123 @subsection Format Directives
1125 @samp{-printf} and @samp{-fprintf} support the following format
1126 directives to print information about the file being processed.
1127 The C @code{printf} function, field width and precision specifiers
1128 are supported, as applied to string (%s) types. I.E. you can specify
1129 "minimum field width"."maximum field width" for each directive.
1131 @samp{%%} is a literal percent sign.  A @samp{%} character followed by
1132 an unrecognised character (i.e. not a known directive or printf field
1133 width and precision specifier), is discarded (but the unrecognised character
1134 is printed), and a warning message is printed to the standard error output
1135 (because it was probably a typo).
1137 @menu
1138 * Name Directives::
1139 * Ownership Directives::
1140 * Size Directives::
1141 * Location Directives::
1142 * Time Directives::
1143 @end menu
1145 @node Name Directives
1146 @subsubsection Name Directives
1148 @table @code
1149 @item %p
1150 File's name.
1151 @item %f
1152 File's name with any leading directories removed (only the last element).
1153 @item %h
1154 Leading directories of file's name (all but the last element and the
1155 slash before it).
1156 @item %P
1157 File's name with the name of the command line argument under which
1158 it was found removed from the beginning.
1159 @item %H
1160 Command line argument under which file was found.
1161 @end table
1163 @node Ownership Directives
1164 @subsubsection Ownership Directives
1166 @table @code
1167 @item %g
1168 File's group name, or numeric group ID if the group has no name.
1169 @item %G
1170 File's numeric group ID.
1171 @item %u
1172 File's user name, or numeric user ID if the user has no name.
1173 @item %U
1174 File's numeric user ID.
1175 @item %m
1176 File's permissions (in octal).
1177 @end table
1179 @node Size Directives
1180 @subsubsection Size Directives
1182 @table @code
1183 @item %k
1184 Amount of disk space occupied by the file, measured in 1K blocks
1185 (rounded up).  This can be less than the length of the file if 
1186 it is a sparse file (that is, it has ``holes'').
1187 @item %b
1188 File's size in 512-byte blocks (rounded up).  This also can be less 
1189 than the length of the file, if the file is sparse.
1190 @item %s
1191 File's size in bytes.
1192 @end table
1194 @node Location Directives
1195 @subsubsection Location Directives
1197 @table @code
1198 @item %d
1199 File's depth in the directory tree; files named on the command line
1200 have a depth of 0.
1201 @item %F
1202 Type of the filesystem the file is on; this value can be used for
1203 @samp{-fstype} (@pxref{Directories}).
1204 @item %l
1205 Object of symbolic link (empty string if file is not a symbolic link).
1206 @item %i
1207 File's inode number (in decimal).
1208 @item %n
1209 Number of hard links to file.
1210 @end table
1212 @node Time Directives
1213 @subsubsection Time Directives
1215 Some of these directives use the C @code{ctime} function.  Its output
1216 depends on the current locale, but it typically looks like
1218 @example
1219 Wed Nov  2 00:42:36 1994
1220 @end example
1222 @table @code
1223 @item %a
1224 File's last access time in the format returned by the C @code{ctime} function.
1225 @item %A@var{k}
1226 File's last access time in the format specified by @var{k}
1227 (@pxref{Time Formats}). 
1228 @item %c
1229 File's last status change time in the format returned by the C @code{ctime}
1230 function.
1231 @item %C@var{k}
1232 File's last status change time in the format specified by @var{k}
1233 (@pxref{Time Formats}).
1234 @item %t
1235 File's last modification time in the format returned by the C @code{ctime}
1236 function.
1237 @item %T@var{k}
1238 File's last modification time in the format specified by @var{k} 
1239 (@pxref{Time Formats}). 
1240 @end table
1242 @node Time Formats
1243 @subsection Time Formats
1245 Below are the formats for the directives @samp{%A}, @samp{%C}, and
1246 @samp{%T}, which print the file's timestamps.  Some of these formats
1247 might not be available on all systems, due to differences in the C
1248 @code{strftime} function between systems.
1250 @menu
1251 * Time Components::
1252 * Date Components::
1253 * Combined Time Formats::
1254 @end menu
1256 @node Time Components
1257 @subsubsection Time Components
1259 The following format directives print single components of the time.
1261 @table @code
1262 @item H
1263 hour (00..23)
1264 @item I
1265 hour (01..12)
1266 @item k
1267 hour ( 0..23)
1268 @item l
1269 hour ( 1..12)
1270 @item p
1271 locale's AM or PM
1272 @item Z
1273 time zone (e.g., EDT), or nothing if no time zone is determinable
1274 @item M
1275 minute (00..59)
1276 @item S
1277 second (00..61)
1278 @item @@
1279 seconds since Jan. 1, 1970, 00:00 GMT.
1280 @end table
1282 @node Date Components
1283 @subsubsection Date Components
1285 The following format directives print single components of the date.
1287 @table @code
1288 @item a
1289 locale's abbreviated weekday name (Sun..Sat)
1290 @item A
1291 locale's full weekday name, variable length (Sunday..Saturday)
1292 @item b
1293 @itemx h
1294 locale's abbreviated month name (Jan..Dec)
1295 @item B
1296 locale's full month name, variable length (January..December)
1297 @item m
1298 month (01..12)
1299 @item d
1300 day of month (01..31)
1301 @item w
1302 day of week (0..6)
1303 @item j
1304 day of year (001..366)
1305 @item U
1306 week number of year with Sunday as first day of week (00..53)
1307 @item W
1308 week number of year with Monday as first day of week (00..53)
1309 @item Y
1310 year (1970@dots{})
1311 @item y
1312 last two digits of year (00..99)
1313 @end table
1315 @node Combined Time Formats
1316 @subsubsection Combined Time Formats
1318 The following format directives print combinations of time and date
1319 components. 
1321 @table @code
1322 @item r
1323 time, 12-hour (hh:mm:ss [AP]M)
1324 @item T
1325 time, 24-hour (hh:mm:ss)
1326 @item X
1327 locale's time representation (H:M:S)
1328 @item c
1329 locale's date and time (Sat Nov 04 12:02:33 EST 1989)
1330 @item D
1331 date (mm/dd/yy)
1332 @item x
1333 locale's date representation (mm/dd/yy)
1334 @end table
1336 @node Run Commands
1337 @section Run Commands
1339 You can use the list of file names created by @code{find} or
1340 @code{locate} as arguments to other commands.  In this way you can
1341 perform arbitrary actions on the files.
1343 @menu
1344 * Single File::
1345 * Multiple Files::
1346 * Querying::
1347 @end menu
1349 @node Single File
1350 @subsection Single File
1352 Here is how to run a command on one file at a time.
1354 @deffn Action -exec command ;
1355 Execute @var{command}; true if 0 status is returned.  @code{find} takes
1356 all arguments after @samp{-exec} to be part of the command until an
1357 argument consisting of @samp{;} is reached.  It replaces the string
1358 @samp{@{@}} by the current file name being processed everywhere it
1359 occurs in the command.  Both of these constructions need to be escaped
1360 (with a @samp{\}) or quoted to protect them from expansion by the shell.
1361 The command is executed in the directory in which @code{find} was run.
1363 For example, to compare each C header file in the current directory with
1364 the file @file{/tmp/master}:
1366 @example
1367 find . -name '*.h' -exec diff -u '@{@}' /tmp/master ';'
1368 @end example
1369 @end deffn
1371 @node Multiple Files
1372 @subsection Multiple Files
1374 Sometimes you need to process files alone.  But when you
1375 don't, it is faster to run a command on as many files as possible at a
1376 time, rather than once per file.  Doing this saves on the time it takes
1377 to start up the command each time.
1379 To run a command on more than one file at once, use the @code{xargs}
1380 command, which is invoked like this:
1382 @example
1383 xargs @r{[}@var{option}@dots{}@r{]} @r{[}@var{command} @r{[}@var{initial-arguments}@r{]}@r{]}
1384 @end example
1386 @code{xargs} reads arguments from the standard input, delimited by
1387 blanks (which can be protected with double or single quotes or a
1388 backslash) or newlines.  It executes the @var{command} (default is
1389 @file{/bin/echo}) one or more times with any @var{initial-arguments}
1390 followed by arguments read from standard input.  Blank lines on the
1391 standard input are ignored.
1393 Instead of blank-delimited names, it is safer to use @samp{find -print0}
1394 or @samp{find -fprint0} and process the output by giving the @samp{-0}
1395 or @samp{--null} option to GNU @code{xargs}, GNU @code{tar}, GNU
1396 @code{cpio}, or @code{perl}.
1398 You can use shell command substitution (backquotes) to process a list of
1399 arguments, like this:
1401 @example
1402 grep -l sprintf `find $HOME -name '*.c' -print`
1403 @end example
1405 However, that method produces an error if the length of the @samp{.c}
1406 file names exceeds the operating system's command-line length limit.
1407 @code{xargs} avoids that problem by running the command as many times as
1408 necessary without exceeding the limit:
1410 @example
1411 find $HOME -name '*.c' -print | xargs grep -l sprintf
1412 @end example
1414 However, if the command needs to have its standard input be a terminal
1415 (@code{less}, for example), you have to use the shell command
1416 substitution method.
1418 The @code{xargs} command will process all its input, building command
1419 lines and executing them, unless one of the commands exits with a
1420 status of 255 (this will cause xargs to issue an error message and
1421 stop) or it reads a line contains the end of file string specified
1422 with the @samp{--eof} option. 
1424 @menu
1425 * Unsafe File Name Handling::
1426 * Safe File Name Handling::
1427 * Limiting Command Size::
1428 * Interspersing File Names::
1429 @end menu
1431 @node Unsafe File Name Handling
1432 @subsubsection Unsafe File Name Handling
1434 Because file names can contain quotes, backslashes, blank characters,
1435 and even newlines, it is not safe to process them using @code{xargs} in its
1436 default mode of operation.  But since most files' names do not contain
1437 blanks, this problem occurs only infrequently.  If you are only
1438 searching through files that you know have safe names, then you need not
1439 be concerned about it.
1441 @c This example is adapted from:
1442 @c From: pfalstad@stone.Princeton.EDU (Paul John Falstad)
1443 @c Newsgroups: comp.unix.shell
1444 @c Subject: Re: Beware xargs security holes
1445 @c Date: 16 Oct 90 19:12:06 GMT
1446 @c 
1447 In many applications, if @code{xargs} botches processing a file because
1448 its name contains special characters, some data might be lost.  The
1449 importance of this problem depends on the importance of the data and
1450 whether anyone notices the loss soon enough to correct it.  However,
1451 here is an extreme example of the problems that using blank-delimited
1452 names can cause.  If the following command is run daily from
1453 @code{cron}, then any user can remove any file on the system:
1455 @example
1456 find / -name '#*' -atime +7 -print | xargs rm
1457 @end example
1459 For example, you could do something like this:
1461 @example
1462 eg$ echo > '#
1463 vmunix'
1464 @end example
1466 @noindent
1467 and then @code{cron} would delete @file{/vmunix}, if it ran
1468 @code{xargs} with @file{/} as its current directory.
1470 To delete other files, for example @file{/u/joeuser/.plan}, you could do
1471 this:
1473 @example
1474 eg$ mkdir '#
1476 eg$ cd '#
1478 eg$ mkdir u u/joeuser u/joeuser/.plan'
1480 eg$ echo > u/joeuser/.plan'
1481 /#foo'
1482 eg$ cd ..
1483 eg$ find . -name '#*' -print | xargs echo
1484 ./# ./# /u/joeuser/.plan /#foo
1485 @end example
1487 @node Safe File Name Handling
1488 @subsubsection Safe File Name Handling
1490 Here is how to make @code{find} output file names so that they can be
1491 used by other programs without being mangled or misinterpreted.  You can
1492 process file names generated this way by giving the @samp{-0} or
1493 @samp{--null} option to GNU @code{xargs}, GNU @code{tar}, GNU
1494 @code{cpio}, or @code{perl}.
1496 @deffn Action -print0
1497 True; print the full file name on the standard output, followed by a
1498 null character.
1499 @end deffn
1501 @deffn Action -fprint0 file
1502 True; like @samp{-print0} but write to @var{file} like @samp{-fprint}
1503 (@pxref{Print File Name}).
1504 @end deffn
1506 @node Limiting Command Size
1507 @subsubsection Limiting Command Size
1509 @code{xargs} gives you control over how many arguments it passes to the
1510 command each time it executes it.  By default, it uses up to
1511 @code{ARG_MAX} - 2k, or 20k, whichever is smaller, characters per
1512 command.  It uses as many lines and arguments as fit within that limit.
1513 The following options modify those values.
1515 @table @code
1516 @item --no-run-if-empty
1517 @itemx -r
1518 If the standard input does not contain any nonblanks, do not run the
1519 command.  By default, the command is run once even if there is no input.
1521 @item --max-lines@r{[}=@var{max-lines}@r{]}
1522 @itemx -l@r{[}@var{max-lines}@r{]}
1523 Use at most @var{max-lines} nonblank input lines per command line;
1524 @var{max-lines} defaults to 1 if omitted.  Trailing blanks cause an
1525 input line to be logically continued on the next input line, for the
1526 purpose of counting the lines.  Implies @samp{-x}.
1528 @item --max-args=@var{max-args}
1529 @itemx -n @var{max-args}
1530 Use at most @var{max-args} arguments per command line.  Fewer than
1531 @var{max-args} arguments will be used if the size (see the @samp{-s}
1532 option) is exceeded, unless the @samp{-x} option is given, in which case
1533 @code{xargs} will exit.
1535 @item --max-chars=@var{max-chars}
1536 @itemx -s @var{max-chars}
1537 Use at most @var{max-chars} characters per command line, including the
1538 command and initial arguments and the terminating nulls at the ends of
1539 the argument strings.
1541 @item --max-procs=@var{max-procs}
1542 @itemx -P @var{max-procs}
1543 Run up to @var{max-procs} processes at a time; the default is 1.  If
1544 @var{max-procs} is 0, @code{xargs} will run as many processes as
1545 possible at a time.  Use the @samp{-n}, @samp{-s}, or @samp{-l} option
1546 with @samp{-P}; otherwise chances are that the command will be run only
1547 once.
1548 @end table
1550 @node Interspersing File Names
1551 @subsubsection Interspersing File Names
1553 @code{xargs} can insert the name of the file it is processing between
1554 arguments you give for the command.  Unless you also give options to
1555 limit the command size (@pxref{Limiting Command Size}), this mode of
1556 operation is equivalent to @samp{find -exec} (@pxref{Single File}).
1558 @table @code
1559 @item --replace@r{[}=@var{replace-str}@r{]}
1560 @itemx -i@r{[}@var{replace-str}@r{]}
1561 Replace occurrences of @var{replace-str} in the initial arguments with
1562 names read from standard input.  Also, unquoted blanks do not terminate
1563 arguments.  If @var{replace-str} is omitted, it defaults to @samp{@{@}}
1564 (like for @samp{find -exec}).  Implies @samp{-x} and @samp{-l 1}.  As an
1565 example, to sort each file the @file{bills} directory, leaving the
1566 output in that file name with @file{.sorted} appended, you could do:
1568 @example
1569 find bills -type f | xargs -iXX sort -o XX.sorted XX
1570 @end example
1572 @noindent
1573 The equivalent command using @samp{find -exec} is:
1575 @example
1576 find bills -type f -exec sort -o '@{@}.sorted' '@{@}' ';'
1577 @end example
1578 @end table
1580 @node Querying
1581 @subsection Querying
1583 To ask the user whether to execute a command on a single file, you can
1584 use the @code{find} primary @samp{-ok} instead of @samp{-exec}:
1586 @deffn Action -ok command ;
1587 Like @samp{-exec} (@pxref{Single File}), but ask the user first (on
1588 the standard input); if the response does not start with @samp{y} or
1589 @samp{Y}, do not run the command, and return false.
1590 @end deffn
1592 When processing multiple files with a single command, to query the user
1593 you give @code{xargs} the following option.  When using this option, you
1594 might find it useful to control the number of files processed per
1595 invocation of the command (@pxref{Limiting Command Size}).
1597 @table @code
1598 @item --interactive
1599 @itemx -p
1600 Prompt the user about whether to run each command line and read a line
1601 from the terminal.  Only run the command line if the response starts
1602 with @samp{y} or @samp{Y}.  Implies @samp{-t}.
1603 @end table
1605 @node Adding Tests
1606 @section Adding Tests
1608 You can test for file attributes that none of the @code{find} builtin
1609 tests check.  To do this, use @code{xargs} to run a program that filters
1610 a list of files printed by @code{find}.  If possible, use @code{find}
1611 builtin tests to pare down the list, so the program run by @code{xargs}
1612 has less work to do.  The tests builtin to @code{find} will likely run
1613 faster than tests that other programs perform.
1615 For example, here is a way to print the names of all of the unstripped
1616 binaries in the @file{/usr/local} directory tree.  Builtin tests avoid
1617 running @code{file} on files that are not regular files or are not
1618 executable.
1620 @example
1621 find /usr/local -type f -perm +a=x | xargs file | 
1622   grep 'not stripped' | cut -d: -f1
1623 @end example
1625 @noindent
1626 The @code{cut} program removes everything after the file name from the
1627 output of @code{file}.
1629 @c Idea from Martin Weitzel.
1630 If you want to place a special test somewhere in the middle of a
1631 @code{find} expression, you can use @samp{-exec} to run a program that
1632 performs the test.  Because @samp{-exec} evaluates to the exit status of
1633 the executed program, you can write a program (which can be a shell
1634 script) that tests for a special attribute and make it exit with a true
1635 (zero) or false (non-zero) status.  It is a good idea to place such a
1636 special test @emph{after} the builtin tests, because it starts a new
1637 process which could be avoided if a builtin test evaluates to false.
1638 Use this method only when @code{xargs} is not flexible enough, because
1639 starting one or more new processes to test each file is slower than
1640 using @code{xargs} to start one process that tests many files.
1642 Here is a shell script called @code{unstripped} that checks whether its
1643 argument is an unstripped binary file:
1645 @example
1646 #! /bin/sh
1647 file $1 | grep 'not stripped' > /dev/null
1648 @end example
1650 This script relies on the fact that the shell exits with the status of
1651 the last program it executed, in this case @code{grep}.  @code{grep}
1652 exits with a true status if it found any matches, false if not.  Here is
1653 an example of using the script (assuming it is in your search path).  It
1654 lists the stripped executables in the file @file{sbins} and the
1655 unstripped ones in @file{ubins}.
1657 @example
1658 find /usr/local -type f -perm +a=x \
1659   \( -exec unstripped '@{@}' \; -fprint ubins -o -fprint sbins \)
1660 @end example
1662 @node Common Tasks, Databases, Actions, Top
1663 @chapter Common Tasks
1665 The sections that follow contain some extended examples that both give a
1666 good idea of the power of these programs, and show you how to solve
1667 common real-world problems.
1669 @menu
1670 * Viewing And Editing::
1671 * Archiving::
1672 * Cleaning Up::
1673 * Strange File Names::
1674 * Fixing Permissions::
1675 * Classifying Files::
1676 @end menu
1678 @node Viewing And Editing
1679 @section Viewing And Editing
1681 To view a list of files that meet certain criteria, simply run your file
1682 viewing program with the file names as arguments.  Shells substitute a
1683 command enclosed in backquotes with its output, so the whole command
1684 looks like this:
1686 @example
1687 less `find /usr/include -name '*.h' | xargs grep -l mode_t`
1688 @end example
1690 @noindent
1691 You can edit those files by giving an editor name instead of a file
1692 viewing program.
1694 @node Archiving
1695 @section Archiving
1697 You can pass a list of files produced by @code{find} to a file archiving
1698 program.  GNU @code{tar} and @code{cpio} can both read lists of file
1699 names from the standard input---either delimited by nulls (the safe way)
1700 or by blanks (the lazy, risky default way).  To use null-delimited
1701 names, give them the @samp{--null} option.  You can store a file archive
1702 in a file, write it on a tape, or send it over a network to extract on
1703 another machine.
1705 One common use of @code{find} to archive files is to send a list of the
1706 files in a directory tree to @code{cpio}.  Use @samp{-depth} so if a
1707 directory does not have write permission for its owner, its contents can
1708 still be restored from the archive since the directory's permissions are
1709 restored after its contents.  Here is an example of doing this using
1710 @code{cpio}; you could use a more complex @code{find} expression to
1711 archive only certain files.
1713 @example
1714 find . -depth -print0 |
1715   cpio --create --null --format=crc --file=/dev/nrst0
1716 @end example
1718 You could restore that archive using this command:
1720 @example
1721 cpio --extract --null --make-dir --unconditional \
1722   --preserve --file=/dev/nrst0
1723 @end example
1725 Here are the commands to do the same things using @code{tar}:
1727 @example
1728 find . -depth -print0 |
1729   tar --create --null --files-from=- --file=/dev/nrst0
1731 tar --extract --null --preserve-perm --same-owner \
1732   --file=/dev/nrst0
1733 @end example
1735 @c Idea from Rick Sladkey.
1736 Here is an example of copying a directory from one machine to another:
1738 @example
1739 find . -depth -print0 | cpio -0o -Hnewc |
1740   rsh @var{other-machine} "cd `pwd` && cpio -i0dum"
1741 @end example
1743 @node Cleaning Up
1744 @section Cleaning Up
1746 @c Idea from Jim Meyering.
1747 This section gives examples of removing unwanted files in various situations.
1748 Here is a command to remove the CVS backup files created when an update
1749 requires a merge:
1751 @example
1752 find . -name '.#*' -print0 | xargs -0r rm -f
1753 @end example
1755 @c Idea from Franc,ois Pinard.
1756 You can run this command to clean out your clutter in @file{/tmp}.  You
1757 might place it in the file your shell runs when you log out
1758 (@file{.bash_logout}, @file{.logout}, or @file{.zlogout}, depending on
1759 which shell you use).
1761 @example
1762 find /tmp -user $LOGNAME -type f -print0 | xargs -0 -r rm -f
1763 @end example
1765 If your @code{find} command removes directories, you may find that 
1766 you get a spurious error message when @code{find} tries to recurse
1767 into a directory that has now been removed.  Using the @samp{-depth}
1768 option will normally resolve this problem.
1770 @c Idea from Noah Friedman.
1771 To remove old Emacs backup and auto-save files, you can use a command
1772 like the following.  It is especially important in this case to use
1773 null-terminated file names because Emacs packages like the VM mailer
1774 often create temporary file names with spaces in them, like @file{#reply
1775 to David J. MacKenzie<1>#}.
1777 @example
1778 find ~ \( -name '*~' -o -name '#*#' \) -print0 |
1779   xargs --no-run-if-empty --null rm -vf
1780 @end example
1782 Removing old files from @file{/tmp} is commonly done from @code{cron}:
1784 @c Idea from Kaveh Ghazi.
1785 @example
1786 find /tmp /var/tmp -not -type d -mtime +3 -print0 |
1787   xargs --null --no-run-if-empty rm -f
1789 find /tmp /var/tmp -depth -mindepth 1 -type d -empty -exec rmdir @{@} \;
1790 @end example
1792 The second @code{find} command above uses @samp{-depth} so it cleans out
1793 empty directories depth-first, hoping that the parents become empty and
1794 can be removed too.  It uses @samp{-mindepth} to avoid removing
1795 @file{/tmp} itself if it becomes totally empty.
1797 @node Strange File Names
1798 @section Strange File Names
1800 @c Idea from:
1801 @c From: tmatimar@isgtec.com (Ted Timar)
1802 @c Newsgroups: comp.unix.questions,comp.unix.shell,comp.answers,news.answers
1803 @c Subject: Unix - Frequently Asked Questions (2/7) [Frequent posting]
1804 @c Subject: How do I remove a file with funny characters in the filename ?
1805 @c Date: Thu Mar 18 17:16:55 EST 1993
1806 @code{find} can help you remove or rename a file with strange characters
1807 in its name.  People are sometimes stymied by files whose names contain
1808 characters such as spaces, tabs, control characters, or characters with
1809 the high bit set.  The simplest way to remove such files is:
1811 @example
1812 rm -i @var{some*pattern*that*matches*the*problem*file}
1813 @end example
1815 @code{rm} asks you whether to remove each file matching the given
1816 pattern.  If you are using an old shell, this approach might not work if
1817 the file name contains a character with the high bit set; the shell may
1818 strip it off.  A more reliable way is:
1820 @example
1821 find . -maxdepth 1 @var{tests} -ok rm '@{@}' \;
1822 @end example
1824 @noindent
1825 where @var{tests} uniquely identify the file.  The @samp{-maxdepth 1}
1826 option prevents @code{find} from wasting time searching for the file in
1827 any subdirectories; if there are no subdirectories, you may omit it.  A
1828 good way to uniquely identify the problem file is to figure out its
1829 inode number; use
1831 @example
1832 ls -i
1833 @end example
1835 Suppose you have a file whose name contains control characters, and you
1836 have found that its inode number is 12345.  This command prompts you for
1837 whether to remove it:
1839 @example
1840 find . -maxdepth 1 -inum 12345 -ok rm -f '@{@}' \;
1841 @end example
1843 If you don't want to be asked, perhaps because the file name may contain
1844 a strange character sequence that will mess up your screen when printed,
1845 then use @samp{-exec} instead of @samp{-ok}.
1847 If you want to rename the file instead, you can use @code{mv} instead of
1848 @code{rm}:
1850 @example
1851 find . -maxdepth 1 -inum 12345 -ok mv '@{@}' @var{new-file-name} \;
1852 @end example
1854 @node Fixing Permissions
1855 @section Fixing Permissions
1857 Suppose you want to make sure that everyone can write to the directories in a
1858 certain directory tree.  Here is a way to find directories lacking either
1859 user or group write permission (or both), and fix their permissions:
1861 @example
1862 find . -type d -not -perm -ug=w | xargs chmod ug+w
1863 @end example
1865 @noindent
1866 You could also reverse the operations, if you want to make sure that
1867 directories do @emph{not} have world write permission.
1869 @node Classifying Files
1870 @section Classifying Files
1872 @c Idea from:
1873 @c From: martin@mwtech.UUCP (Martin Weitzel)
1874 @c Newsgroups: comp.unix.wizards,comp.unix.questions
1875 @c Subject: Advanced usage of 'find' (Re: Unix security automating script)
1876 @c Date: 22 Mar 90 15:05:19 GMT
1877 If you want to classify a set of files into several groups based on
1878 different criteria, you can use the comma operator to perform multiple
1879 independent tests on the files.  Here is an example:
1881 @example
1882 find / -type d \( -perm -o=w -fprint allwrite , \
1883   -perm -o=x -fprint allexec \)
1885 echo "Directories that can be written to by everyone:"
1886 cat allwrite
1887 echo ""
1888 echo "Directories with search permissions for everyone:"
1889 cat allexec
1890 @end example
1892 @code{find} has only to make one scan through the directory tree (which
1893 is one of the most time consuming parts of its work).
1895 @node Databases, File Permissions, Common Tasks, Top
1896 @chapter File Name Databases
1898 The file name databases used by @code{locate} contain lists of files
1899 that were in particular directory trees when the databases were last
1900 updated.  The file name of the default database is determined when
1901 @code{locate} and @code{updatedb} are configured and installed.  The
1902 frequency with which the databases are updated and the directories for
1903 which they contain entries depend on how often @code{updatedb} is run,
1904 and with which arguments.
1906 @menu
1907 * Database Locations::
1908 * Database Formats::
1909 @end menu
1911 @node Database Locations
1912 @section Database Locations
1914 There can be multiple file name databases.  Users can select which
1915 databases @code{locate} searches using an environment variable or a
1916 command line option.  The system administrator can choose the file name
1917 of the default database, the frequency with which the databases are
1918 updated, and the directories for which they contain entries.  File name
1919 databases are updated by running the @code{updatedb} program, typically
1920 nightly.
1922 In networked environments, it often makes sense to build a database at
1923 the root of each filesystem, containing the entries for that filesystem.
1924 @code{updatedb} is then run for each filesystem on the fileserver where
1925 that filesystem is on a local disk, to prevent thrashing the network.
1926 Here are the options to @code{updatedb} to select which directories each
1927 database contains entries for:
1929 @table @code
1930 @item --localpaths='@var{path}@dots{}'
1931 Non-network directories to put in the database.
1932 Default is @file{/}.
1934 @item --netpaths='@var{path}@dots{}'
1935 Network (NFS, AFS, RFS, etc.) directories to put in the database.
1936 The environment variable @code{NETPATHS} also sets this value.
1937 Default is none.
1940 @item --prunepaths='@var{path}@dots{}'
1941 Directories to not put in the database, which would otherwise be.
1942 The environment variable @code{PRUNEPATHS} also sets this value.
1943 Default is @file{/tmp /usr/tmp /var/tmp /afs}.
1945 @item --prunefs='@var{path}@dots{}'
1946 File systems to not put in the database, which would otherwise be.
1947 Note that files are pruned when a file system is reached;
1948 Any file system mounted under an undesired file system will be
1949 ignored.
1950 The environment variable @code{PRUNEFS} also sets this value.
1951 Default is @file{nfs NFS proc}.
1953 @item --output=@var{dbfile}
1954 The database file to build.
1955 Default is system-dependent, but typically @file{/usr/local/var/locatedb}.
1957 @item --localuser=@var{user}
1958 The user to search the non-network directories as, using @code{su}.
1959 Default is to search the non-network directories as the current user.
1960 You can also use the environment variable @code{LOCALUSER} to set this user.
1962 @item --netuser=@var{user}
1963 The user to search network directories as, using @code{su}.
1964 Default is @code{daemon}.
1965 You can also use the environment variable @code{NETUSER} to set this user.
1966 @end table
1968 @node Database Formats
1969 @section Database Formats
1971 The file name databases contain lists of files that were in particular
1972 directory trees when the databases were last updated.  The file name
1973 database format changed starting with GNU @code{locate} version 4.0 to
1974 allow machines with different byte orderings to share the databases.  The
1975 new GNU @code{locate} can read both the old and new database formats.
1976 However, old versions of @code{locate} and @code{find} produce incorrect
1977 results if given a new-format database.
1979 @menu
1980 * New Database Format::
1981 * Sample Database::
1982 * Old Database Format::
1983 @end menu
1985 @node New Database Format
1986 @subsection New Database Format
1988 @code{updatedb} runs a program called @code{frcode} to
1989 @dfn{front-compress} the list of file names, which reduces the database
1990 size by a factor of 4 to 5.  Front-compression (also known as
1991 incremental encoding) works as follows.
1993 The database entries are a sorted list (case-insensitively, for users'
1994 convenience).  Since the list is sorted, each entry is likely to share a
1995 prefix (initial string) with the previous entry.  Each database entry
1996 begins with an offset-differential count byte, which is the additional
1997 number of characters of prefix of the preceding entry to use beyond the
1998 number that the preceding entry is using of its predecessor.  (The
1999 counts can be negative.)  Following the count is a null-terminated ASCII
2000 remainder---the part of the name that follows the shared prefix.
2002 If the offset-differential count is larger than can be stored in a byte
2003 (+/-127), the byte has the value 0x80 and the count follows in a 2-byte
2004 word, with the high byte first (network byte order).
2006 Every database begins with a dummy entry for a file called
2007 @file{LOCATE02}, which @code{locate} checks for to ensure that the
2008 database file has the correct format; it ignores the entry in doing the
2009 search.
2011 Databases can not be concatenated together, even if the first (dummy)
2012 entry is trimmed from all but the first database.  This is because the
2013 offset-differential count in the first entry of the second and following
2014 databases will be wrong.
2016 @node Sample Database
2017 @subsection Sample Database
2019 Sample input to @code{frcode}:
2020 @c with nulls changed to newlines:
2022 @example
2023 /usr/src
2024 /usr/src/cmd/aardvark.c
2025 /usr/src/cmd/armadillo.c
2026 /usr/tmp/zoo
2027 @end example
2029 Length of the longest prefix of the preceding entry to share:
2031 @example
2032 0 /usr/src
2033 8 /cmd/aardvark.c
2034 14 rmadillo.c
2035 5 tmp/zoo
2036 @end example
2038 Output from @code{frcode}, with trailing nulls changed to newlines
2039 and count bytes made printable:
2041 @example
2042 0 LOCATE02
2043 0 /usr/src
2044 8 /cmd/aardvark.c
2045 6 rmadillo.c
2046 -9 tmp/zoo
2047 @end example
2049 (6 = 14 - 8, and -9 = 5 - 14)
2051 @node Old Database Format
2052 @subsection Old Database Format
2054 The old database format is used by Unix @code{locate} and @code{find}
2055 programs and earlier releases of the GNU ones.  @code{updatedb} produces
2056 this format if given the @samp{--old-format} option.
2058 @code{updatedb} runs programs called @code{bigram} and @code{code} to
2059 produce old-format databases.  The old format differs from the new one
2060 in the following ways.  Instead of each entry starting with an
2061 offset-differential count byte and ending with a null, byte values from
2062 0 through 28 indicate offset-differential counts from -14 through 14.
2063 The byte value indicating that a long offset-differential count follows
2064 is 0x1e (30), not 0x80.  The long counts are stored in host byte order,
2065 which is not necessarily network byte order, and host integer word size,
2066 which is usually 4 bytes.  They also represent a count 14 less than
2067 their value.  The database lines have no termination byte; the start of
2068 the next line is indicated by its first byte having a value <= 30.
2070 In addition, instead of starting with a dummy entry, the old database
2071 format starts with a 256 byte table containing the 128 most common
2072 bigrams in the file list.  A bigram is a pair of adjacent bytes.  Bytes
2073 in the database that have the high bit set are indexes (with the high
2074 bit cleared) into the bigram table.  The bigram and offset-differential
2075 count coding makes these databases 20-25% smaller than the new format,
2076 but makes them not 8-bit clean.  Any byte in a file name that is in the
2077 ranges used for the special codes is replaced in the database by a
2078 question mark, which not coincidentally is the shell wildcard to match a
2079 single character.
2081 The old format therefore can not faithfully store entries with non-ASCII
2082 characters. It therefore should not be used in internationalized
2083 environments.
2085 @node File Permissions, Reference, Databases, Top
2086 @chapter File Permissions
2088 @include perm.texi
2090 @node Reference, Primary Index, File Permissions, Top
2091 @chapter Reference
2093 Below are summaries of the command line syntax for the programs
2094 discussed in this manual.
2096 @menu
2097 * Invoking find::
2098 * Invoking locate::
2099 * Invoking updatedb::
2100 * Invoking xargs::
2101 @end menu
2103 @node Invoking find, Invoking locate, , Reference
2104 @section Invoking @code{find}
2106 @example
2107 find @r{[}@var{file}@dots{}@r{]} @r{[}@var{expression}@r{]}
2108 @end example
2110 @code{find} searches the directory tree rooted at each file name
2111 @var{file} by evaluating the @var{expression} on each file it finds in
2112 the tree.
2114 @code{find} considers the first argument that begins with @samp{-},
2115 @samp{(}, @samp{)}, @samp{,}, or @samp{!} to be the beginning of the
2116 expression; any arguments before it are paths to search, and any
2117 arguments after it are the rest of the expression.  If no paths are
2118 given, the current directory is used.  If no expression is given, the
2119 expression @samp{-print} is used.
2121 @code{find} exits with status 0 if all files are processed successfully,
2122 greater than 0 if errors occur.
2124 @xref{Primary Index}, for a summary of all of the tests, actions, and
2125 options that the expression can contain.
2127 @code{find} also recognizes two options for administrative use:
2129 @table @code
2130 @item --help
2131 Print a summary of the command-line argument format and exit.
2132 @item --version
2133 Print the version number of @code{find} and exit.
2134 @end table
2136 @node Invoking locate, Invoking updatedb, Invoking find, Reference
2137 @section Invoking @code{locate}
2139 @example
2140 locate @r{[}@var{option}@dots{}@r{]} @var{pattern}@dots{}
2141 @end example
2143 @table @code
2144 @item --database=@var{path}
2145 @itemx -d @var{path}
2146 Instead of searching the default file name database, search the file
2147 name databases in @var{path}, which is a colon-separated list of
2148 database file names.  You can also use the environment variable
2149 @code{LOCATE_PATH} to set the list of database files to search.  The
2150 option overrides the environment variable if both are used.
2152 @item --existing
2153 @itemx -e
2154 Only print out such names which currently exist (instead of such names
2155 which existed when the database was created).
2156 Note that this may slow down the program a lot, if there are many matches
2157 in the database.
2159 @item --ignore-case
2160 @itemx -i
2161 Ignore case distinctions in both the pattern and the file names.
2163 @item --help
2164 Print a summary of the options to @code{locate} and exit.
2166 @item --version
2167 Print the version number of @code{locate} and exit.
2168 @end table
2170 @node Invoking updatedb, Invoking xargs, Invoking locate, Reference
2171 @section Invoking @code{updatedb}
2173 @example
2174 updatedb @r{[}@var{option}@dots{}@r{]}
2175 @end example
2177 @table @code
2178 @item --localpaths='@var{path}@dots{}'
2179 Non-network directories to put in the database.
2180 Default is @file{/}.
2182 @item --netpaths='@var{path}@dots{}'
2183 Network (NFS, AFS, RFS, etc.) directories to put in the database.
2184 The environment variable @code{NETPATHS} also sets this value.
2185 Default is none.
2187 @item --prunepaths='@var{path}@dots{}'
2188 Directories to not put in the database, which would otherwise be.
2189 The environment variable @code{PRUNEPATHS} also sets this value.
2190 Default is @file{/tmp /usr/tmp /var/tmp /afs}.
2192 @item --prunefs='@var{path}@dots{}'
2193 File systems to not put in the database, which would otherwise be.
2194 Note that files are pruned when a file system is reached;
2195 Any file system mounted under an undesired file system will be
2196 ignored.
2197 The environment variable @code{PRUNEFS} also sets this value.
2198 Default is @file{nfs NFS proc}.
2200 @item --output=@var{dbfile}
2201 The database file to build.
2202 Default is system-dependent, but typically @file{/usr/local/var/locatedb}.
2204 @item --localuser=@var{user}
2205 The user to search the non-network directories as, using @code{su}.
2206 Default is to search the non-network directories as the current user.
2207 You can also use the environment variable @code{LOCALUSER} to set this user.
2209 @item --netuser=@var{user}
2210 The user to search network directories as, using @code{su}(1).
2211 Default is @code{daemon}.
2212 You can also use the environment variable @code{NETUSER} to set this user.
2213 @end table
2215 @node Invoking xargs, ,  Invoking updatedb, Reference
2216 @section Invoking @code{xargs}
2218 @example
2219 xargs @r{[}@var{option}@dots{}@r{]} @r{[}@var{command} @r{[}@var{initial-arguments}@r{]}@r{]}
2220 @end example
2222 @code{xargs} exits with the following status:
2224 @table @asis
2225 @item 0
2226 if it succeeds
2227 @item 123
2228 if any invocation of the command exited with status 1-125
2229 @item 124
2230 if the command exited with status 255
2231 @item 125
2232 if the command is killed by a signal
2233 @item 126
2234 if the command cannot be run
2235 @item 127
2236 if the command is not found
2237 @item 1
2238 if some other error occurred.
2239 @end table
2241 @table @code
2242 @item --null
2243 @itemx -0
2244 Input filenames are terminated by a null character instead of by
2245 whitespace, and the quotes and backslash are not special (every
2246 character is taken literally).  Disables the end of file string, which
2247 is treated like any other argument.
2249 @item --eof@r{[}=@var{eof-str}@r{]}
2250 @itemx -e@r{[}@var{eof-str}@r{]}
2251 Set the end of file string to @var{eof-str}.  If the end of file string
2252 occurs as a line of input, the rest of the input is ignored.  If
2253 @var{eof-str} is omitted, there is no end of file string.  If this
2254 option is not given, the end of file string defaults to @samp{_}.
2256 @item --help
2257 Print a summary of the options to @code{xargs} and exit.
2259 @item --replace@r{[}=@var{replace-str}@r{]}
2260 @itemx -i@r{[}@var{replace-str}@r{]}
2261 Replace occurrences of @var{replace-str} in the initial arguments with
2262 names read from standard input.  Also, unquoted blanks do not terminate
2263 arguments.  If @var{replace-str} is omitted, it defaults to @samp{@{@}}
2264 (like for @samp{find -exec}).  Implies @samp{-x} and @samp{-l 1}.
2266 @item --max-lines@r{[}=@var{max-lines}@r{]}
2267 @itemx -l@r{[}@var{max-lines}@r{]}
2268 Use at most @var{max-lines} nonblank input lines per command line;
2269 @var{max-lines} defaults to 1 if omitted.  Trailing blanks cause an
2270 input line to be logically continued on the next input line, for the
2271 purpose of counting the lines.  Implies @samp{-x}.
2273 @item --max-args=@var{max-args}
2274 @itemx -n @var{max-args}
2275 Use at most @var{max-args} arguments per command line.  Fewer than
2276 @var{max-args} arguments will be used if the size (see the @samp{-s}
2277 option) is exceeded, unless the @samp{-x} option is given, in which case
2278 @code{xargs} will exit.
2280 @item --interactive
2281 @itemx -p
2282 Prompt the user about whether to run each command line and read a line
2283 from the terminal.  Only run the command line if the response starts
2284 with @samp{y} or @samp{Y}.  Implies @samp{-t}.
2286 @item --no-run-if-empty
2287 @itemx -r
2288 If the standard input does not contain any nonblanks, do not run the
2289 command.  By default, the command is run once even if there is no input.
2291 @item --max-chars=@var{max-chars}
2292 @itemx -s @var{max-chars}
2293 Use at most @var{max-chars} characters per command line, including the
2294 command and initial arguments and the terminating nulls at the ends of
2295 the argument strings.
2297 @item --verbose
2298 @itemx -t
2299 Print the command line on the standard error output before executing
2302 @item --version
2303 Print the version number of @code{xargs} and exit.
2305 @item --exit
2306 @itemx -x
2307 Exit if the size (see the @samp{-s} option) is exceeded.
2310 @item --max-procs=@var{max-procs}
2311 @itemx -P @var{max-procs}
2312 Run up to @var{max-procs} processes at a time; the default is 1.  If
2313 @var{max-procs} is 0, @code{xargs} will run as many processes as
2314 possible at a time.
2315 @end table
2317 @node Primary Index, , Reference, Top
2318 @unnumbered @code{find} Primary Index
2320 This is a list of all of the primaries (tests, actions, and options)
2321 that make up @code{find} expressions for selecting files.  @xref{find
2322 Expressions}, for more information on expressions.
2324 @printindex fn
2326 @contents
2327 @bye
2329 @comment texi related words used by Emacs' spell checker ispell.el
2331 @comment LocalWords: texinfo setfilename settitle setchapternewpage
2332 @comment LocalWords: iftex finalout ifinfo DIR titlepage vskip pt
2333 @comment LocalWords: filll dir samp dfn noindent xref pxref
2334 @comment LocalWords: var deffn texi deffnx itemx emph asis
2335 @comment LocalWords: findex smallexample subsubsection cindex
2337 @comment other words used by Emacs' spell checker ispell.el
2338 @comment LocalWords: README fred updatedb xargs Plett Rendell akefile
2339 @comment LocalWords: args grep Filesystems fo foo fOo wildcards iname
2340 @comment LocalWords: ipath regex iregex expr fubar regexps
2341 @comment LocalWords: metacharacters macs sr sc inode lname ilname
2342 @comment LocalWords: sysdep noleaf ls inum xdev filesystems usr atime
2343 @comment LocalWords: ctime mtime amin cmin mmin al daystart Sladkey rm
2344 @comment LocalWords: anewer cnewer bckw rf xtype uname gname uid gid
2345 @comment LocalWords: nouser nogroup chown chgrp perm ch maxdepth
2346 @comment LocalWords: mindepth cpio src CD AFS statted stat fstype ufs
2347 @comment LocalWords: nfs tmp mfs printf fprint dils rw djm Nov lwall
2348 @comment LocalWords: POSIXLY fls fprintf strftime locale's EDT GMT AP
2349 @comment LocalWords: EST diff perl backquotes sprintf Falstad Oct cron
2350 @comment LocalWords: eg vmunix mkdir afs allexec allwrite ARG bigram
2351 @comment LocalWords: bigrams cd chmod comp crc CVS dbfile dum eof
2352 @comment LocalWords: fileserver filesystem fn frcode Ghazi Hnewc iXX
2353 @comment LocalWords: joeuser Kaveh localpaths localuser LOGNAME
2354 @comment LocalWords: Meyering mv netpaths netuser nonblank nonblanks
2355 @comment LocalWords: ois ok Pinard printindex proc procs prunefs
2356 @comment LocalWords: prunepaths pwd RFS rmadillo rmdir rsh sbins str
2357 @comment LocalWords: su Timar ubins ug unstripped vf VM Weitzel
2358 @comment LocalWords: wildcard zlogout