Date command has d parameter, that displays time described after d parameter:
date -d yesterday '+%Y-%m-%d'
%Y means year, %m means month, and %d means day. You can change formatting if you want:
date -d yesterday '+%Y:%m:%d'
What if you want get several days, for example day before 5 days?
date +%Y-%m-%d -d "5 day ago"
Would you take yesterday date to variable?
YESTERDAY=`date -d yesterday '+%Y-%m-%d'` echo $YESTERDAY
Alternative way is using hours:
date -d "24 hours ago" '+%Y-%m-%d'
date --date='-1 day' '+%Y-%m-%d'
We prepared for you video course Marian's BASH Video Training: Mastering Unix Shell, if you would like to get much more information.
Thank you. Marian Knezek