06 June 2008

Date logic in Bash

You can generate strings that include relative date values using a script like:

#!/bin/sh
for n in 20 19 18 17 16 15 14 13 12 11;
do
d=`date +'%Y.%m.%d' -d "-${n} day"`
echo "Deleting ${d}"
rm -rf ./${d}
done