Date and Time Functions in Bash


Bash is very powerful for handling dates and times, but you need to get to grips with it’s syntax. This article contains a few commonly used date and time functions that one could use when doing Bash scripts.

How to determine the time elapsed in Bash

START_TIME=$(date +%s)
echo -n Finding mp3 files
sleep 3 # some time consuming command
echo .\ Elapsed time: $(( $(date +%s)-START_TIME ))

How to echo the date in Bash

echo "Today is $(date)"

Sleep Times Reference

sleep .5 # Waits 0.5 second.
sleep 5 # Waits 5 seconds.
sleep 5s # Waits 5 seconds.
sleep 5m # Waits 5 minutes.
sleep 5h # Waits 5 hours.
sleep 5d # Waits 5 days.



Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top