BASH Time and Date

From Indie IT Wiki
Jump to: navigation, search

Ping With Time And Date Stamp

ping -i1 -c10 192.168.1.1 | while read pong; do echo "$(date '+%Y-%m-%d-%H:%M:%S')    $pong"; done

Time

Checking NTP

ntpstat
or
ntpq -pn

Thanks to Cyberciti

Convert Standard Date And Time To Epoch Time

date +%s

Convert Epoch Time To Standard Date And Time

date --date='@1335309835'

Date

Today

date

Yesterday

date -d "yesterday"

Number Of Days Between Two Dates

echo $"(( $(date --date="031122" +%s) - $(date --date="021020" +%s) ))/(60*60*24)"|bc

Number Of Days After

date -d "230 days"
or
date -d "24 weeks 2 days 4 hour 6 minutes"

Number Of Days Before

date -d "230 days ago"
or
date -d "24 weeks 2 days 4 hour 6 minutes ago"