Last Updated: February 25, 2016
·
2.141K
· teito79

Bash elapsed time

If you wish to calculate elapsed time when running bash scripts:

#!/bin/bash

T="$(date +%s)" 
sleep 2
T="$(($(date +%s)-T))"
echo "Time in seconds: ${T}"

The +%s parameter makes the date command return a timestamp.
Then it is simply substracted (and printed).