title: remove all but last 5 directories with shell script and find command
body: <p>-not sure if this belongs here or on serverfault-</p>
  
  <p>What I want to do it list all directories in a directory and delete all of them, except for the last 5. We have a deployment system in place that will incrementally do something link this:</p>
  
  <pre><code>/var/www/html/build1
  /var/www/html/build2
  /var/www/html/build3
  /var/www/html/build4
  /var/www/html/build5
  /var/www/html/build6
  /var/www/html/build7
  /var/www/html/build8
  /var/www/html/build9
  /var/www/html/build10
  </code></pre>
  
  <p>This is using up way too much disk space so we only want to keep the last 5 builds.</p>
  
  <p>I came up with the following:</p>
  
  <p>(find /var/www/html/ -type d -name "build*" | sort -r)
  /var/www/html/build1564
  /var/www/html/build1563
  /var/www/html/build1560
  /var/www/html/build1558
  /var/www/html/build1557
  /var/www/html/build1556
  /var/www/html/build1555
  /var/www/html/build1554
  /var/www/html/build1553
  /var/www/html/build1552
  /var/www/html/build1551
  /var/www/html/build1550</p>
  
  <p>now all I need to do is add an "offset" to that command, so that the first five directories don't show up. After that, the remaining directories should be removed.</p>
  
  <p>If there are no more than 5 directories, nothing should happen.</p>
  
  <p>I guess I'm still missing two steps here, the offset step and the rm -rf step?</p>