Find

From ZENotes
(Difference between revisions)
Jump to: navigation, search
m (1 revision)
 
Line 2: Line 2:
  
  
 +
  find . -name '*.sho'
 +
 +
 
  
 
     find htdocs -name '*.html' -print0 | xargs -0 chmod a+r  
 
     find htdocs -name '*.html' -print0 | xargs -0 chmod a+r  

Latest revision as of 13:15, 24 March 2016

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 . -name '*.sho'


   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