Linux Commands - watch command (run a command once every x seconds)

by
Jeremy Canfield |
Updated: December 07 2021
| Linux Commands articles
Let's say you have a script named foo.sh that will append "Hello World" to a txt file, like this.
#!/bin/bash
echo "Hello World - The current date and time is `date +%Y-%m-%s %H:%M:%S`" >> log.txt
The watch command can be used to run this script every x seconds. In this example, the foo.sh script will be run every 5 seconds.
watch -n 5 bash foo.sh
Something like this should be displayed.
Every 5.0s: foo.sh
Did you find this article helpful?
If so, consider buying me a coffee over at