work with date and time in Bash

Compare Time and Dates in Bash. And the Simplest Alarm on Bash

Using bash it is possible to compare time easily in epoch format. If you need to compare date like 14:23 with 14:17 you need to transform it to seconds since epoch and compare as two integers. Here it is my function in ~/.bashrc and examples


Bash: Count Minutes and Seconds since Start of a Process

Starting long process you may want to watch how much time is it going. This helps you to guess how much time remains.

Usually you run some process and then watch on it in another terminal window in a loop `while [ 1 ]`.

For example, need to count minutes since the process start. Algorithm and simple bash script are here.


1. Store the start time in seconds in a variable

start=$(date +%s)

This stores start point as POSIX time in seconds like: 1660042758