Skip to content

Latest commit

 

History

History
22 lines (15 loc) · 844 Bytes

2016-02-10-using-gnudate-to-go-back-one-month.md

File metadata and controls

22 lines (15 loc) · 844 Bytes
title author date url thumbnail categories
Using GNU/date to go back one month
svennd
2016-02-10 08:59:53 +0000
/using-gnudate-to-go-back-one-month/
/img/2021/03/simon-stratford-_ILkd7aVqAM-unsplash.jpg
Linux

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!