title: How to get the last month? date +%Y%m -d '1 month ago' doesn't work on March 30
body: <p>I wrote a script to delete old files. Part of the script is following: </p>
  
  <pre><code>lastmonth=`date +%Y%m -d '1 month ago'`
  inputdir0=/var/this/directory/${lastmonth}*
  
  if [ `date +%d` -gt 9 ];
  then        
      rm -Rf $inputdir0
  fi
  </code></pre>
  
  <p>There are some directories named after the date +%Y%m%d format.
  Now it's March 29/30/31 and the script deleted all files of this month.
  Today I learned this happens because there is no February 29/30/31.</p>
  
  <p>How can i fix this? </p>