title: How to copy all files from a directory and its subdirectories to another dir?
body: <p>I have a <code>/dir1</code>, the structure is:</p>
  
  <pre><code>./aaa.txt
  ./bbb.jpg
  ./subdir1/cccc.doc
  ./subdir1/eeee.txt
  ./subdir2/dddd.xls
  ./subdir2/ffff.jpg
  </code></pre>
  
  <p>I want to copy all <code>.txt</code> and <code>.jpg</code> in <code>/dir1</code> and its subdirectories to <code>/dir2</code>.</p>
  
  <p>By using <code>cp -r /dir1/* /dir2</code>, it copies all files and its structure to <code>/dir2</code>.</p>
  
  <p>By using <code>cp -r /dir1/*.jpg /dir2</code> and <code>cp -r /dir1/*.txt /dir2</code>, it doesn't copy the <code>.jpg</code> and <code>.txt</code> files in the subdirectories.</p>
  
  <p>By using</p>
  
  <pre><code>for FILE in `find`
  do
    cp -f $FILE /dir1/
  done
  </code></pre>
  
  <p>it can copy all files in dir and subdirectories to the destination, but I cannot filter the file type.</p>
  
  <p>Is there another way that can achieve what I want?</p>