This is a great way to monitor a directory for changes every 5 seconds as an example, or monitor a large files changing size as you move it from one server to another.
the watch
command.
Usage: watch [-dhntv] [--differences[=cumulative]] [--help] [--interval=<n>]
[--no-title] [--version] <command>`
So that:
watch -n1 command
will run the command every second (well, technically, every one second plus the time it takes for command
to run as watch
(at least the procps
and busybox
implementations) just sleeps one second in between two runs of command
), forever.
Would you want to pass the command to exec
instead of sh -c
, use -x
option:
watch -n1 -x command