Last active
November 13, 2016 13:13
-
-
Save piaoger/87bb91638deab51149d45d790358e135 to your computer and use it in GitHub Desktop.
handling date in linux bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I want compress yesterday's log, so I have to learn how to get yesterday with bash | |
# yesterday=$(date --date='-1 day' +%Y-%m-%d) | |
# today=$(date +%Y-%m-%d) | |
# yesterday_log=service_log_${yesterday}.log | |
# zip ${yesterday_log}.zip ${yesterday_log} | |
## today | |
today=$(date +%Y-%m-%d) | |
## Yesterday | |
yesterday_one=$(date --date='1 day ago' +%Y-%m-%d) | |
yesterday_two=$(date --date='-1 days' +%Y-%m-%d) | |
echo $yesterday_one | |
echo $yesterday_two | |
## tomorrow | |
tomorrow_one=$(date --date='1 day' +%Y-%m-%d) | |
tomorrow_two=$(date --date='+1 days' +%Y-%m-%d) | |
echo $tomorrow_one | |
echo $tomorrow_two | |
## other (second/minute/hour/week/month/year) | |
## more exmaples | |
date -d "-1 month" | |
date -d "-1 months" | |
date -d "+1 month" | |
date -d "+1 months" | |
date -d "-1 year" | |
date -d "-1 years" | |
date -d "+1 year" | |
date -d "+1 years" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment