Taming `watch` for Real-Time Command Output
Quick Tip
Taming `watch` for Real-Time Command Output
Challenge: You need to monitor the output of a command that changes frequently (e.g., system load, file changes, network traffic) without manually re-executing it.
The Solution: Use the `watch` command to repeatedly execute a command and display its output in full-screen.
watch -n 2 'ls -l'
Why it works: The `watch` command executes the specified command (`ls -l` in this case) at a regular interval (every 2 seconds, set by `-n 2`). It then clears the screen and displays the new output, allowing you to observe changes in real-time.
Pro-Tip: Combine `watch` with `-d` to highlight differences between updates, making changes even more obvious. For example: watch -d -n 1 'diff file1.txt file2.txt'
Linux Tips & Tricks | © ngelinux.com | 5/7/2026
