Cyberithub

How to Install watch command on MacOS Using 7 Easy Steps

Advertisements

In this article, I will take you through the steps to install watch command on MacOS Using 7 Easy Steps. watch is a very simple yet very useful command line utility that automatically display the output of any arbitrary command at certain regular interval of time. This utility is particularly useful in a scenario where you need to manually enter a command periodically to check any change in output. Hence saving us from entering same command again and again. Along with that, it also provides few more features that proves to be very useful at certain times. watch utility is available through procps-ng formulae along with other set of utilities.

 

How to Install watch command on MacOS Using 7 Easy Steps

How to Install watch command on MacOS Using 7 Easy Steps

Also Read: How to Install Podman on MacOS Using 8 Easy Steps

Step 1: Prerequisites

a) You should have running MacOS System.

b) You should have a valid user account.

c) You should have homebrew or MacPorts installed in your System.

 

Step 2: Update Your System

Before installing watch command on MacOS, it is important to first update all the formulae using brew update command as shown below.

[cyberithub@mac1066 ~ % brew update

 

Step 3: Install watch command

In the next step, you can install watch command by using any of the below method depending on your requirement.

a) Using Homebrew

If you would like to install watch command using homebrew utility then you need to use brew install watch command as shown below.

[cyberithub@mac1066 ~ % brew install watch
==> Fetching watch
==> Downloading https://ghcr.io/homebrew/core/watch/manifests 4.0.3
##################################################################################################################################################################### 100.0%
==> Downloading https://ghcr.io/homebrew/core/watch/blobs/sha256:cdf2be215979e9529f232f8fbc444dfe2cfe025a8301e529248c1d8a0040ec3
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:cdf2be215979e9529f232f8fbc444dfe2cfe025a8301e529248c1d8a0040ec3?se=2023-04-2
##################################################################################################################################################################### 100.0%
==> Pouring watch--4.0.3.monterey.bottle.tar.gz
    /usr/local/Cellar/watch/4.0.3: 10 files, 143.3KB
==> Running `brew cleanup watch`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /Users/cyberithub/Library/Caches/Homebrew/glib--2.76.1... (6.3MB)
Removing: /Users/cyberithub/Library/Caches/Homebrew/qemu--7.2.1... (98MB)
Removing: /Users/cyberithub/Library/Logs/Homebrew/mpdecimal... (64B)
Removing: /Users/cyberithub/Library/Logs/Homebrew/readline... (64B)
Removing: /Users/cyberithub/Library/Logs/Homebrew/sqlite... (64B)
Removing: /Users/cyberithub/Library/Logs/Homebrew/python@3.11... (2 files, 2.5KB)

b) Using MacPorts

If you would like to install watch command using MacPorts then you need to use sudo port install watch command as shown below.

[cyberithub@mac1066 ~ % sudo port install watch

 

Step 4: Check Version

After successful installation, you can check the installed version by using watch --version command as shown below.

[cyberithub@mac1066 ~ % watch --version
watch from procps-ng 4.0.3

 

Step 5: Using watch command

Now that watch command is installed in your Mac system, it is time to test it by watching the output of kubectl get pods using watch kubectl get pods command as shown below. By default, this will display the output and update any change in output every 2 seconds.

[cyberithub@mac1066 ~ % watch kubectl get pods

If you want to increase the time interval then you need to use -n option and specify the interval in seconds. For example, if you want to check any change in output every 5 seconds then you need to use watch -n 5 kubectl get pods command as shown below.

[cyberithub@mac1066 ~ % watch -n 5 kubectl get pods

 

Step 6: Check all the Available Options

You can check all the options available with watch command using watch --help as shown below.

[cyberithub@mac1066 ~ % watch --help

[Usage:
 watch [options] command

Options:
  -b, --beep              beep if command has a non-zero exit
  -c, --color             interpret ANSI color and style sequences
  -d, --differences[=<permanent>]
                          highlight changes between updates
  -e, --errexit           exit if command has a non-zero exit
  -g, --chgexit           exit when output from command changes
  -q, --equexit <cycles>  
                          exit when output from command does not change
  -n, --interval <secs>   seconds to wait between updates
  -p, --precise           attempt run command in precise intervals
  -r, --no-rerun          do not rerun program on window resize
  -t, --no-title          turn off header
  -w, --no-wrap           turn off line wrapping
  -x, --exec              pass command to exec instead of "sh -c"

-h, --help     display this help and exit
-v, --version  output version information and exit

For more details see watch(1).

 

Step 7: Uninstall watch command

Once you are done using watch command, you can choose to uninstall it from your system by using any of the below method depending on how you have installed it.

a) Using Homebrew

If you installed through homebrew utility then to uninstall you need to use brew remove watch command as shown below.

[cyberithub@mac1066 ~ % brew remove watch
Uninstalling /usr/local/Cellar/watch/4.0.3... (10 files, 143.3KB)

b) Using MacPorts

If you installed through MacPorts then you need to use sudo port uninstall watch command as shown below.

[cyberithub@mac1066 ~ % sudo port uninstall watch

Leave a Comment