How to get a previous date in bash (linux)

Simply put

date -d '1 day ago' +'%Y-%m-%d'
# For multiple days
date -d '7 days ago' +'%Y-%m-%d'

If you wish to place in a shell script:

RMDATE=$(date -d '7 days ago' +'%Y_%m_%d')

will place for example ‘2013-07-01’ in the RMDATE variable which of course you can use like

echo $RMDATE

 

You may also like...

Leave a Reply