title: How to limit grep to only search the files that you want
body: <p>We have a rather large and complex file system and I am trying to generate a list of files containing a particular text string. This should be simple, but I need to exclude the './svn' and './pdv' directories (and probably others) and to only look at files of type *.p, *.w or <em>.i</em>.</p>
  
  <p>I can easily do this with a program, but it is proving very slow to run. I want to speed up the process (so that I'm not searching thousands of files repeatedly) as I need to run such searches against a long list of criteria.</p>
  
  <p>Normally, we search the file system using:</p>
  
  <pre><code>find . -name "*.[!r]*" -exec grep -i -l "search for me" {} \;
  </code></pre>
  
  <p>This is working, but I'm then having to use a program to exclude the unwanted directories , so it is running very slowly.</p>
  
  <p>After looking at the topics here:
  <a href="https://stackoverflow.com/questions/221921/grep-exclude-include-syntax-do-not-grep-through-certain-files">Stack Overflow thread</a></p>
  
  <p>I've decided to try a few other aproaches:</p>
  
  <pre><code>grep -ilR "search for me" . --exclude ".svn" --excluse "pdv" --exclude "!.{p,w,i*}" 
  </code></pre>
  
  <p>Excludes the './svn', but not the './pdv' directories, Doesn't limit the files looked at.</p>
  
  <pre><code>grep -ilR "search for me" . --exclude ".svn" --excluse "pdv" --include "*.p" 
  </code></pre>
  
  <p>Excludes the './svn', but not the './pdv' directories, Doesn't limit the files looked at.</p>
  
  <pre><code>find . -name "*.[!r]*" -exec grep -i -l ".svn" | grep -i -l "search for me" {} \;
  </code></pre>
  
  <p>I can't even get this (or variations on it) to run successfully.</p>
  
  <pre><code>find . ! -name "*.svn*" -prune -print -exec grep -i -l "search for me" {} \;
  </code></pre>
  
  <p>Doesn't return anything. It looks like it stops as soon as it finds the .svn directory.</p>