Mastering Linux’s watch Command: Real‑Time Monitoring Made Easy
This guide explains how to use Linux’s watch command to repeatedly execute a program, customize the interval, highlight output changes, exit on updates, react to non‑zero exit codes, and suppress the header, providing practical examples for each option.
Linux provides the watch command for repeatedly executing a program and displaying its output in full‑screen mode, which is useful for monitoring changing information without writing custom loops.
Basic usage is simply: watch COMMAND By default, watch runs the specified COMMAND every two seconds and shows the result along with a header line indicating the interval, hostname, and timestamp.
To change the execution interval, use the -n INTERVAL option (seconds). For example, to run date every five seconds: watch -n 5 date The -d (or --differences) flag highlights differences between successive outputs, making it easy to spot changes: watch -d -n 1 date If you want the loop to stop as soon as the command’s output changes, use the -g (or --chgexit) option: watch -g free By default, watch ignores the command’s exit status. You can make it react to non‑zero exit codes by enabling a beep with -b or forcing an exit with -e (or --errexit): watch -e wrong_commands Finally, to hide the header line that shows the interval and timestamp, use the -t (or --no-title) option: watch -t date These options together allow flexible, real‑time monitoring of command output directly from the terminal.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
