Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I needed a timer which will start at the very beginning of the script and stops at the end.Can anyone help me with that?

share|improve this question
please, write a goal you want to achieve. to measure script working time use time command ( time ./script.sh ), to printout current time use date command and so on. – rush Nov 4 '12 at 21:06
up vote 13 down vote accepted

If you want the duration in seconds, at the top use


and at the end

duration=$(( SECONDS - start ))
share|improve this answer
What if it takes more than seconds? – Pithikos Oct 17 '14 at 16:49

You could use Linux's built-in time command. From the man page:

time COMMAND [arguments]

time determines which information to display about the resources used by the COMMAND from the string FORMAT. If no format is specified on the command line, but the TIME environment variable is set, its value is used as the format.

To time the cleanup.sh script, use:

$ time cleanup.sh
share|improve this answer
This should be the accepted answer. – so.very.tired Mar 2 at 8:58

Your Answer


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.