How to Run Commands Repeatedly Using the watch Command in Linux

When you are monitoring the execution of a massive, long-running background process on a Linux server, typing a status command (like ls or free) over and over again manually is completely inefficient. It breaks your concentration and guarantees you will miss the exact millisecond a critical metric changes. To mathematically force the Linux kernel to execute a command repeatedly and render the output as a seamless, full-screen dashboard, you must use the watch command.

Executing the Full-Screen Dashboard

The watch command is an aggressive execution engine. It acts as a wrapper around any standard Linux command, physically clearing the terminal screen, running the target command, rendering the output, and then violently looping the process infinitely until you kill it.

If you need to monitor the server’s RAM consumption in real-time, you do not type free -m repeatedly. Instead, you wrap it in the engine:

watch free -m

The exact millisecond you press Enter, your standard terminal prompt vanishes. The engine hijacks the entire screen, executing the free -m command exactly every 2.0 seconds. The output remains statically locked on the screen, but the numbers will dynamically update in real-time, providing you with a pristine, continuously updating memory dashboard.

To mathematically terminate the engine and return to the standard prompt, you must press Ctrl + C.

Modifying the Loop Architecture

The default 2-second loop is highly efficient, but if you are monitoring a hyper-critical process (like an ongoing file download), you may need instantaneous updates. You can mathematically force the engine to accelerate the loop by injecting the -n (interval) flag.

watch -n 0.5 ls -l /downloads/massive_file.iso

This command instructs the engine to violently execute the ls command every 0.5 seconds (half a second). The screen will update so rapidly it acts as a real-time progress bar, allowing you to watch the file size increase dynamically.

Highlighting Data Differences

If you are monitoring a massive block of text and cannot easily spot the numbers changing, you can inject the -d (differences) flag.

watch -d free -m

The engine will execute the loop, but it will mathematically compare the current output to the previous output. The exact millisecond a specific integer changes on the screen, the engine will violently highlight it in bright white, guaranteeing you instantly identify the fluctuating metric.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.