You can use watch -n seconds or –interval seconds option to specify update interval. The command will not allow quicker than 0.1 second interval, in which the smaller values are converted. Both ‘.’ and ‘,’ work for any locales. The WATCH_INTERVAL environment can be used to persistently set a non-default interval (following the same rules and formatting).
Example:
Create and execute a script that inserts 1 item every 1 sec indefinitely:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
## create a script to insert 1 item every 1 second indefinitely cat << 'EOF' > myscript.sh #!/bin/bash > myfile i=1; while : do echo "$i" >> myfile sleep 1 ((i++)) done EOF ## execute the script in the background chmod +x myscript.sh ./myscript.sh & |
watch -n seconds or –interval seconds option example:
1 2 3 4 5 6 7 8 |
## deafult watch tail myfile ## refresh the output every 2 seconds (default) ## watch -n seconds or --interval seconds option watch -n 10 tail myfile ## refresh the output every 10 seconds pkill -f "myscript.sh" ## kill myscript.sh rm my* |