home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / info / find.info-2 (.txt) < prev    next >
GNU Info File  |  1994-12-22  |  38KB  |  746 lines

  1. This is Info file find.info, produced by Makeinfo-1.55 from the input
  2. file find.texi.
  3. START-INFO-DIR-ENTRY
  4. * Finding Files: (find).        Listing and operating on files
  5.                                 that match certain criteria.
  6. END-INFO-DIR-ENTRY
  7.    This file documents the GNU utilities for finding files that match
  8. certain criteria and performing various operations on them.
  9.    Copyright (C) 1994 Free Software Foundation, Inc.
  10.    Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice are
  12. preserved on all copies.
  13.    Permission is granted to copy and distribute modified versions of
  14. this manual under the conditions for verbatim copying, provided that
  15. the entire resulting derived work is distributed under the terms of a
  16. permission notice identical to this one.
  17.    Permission is granted to copy and distribute translations of this
  18. manual into another language, under the above conditions for modified
  19. versions, except that this permission notice may be stated in a
  20. translation approved by the Foundation.
  21. File: find.info,  Node: Viewing And Editing,  Next: Archiving,  Up: Common Tasks
  22. Viewing And Editing
  23. ===================
  24.    To view a list of files that meet certain criteria, simply run your
  25. file viewing program with the file names as arguments.  Shells
  26. substitute a command enclosed in backquotes with its output, so the
  27. whole command looks like this:
  28.      less `find /usr/include -name '*.h' | xargs grep -l mode_t`
  29. You can edit those files by giving an editor name instead of a file
  30. viewing program.
  31. File: find.info,  Node: Archiving,  Next: Cleaning Up,  Prev: Viewing And Editing,  Up: Common Tasks
  32. Archiving
  33. =========
  34.    You can pass a list of files produced by `find' to a file archiving
  35. program.  GNU `tar' and `cpio' can both read lists of file names from
  36. the standard input--either delimited by nulls (the safe way) or by
  37. blanks (the lazy, risky default way).  To use null-delimited names,
  38. give them the `--null' option.  You can store a file archive in a file,
  39. write it on a tape, or send it over a network to extract on another
  40. machine.
  41.    One common use of `find' to archive files is to send a list of the
  42. files in a directory tree to `cpio'.  Use `-depth' so if a directory
  43. does not have write permission for its owner, its contents can still be
  44. restored from the archive since the directory's permissions are
  45. restored after its contents.  Here is an example of doing this using
  46. `cpio'; you could use a more complex `find' expression to archive only
  47. certain files.
  48.      find . -depth -print0 |
  49.        cpio --create --null --format=crc --file=/dev/nrst0
  50.    You could restore that archive using this command:
  51.      cpio --extract --null --make-dir --unconditional \
  52.        --preserve --file=/dev/nrst0
  53.    Here are the commands to do the same things using `tar':
  54.      find . -depth -print0 |
  55.        tar --create --null --files-from=- --file=/dev/nrst0
  56.      
  57.      tar --extract --null --preserve-perm --same-owner \
  58.        --file=/dev/nrst0
  59.    Here is an example of copying a directory from one machine to
  60. another:
  61.      find . -depth -print0 | cpio -0o -Hnewc |
  62.        rsh OTHER-MACHINE "cd `pwd` && cpio -i0dum"
  63. File: find.info,  Node: Cleaning Up,  Next: Strange File Names,  Prev: Archiving,  Up: Common Tasks
  64. Cleaning Up
  65. ===========
  66.    This section gives examples of removing unwanted files in various
  67. situations.  Here is a command to remove the CVS backup files created
  68. when an update requires a merge:
  69.      find . -name '.#*' -print0 | xargs -0r rm -f
  70.    You can run this command to clean out your clutter in `/tmp'.  You
  71. might place it in the file your shell runs when you log out
  72. (`.bash_logout', `.logout', or `.zlogout', depending on which shell you
  73. use).
  74.      find /tmp -user $LOGNAME -type f -print0 | xargs -0 -r rm -f
  75.    To remove old Emacs backup and auto-save files, you can use a command
  76. like the following.  It is especially important in this case to use
  77. null-terminated file names because Emacs packages like the VM mailer
  78. often create temporary file names with spaces in them, like `#reply to
  79. David J. MacKenzie<1>#'.
  80.      find ~ \( -name '*~' -o -name '#*#' \) -print0 |
  81.        xargs --no-run-if-empty --null rm -vf
  82.    Removing old files from `/tmp' is commonly done from `cron':
  83.      find /tmp /var/tmp -not -type d -mtime +3 -print0 |
  84.        xargs --null --no-run-if-empty rm -f
  85.      
  86.      find /tmp /var/tmp -depth -mindepth 1 -type d -empty -print0 |
  87.        xargs --null --no-run-if-empty rmdir
  88.    The second `find' command above uses `-depth' so it cleans out empty
  89. directories depth-first, hoping that the parents become empty and can
  90. be removed too.  It uses `-mindepth' to avoid removing `/tmp' itself if
  91. it becomes totally empty.
  92. File: find.info,  Node: Strange File Names,  Next: Fixing Permissions,  Prev: Cleaning Up,  Up: Common Tasks
  93. Strange File Names
  94. ==================
  95.    `find' can help you remove or rename a file with strange characters
  96. in its name.  People are sometimes stymied by files whose names contain
  97. characters such as spaces, tabs, control characters, or characters with
  98. the high bit set.  The simplest way to remove such files is:
  99.      rm -i SOME*PATTERN*THAT*MATCHES*THE*PROBLEM*FILE
  100.    `rm' asks you whether to remove each file matching the given
  101. pattern.  If you are using an old shell, this approach might not work if
  102. the file name contains a character with the high bit set; the shell may
  103. strip it off.  A more reliable way is:
  104.      find . -maxdepth 1 TESTS -ok rm '{}' \;
  105. where TESTS uniquely identify the file.  The `-maxdepth 1' option
  106. prevents `find' from wasting time searching for the file in any
  107. subdirectories; if there are no subdirectories, you may omit it.  A
  108. good way to uniquely identify the problem file is to figure out its
  109. inode number; use
  110.      ls -i
  111.    Suppose you have a file whose name contains control characters, and
  112. you have found that its inode number is 12345.  This command prompts
  113. you for whether to remove it:
  114.      find . -maxdepth 1 -inum 12345 -ok rm -f '{}' \;
  115.    If you don't want to be asked, perhaps because the file name may
  116. contain a strange character sequence that will mess up your screen when
  117. printed, then use `-exec' instead of `-ok'.
  118.    If you want to rename the file instead, you can use `mv' instead of
  119. `rm':
  120.      find . -maxdepth 1 -inum 12345 -ok mv '{}' NEW-FILE-NAME \;
  121. File: find.info,  Node: Fixing Permissions,  Next: Classifying Files,  Prev: Strange File Names,  Up: Common Tasks
  122. Fixing Permissions
  123. ==================
  124.    Suppose you want to make sure that everyone can write to the
  125. directories in a certain directory tree.  Here is a way to find
  126. directories lacking either user or group write permission (or both),
  127. and fix their permissions:
  128.      find . -type d -not -perm -ug=w | xargs chmod ug+w
  129. You could also reverse the operations, if you want to make sure that
  130. directories do *not* have world write permission.
  131. File: find.info,  Node: Classifying Files,  Prev: Fixing Permissions,  Up: Common Tasks
  132. Classifying Files
  133. =================
  134.    If you want to classify a set of files into several groups based on
  135. different criteria, you can use the comma operator to perform multiple
  136. independent tests on the files.  Here is an example:
  137.      find / -type d \( -perm -o=w -fprint allwrite , \
  138.        -perm -o=x -fprint allexec \)
  139.      
  140.      echo "Directories that can be written to by everyone:"
  141.      cat allwrite
  142.      echo ""
  143.      echo "Directories with search permissions for everyone:"
  144.      cat allexec
  145.    `find' has only to make one scan through the directory tree (which
  146. is one of the most time consuming parts of its work).
  147. File: find.info,  Node: Databases,  Next: File Permissions,  Prev: Common Tasks,  Up: Top
  148. File Name Databases
  149. *******************
  150.    The file name databases used by `locate' contain lists of files that
  151. were in particular directory trees when the databases were last
  152. updated.  The file name of the default database is determined when
  153. `locate' and `updatedb' are configured and installed.  The frequency
  154. with which the databases are updated and the directories for which they
  155. contain entries depend on how often `updatedb' is run, and with which
  156. arguments