title: Using `cp` within `find` while preserving directory structure (bash)
body: <p>This is a specific question about using <code>cp</code> within <code>find</code> while preserving directory structure. This is the way that seems like it should work, but perhaps there is a way to do it better. The reason I am using <code>find</code> is because I only want to copy files of a certain age.</p>
  
  <p>I have a directory structure like this. The operating system is Ubuntu 16.04.</p>
  
  <pre><code>folders
     folder1
       file1.txt
     folder2
       file1.txt
       file2.txt
     folder3
       file1.txt
  </code></pre>
  
  <p>I am using the <code>cp</code> command within the <code>find</code> command, as so...</p>
  
  <pre><code>find "$pathtofolder"/* -mmin +"$timeinmins" -type f -name "*.txt" -exec cp --parents {} /var/www/website/archives \;
  </code></pre>
  
  <p>The <code>--parents</code> flag copies the entire path to the files so I get something like <code>archives/var/www/website/folders/folder1/file1.txt</code>. This is not what I'm going for. I just want <code>archives/folder1/file1.txt</code>.</p>
  
  <p>The <code>-R</code> and <code>-a</code> flags do not work in this statement within <code>find</code>. When I use either one of them they seem to stop the copy from happening at all.</p>
  
  <p>What am I doing wrong? Is there a better way to do this?</p>
  
  <p>Thanks very much.</p>