title: How to clean up folders efficiently using shell script
body: <p>I am using a directory structure with various folders. There are new files created daily in some of them. </p>
  
  <p>I have created some programs to clean up the directories, but I would like to use a shell script to make it more efficient.</p>
  
  <p>Therefore I would like to store an "<strong>archiving.properties</strong>" file in every folder that needs to be cleaned up. The properties file should contain the following variables</p>
  
  <pre><code>file_pattern="*.xml"
  days_to_keep=2
  </code></pre>
  
  <p>Now my clean up routine should:</p>
  
  <ol>
  <li>find all properties files </li>
  <li>delete all files that match the file name pattern (file_pattern) and that are older then the defined number of days (days_to_keep) in the directory where the properties file was found.</li>
  </ol>
  
  <p>So my question is how can I do this in the most efficient way?</p>
  
  <pre><code>find . -type f -name "archiving.properties"  -print
  find . -type f -name "&lt;file_pattern&gt;"  -mtime +&lt;days_to_keep&gt; -delete
  </code></pre>
  
  <p>currently I was trying the following in a single folder. It prints out the command correctly, but it is not executed. </p>
  
  <pre><code>#!/bin/bash
  . archiving.properties
  find . -type f -name "*.xml"  -mtime +1 -exec rm -rf {} \;
  echo "    find . -type f -name \"${file_pattern}\"  -mtime +${days_to_keep} -exec rm -rf {} \;" 
  
  
  Result is:    find . -type f -name "*.xml"  -mtime +1 -exec rm -rf {} \;
  </code></pre>
  
  <p>Thanks for your help in advance.</p>