title: How to recursively remove all files in a directory except specific file type and folder?
body: <p>Assume I have a directory which contains:</p>
  
  <pre><code>.\Folder\Folder1\exe\a.exe
  .\Folder\Folder1\dll\b.dll
  .\Folder\Folder1\txt\c.txt
  .\Folder\Folder2\exe\a.exe
  .\Folder\Folder2\dll\b.dll
  .\Folder\Folder2\txt\c.txt
  .
  .
  .
  </code></pre>
  
  <p>Now I want to recursively remove from .\Folder\ except all *.txt, such that:</p>
  
  <pre><code>.\Folder\Folder1\exe\
  .\Folder\Folder1\dll\
  .\Folder\Folder1\txt\c.txt
  .\Folder\Folder2\exe\
  .\Folder\Folder2\dll\
  .\Folder\Folder2\txt\c.txt
  .
  .
  .
  </code></pre>
  
  <p>Could anyone please suggest the command for using rm to do the job? Thanks!</p>
  
  <h2>I tried:</h2>
  
  <pre><code>cd .\Folder
  shopt -s extglob
  </code></pre>
  
  <h2>    rm -rf !("*.txt")</h2>
  
  <p>but it delete all files and directory inside .\Folder</p>