Last Updated: February 25, 2016
· bear

generate date based filenames

Most folks are aware that you can use:

FOO=`date +%Y%m%d%H%M%S`

to generate a date formatted string, but, did you also know that it is very good at calculating a date using expressions?

BAR=`date +%Y%m%d%H%M%S --date="1 day ago"`
BAZ=`date +%Y%m%d%H%M%S --date="+ 1 day 2 hours"`

very handy if you need to process logs for a previous date and/or time range

START=`date +%Y%m%d%H%M%S --date="1 day ago"`
END=`date +%Y%m%d%H%M%S --date="1 hour ago"`

Now actually extracting the matching log lines is for another tip...

Say Thanks