Recently I had to create a bash script to copy some files based on date.

The rule was copy yesterday’s files to …

But How to determine what was the yesterdays date?

The answer was in date man page.

Here are the parts from the script related to yesterday date:

$date -d '1 day ago' +'%Y/%m/%d'
2011/06/02

on Internet I’ve found also:

date --date='yesterday'
Thu Jun  2 14:01:28 EDT 2011

And (Bonus!!) if you want to go in future 😉

date --date='tomorrow'
Sat Jun  4 14:04:29 EDT 2011

Happy scripting…