Calculating Execution Time for a Bash Script

Sometimes you want to know how long the script takes to execute. Here are the basic steps…
1-Get the starting time
2-Get the end time
3-Subtract (endTime – startTime).

startTime=$(date +%s)
##### code here ##########
endTime=$(date +%s)
diff=$((endTime - startTime))
echo "Elapse time is $((diff/60)) minutes and $((diff%60)) seconds"
Share This!

Add a Comment

Your email address will not be published.

Sign up for our Newsletter

Download "Google Search Pro"

Enter your email and stay on top of things,

Subscribe!