title: Retaining n most recent directories in a backup script
body: <p>I have directory in <code>/home/backup/</code> that stores yearly backups. Inside the backup folder, we have these directories:</p>
  
  <pre><code>/home/backup/2012
  /home/backup/2013
  /home/backup/2014
  /home/backup/2015
  /home/backup/2016
  /home/backup/2017
  </code></pre>
  
  <p>and every year I have to clean up the data, keeping only the last three years of backup.</p>
  
  <p>In the above case, I have to delete:</p>
  
  <pre><code>/home/backup/2012
  /home/backup/2013
  /home/backup/2014
  </code></pre>
  
  <p>What is the best way to find the directories to be deleted?  I have this but it doesn't work:</p>
  
  <pre><code>find /home/ecentrix/recording/ -maxdepth 1 -mindepth 1 -type d -ctime +1095 -exec rm -rf {} \;
  </code></pre>
  
  <p>Do you guys have another idea to do that?</p>