How can I track time from the command-line?
This answer suggests to use
time cat
and use Ctrl-D to see the time.
You can also use
time read
and use Enter key
Also check this answer on the same question
How about:
stopwatch() {
local start=$SECONDS
read -p "Hit Enter..."
echo $((SECONDS-start)) seconds elapsed
}
In action:
$ stopwatch
Hit Enter...
14 seconds elapsed
Simple way of doing it is to take start time, and once you stop the script - take stop time. Finally, print the time difference. This can easily be done with Python:
python -c $'import time;start=time.time();\ntry:\n\twhile True: time.sleep(0.25)\nexcept: print(time.time()-start)'
Or long version for readability:
import time
start=time.time();
try:
while True: time.sleep(0.25)
except:
print(time.time()-start)
Stopping is done with Ctrl+C