SvennD
February 10, 2016

Using GNU/date to go back one month

Posted on February 10, 2016  •  1 minutes  • 95 words  •  Suggest Changes

GNU/date is really a nice tool, today I found this awesome option. (reading the man page … ahum) In a shell script I run in a cron I make a monthly store. (/year/month/day.ext) I wanted to store last months in a single archive.

I store the backup file :

BACKUP_PATH=/mnt/database_backup/$(date +%Y)/$(date +%m)/

this makes an easy /2016/01/01.db, /2016/01/02.db, … Now going back one month can be done with text ! Just tell date to go back “1 month ago”. How awesome is that !

BACKUP_PATH=/mnt/database_backup/$(date +%Y)/$(date +%m --date '1 month ago')/

great for simple cronnies!

Support

If you enjoyed this website, consider buying me a Dr. Pepper

Buy me a Dr PepperBuy me a Dr Pepper