Find

From ZENotes
Revision as of 23:59, 14 October 2011 by Admin (Talk | contribs)
Jump to: navigation, search

Here is an example operation to make all HTML files in the subdirectory htdocs readable by all using find and xargs. This is a typical example of how find and xargs are used with other utilities to provide powerful directory traversal capability.


   find htdocs -name '*.html' -print0 | xargs -0 chmod a+r 

Say:

  find somewhere -name 'thenameyouarelookingfor' 

and so on and so on


The following examples illustrate typical uses of the command find for finding files on a computer.

   find / -name game

Looks for a file named "game" starting at the root directory (searching all directories including mounted filesystems). The `-name' option makes the search case sensitive. You can use the `-iname' option to find something regardless of case.

   find /home -user joe

Find every file under the directory /home owned by the user joe.

   find /usr -name *stat

Find every file under the directory /usr ending in "stat".

   find /var/spool -mtime +60

Find every file under the directory /var/spool that was modified more than 60 days ago.

   find /tmp -name core -type f -print | xargs /bin/rm -f

Find files named core in or below the directory /tmp and delete them. Note that this will work incorrectly if there are any filenames containing newlines, single or double quotes, or spaces.

   find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f

Find files named core in or below the directory /tmp and delete them, processing filenames in such a way that file or directory names containing single or double quotes, spaces or newlines are correctly handled. The -name test comes before the -type test in order to avoid having to call stat(2) on every file.

   find . -type f -exec file '{}' \;
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox