title: Simple script needed to delete all docker images older than 4 weeks
body: <p>I know similar questions have been asked before, but I cannot find anything that does exactly what I need. I've also asked on the Docker Community forums, but nobody could help.</p>
  
  <p>I don't have access to the new <code>docker image prune</code> command, as I cannot upgrade from my current version 1.11.2 to the latest whizzy 1.13 yet, but I need a simple script that can be run under cron to remove all images, whether dangling or not, over 1 month old.  I don't need to worry about containers, as this is from a repo that only stores images.</p>
  
  <p>If docker images reported "4 weeks" as "1 month" it would be simple, I could use something like</p>
  
  <pre><code>docker images | grep " [months]* "
  </code></pre>
  
  <p>and pipe the output to the <code>docker rmi</code> command. However, since it appears to report in "weeks" up to 11 weeks, and only "months" once the image is 3 months old or over, I can't do this.</p>
  
  <pre><code>docker images | grep " [months|weeks]* ago" | awk '{print $3,$4,$5}'
  </code></pre>
  
  <p>will give me this output::</p>
  
  <pre><code>6828f152f9cc 2 weeks
  52a7412befd3 2 weeks
  04c2b29e5e08 2 weeks
  cdfb37d22663 2 weeks
  ca38a8cabb2b 3 weeks
  8b043f2395ba 3 weeks
  2aa8b20380a0 3 weeks
  1ac7dcf35935 9 weeks
  f80873c4845b 9 weeks
  d5700d37ee95 9 weeks
  594dc21de8de 9 weeks
  0c9dacb7fa7c 10 weeks
  11f3eec60e17 3 months
  b13ebf1a4999 3 months
  68b0d6a3be3b 7 months
  baadc9c8b0ce 8 months
  10eb0d6b2b99 9 months
  </code></pre>
  
  <p>... but I'm stuck trying to figure out how to test $4,$5 to only include anything that's either "months" or >= "4 weeks" which can then be piped through to docker rmi . Anyone any clues for a simple bit of code that can do this, please?</p>