Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've been trying to find a decent way to monitor elapsed time in the shell. Basically, I'm asking for a stopwatch. The end result is easy enough to accomplish; I've seen examples of using time read, and then hitting enter when you're done, but that method makes the current terminal unusable.

Ideally, I'd like something like:

timer start
(do some work, vim, python, etc.)
timer stop

It also would be nice if there was a way to pause the timer. For reference, I was planning on using it to time how long it takes to finish programming assignments from MIT's OCW. As such, since the assignments might be completed in more than one sitting, a way to pause and continue the timer would be beneficial.

Is there anything like this?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You may try a shell script (call it timer.sh) like this:

. timer.val

case "$1" in 
  start)
   echo $TIMERSTART
   echo "TIMERSTART=`date +%s`" > timer.val
   echo $TIMERSTART
   ;;
  stop)
   echo $TIMERSTART
   TIMEREND=`date +%s`
   echo $TIMEREND
   let RESULT=$TIMEREND-$TIMERSTART
   echo $RESULT
   ;;
  *)
   echo "no command"
esac
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.