TIL: timeout in Bash scripts

Here comes a handy utility: timeout. As the name suggests, this command adds a timeout to other commands. You specify the time limit you want to wait for a command and if that time passes, timeout sends a signal to terminate it and exits with non-zero. By default, timeout sends SIGTERM, but you can change it with the --signal flag, e.g. timeout --signal=SIGKILL 1s foo.

For example, timeout 1s sleep 5 will send the SIGTERM signal to sleep after 1 second.

(via)