The watch
command is a useful utility in Unix-like systems that allows you to execute a command periodically and display its output. However, macOS does not come with watch
pre-installed. If you’re running macOS Sequoia and want to use watch
, follow the steps below to install it.
Recently i switch my mabook to a new MacBook Pro M2 and try to use the command to watch some openshift logs and i got the following result:
To install just use Homebrew.
brew install watch
Using watch
on macOS
Now that watch
is installed, you can start using it. The basic syntax is:
watch -n <seconds> <command>
For example, to monitor the disk usage of your system every two seconds, you can run:
watch -n 2 df -h
Additional Options
-d
: Highlights the differences between updates.-t
: Turns off the title/header display.-b
: Beeps if the command exits with a non-zero status.
Alternative: Using a while
Loop
If you prefer not to install watch
, you can achieve similar functionality using a while
loop in the terminal:
while true; do <command>; sleep <seconds>; done
For example:
while true; do df -h; sleep 2; done
This method works in any macOS version without requiring additional installations.