Date work often plays an important part in automated bash scripts, and as such, it is pretty useful to be able to calculate yesterday’s date for your variable work.

Now we know in order to get the current date we could use this:

NOW="$(date +"%Y/%m/%d")"

Using this info, we find that it is remarkably simple to get yesterday’s date on any Linux system with:

YESTERDAY="$(date -d 'yesterday' +%Y/%m/%d)"

There are a range of other date manipulating strings available, including things like “3 days ago”, “next Monday”, “2 months”, etc, most of which can be found on the info date entry.

Nifty.