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 want know how I can run a command for a specified time say, one minute and if it doesn't complete execution then I should be able to stop it.

share|improve this question
up vote 27 down vote accepted

Use timeout:

       timeout - run a command with a time limit

       timeout [OPTION] DURATION COMMAND [ARG]...
       timeout [OPTION]

(Just in case, if you don't have this command or if you need to be compatible with very very old shells and have several other utterly specific requirements… have a look at this this question ;-))

share|improve this answer
Perfect, thanks for linking to that question. I didn't have timeout on my system but I do now. Just on a side note, is timeout bundled with the majority of linux distributions? – nikhil Oct 24 '11 at 4:28
Pretty cool. you can do something like this: for i in `seq 0 3`; do timeout 2 ethtool -p eth$i; done; to blink LED's on NIC's – user1527227 Jun 19 '14 at 16:42

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.