Sign up ×
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 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 ./ ), to printout current time use date command and so on. – rush Nov 4 '12 at 21:06

2 Answers 2

up vote 9 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 script, use:

$ time
share|improve this answer

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.