System and processes
The timeout command
Runs a command and stops it if it takes longer than allowed. Ideal for scripts and tests.
Syntax
timeout DURACIÓN COMANDOMost useful options
-s SEÑALThe signal it uses to stop it (TERM by default)s, m, h, dTime suffixes (timeout 30s, timeout 2m)Copy-ready examples
$ timeout 2 sleep 1Finishes within the time$ timeout 10 ping -c 2 google.comLimits a network testYou can try them in the browser terminal: it does not touch your computer.
Typical mistakes
- If it cuts the command, it returns code 124: that warns you that time ran out.
- With no suffix, the duration is in seconds.
FAQ
Can I give it more time without changing the command?
Yes, by increasing the duration: timeout 30 instead of timeout 5.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course