⏱️ Command: watch (The Real-Time Observer)
The watch command is used to run any command repeatedly at a specific interval, allowing you to monitor its output in real-time. It turns a static, one-time command into a live dashboard.
1. The "Why"
For an Arch Linux power user and developer, watch is the ultimate tool for monitoring state changes:
- Monitoring Progress: Instead of manually typing
ls -lhover and over to see if your project's build file is growing,watchdoes it for you. - Network Diagnostics: Combined with
ssornetstat, you can watch connections to your Supabase backend open and close. - Hardware Tracking: Watch your CPU clock speeds or temperature during a heavy work.
- Process Management: Keep an eye on
psorjobsto see exactly when a background task finishes.
2. Basic Syntax
watch [options] command
By default, watch runs the command every 2 seconds.
3. Essential Flags
| Flag | Purpose | Use Case |
|---|---|---|
-n [sec] |
Interval | Change the timing (e.g., -n 1 for every second, or -n 60 for every minute). |
-d |
Differences | Highlights the text that has changed since the last update. |
-t |
No Title | Removes the header showing the interval and current time (useful for clean screenshots). |
-g |
Exit on Change | Stops the command as soon as the output of the command changes. |
4. Practical Examples for Your Workflow
A. Monitoring a File Download or Build
If you are using dd or a build script and want to watch the file size increase in your current folder:
watch -n 1 ls -lh
B. Tracking Network Connections
To see who is connecting to your machine in real-time :
watch -d "ss -tupn"
The -d flag will highlight new connections as they appear.
C. Watching System Load
If you want a live view of your uptime and load averages :
watch uptime
D. Checking Battery/Thermal Status
On Arch Linux, you can often watch your hardware sensors directly:
watch -n 5 cat /sys/class/thermal/thermal_zone0/temp
5. Advanced Usage: Using Pipes
If your command includes pipes (|), you must wrap the entire command in quotes. Otherwise, the shell will try to pipe the output of watch itself rather than the command inside it.
- Wrong:
watch ls | grep "Preader" - Right:
watch "ls | grep Preader"
6. Pro-Tips
- High Precision:
watchsupports sub-second intervals. Usewatch -n 0.1for a very fast, nearly-continuous update. - Arch Linux Context: If you are configuring Waybar or Hyprland and want to see if your config changes are being picked up by the system logs, use:
watch "journalctl -xe | tail -n 10" - Tutorial Tip: In your technical tutorials,
watchis a great tool to recommend for students who are learning about "polling" vs. "interrupts"—it’s a visual representation of the polling concept.
7. Summary Reference
| Goal | Command |
|---|---|
| Default (2s interval) | watch [cmd] |
| 1s interval + Highlight | watch -n 1 -d [cmd] |
| Exit when output changes | watch -g [cmd] |
| Hide the header | watch -t [cmd] |