BASH Time and Date

From Indie IT Wiki
Jump to: navigation, search

Time Between File Timestamps

SECONDS=$((stat --printf '%Y' /home/paully/hb.finished; printf ' - '; stat --printf '%Y\n' /home/paully/hb.started) | bc -lq) && 
TIMETAKEN=$(date -ud "@$SECONDS" +'$((%s/3600/24)) days %H hours %M minutes %S seconds') && 
printf "${INPUTFILESIZE}\n\n${OUTPUTFILESIZE}\n\n${SECONDS}\n\n${TIMETAKEN}"

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

timedatectl status
ntpstat
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"