At a glance
watchrefreshes every 2 seconds by default;-n SECONDStakes values from0.1to2678400(31 days).-dhighlights changes since the last update, and--differences=permanentkeeps every change highlighted.- Wrap pipes, redirects and variables in single quotes so
watchruns them throughsh -ceach time. -gexits when the output changes, and-estops when the command fails.
Run a command every N seconds
Running watch df -h clears your terminal, runs df -h every 2 seconds and fills the screen with the result. The top line shows a header such as Every 2.0s: df -h, followed by the hostname and the current time.
To change the wait between runs, pass -n (or --interval) with a number of seconds, or set the WATCH_INTERVAL environment variable for a new default. Fractions such as 0.5 work, anything below 0.1 is raised to 0.1, and anything above 2678400 is capped there.
watch df -h
watch -n 5 'ls -l /data'
watch -n 0.5 dateThese check disk space at the default 2-second rate, list /data every 5 seconds and print the time twice a second. Press Ctrl+C to quit and return to your prompt.
The options worth knowing
These are the flags you will use most when monitoring jobs and system state:
| Option | What it does | Example |
|---|---|---|
-n, --interval | Seconds between runs, 2 by default | watch -n 5 df -h |
-d, --differences | Highlights what changed since the last run | watch -d free -h |
-t, --no-title | Hides the header line | watch -t date |
-g, --chgexit | Exits when the output changes | watch -g ls /data/done |
-e, --errexit | Stops when the command fails and exits after a key press | watch -e ./check.sh |
-c, --color | Interprets ANSI colors | watch -c ls --color=always |
-p, --precise | Times each run from the start of the previous one | watch -p -n 1 date |
-x, --exec | Runs the command with exec instead of sh -c | watch -x ls -l |
procps-ng 4.0.4 on Debian 13 also has -q to exit when the output stops changing for a number of cycles, -r to skip reruns when the window is resized and -w to turn off line wrapping. Run watch --help to see what your version supports.
Quote pipes and shell syntax
watch passes your command string to sh -c. If you write a pipe, redirect or variable without quotes, your own shell handles it before watch starts, so it pipes the output of watch itself into the next command instead of rerunning the pipeline.
Wrap any command that uses |, > or $VAR in quotes. Single quotes keep your shell from expanding variables, so sh -c expands them fresh on every run, while double quotes expand them once before watch starts. If you don't need shell features, -x hands the command straight to exec, which saves you the extra quoting.
watch 'ps aux | grep [p]ython'
watch -n 1 'grep "^cpu MHz" /proc/cpuinfo | sort -nrk4'Both keep the pipe inside single quotes so it runs on every update. The second example comes from the watch man page and sorts your CPU cores by clock speed once per second.
Everyday watch commands
When a training job, data pipeline or batch script is running, a few short commands cover most of what you check in a second terminal pane:
nvidia-smifor GPU memory and utilization (see the nvidia-smi guide).free -hwith-d, so memory and swap numbers light up as they move.df -hon a disk that a pipeline fills with large intermediate files.ls -lt | head -5on an output directory to see the newest checkpoints arrive.kubectl get pods, thoughkubectl getalso has its own-w(--watch) flag that streams changes.squeue --meon a Slurm cluster, with a long interval such as-n 60, because the Slurm docs ask you not to runsqueuein loops.
watch -n 1 nvidia-smi
watch -d free -h
watch -n 2 'ls -lt /data/out | head -5'
watch -n 60 squeue --meBy default watch waits -n seconds after the previous run finishes. Pass -p to measure the interval from the start of the previous run instead.
Exit when the output changes
You don't have to stare at watch until something happens. -g (or --chgexit) makes watch exit with code 0 as soon as the output changes, so you can chain a follow-up command with &&.
watch -g -n 5 'ls /data/done' && echo "new file arrived"This checks /data/done every 5 seconds and runs echo once a file appears or disappears. When the command you watch might fail, -e freezes the screen on a non-zero exit with command exit with a non-zero status, press a key to exit, and -b rings the terminal bell instead.
Where watch falls short
watch only draws the first screen of output, keeps no history of earlier runs, needs an open terminal and can only alert you inside that terminal, with a beep or by exiting. To check a long Python script or batch command from your phone, a live link beats a terminal polling loop.
FAQ
How do I make watch refresh faster than once per second?
Pass a decimal number to -n, such as watch -n 0.5 date for two updates per second or watch -n 0.1 date for ten. Anything smaller than 0.1 is raised to 0.1.
How do I keep colors in watch output?
Pass -c (or --color) so watch interprets ANSI color sequences. Many tools turn their own colors off when they don't write to a terminal, so also pass their force flag, such as ls --color=always or grep --color=always.
Why does watch say command not found for my alias?
watch runs your command with sh -c, a non-interactive shell that doesn't load the aliases or functions from your .bashrc or .zshrc. Write out the full command, or put it in an executable script on your PATH.
How do I install watch on macOS?
macOS doesn't ship with watch. Install it with brew install watch, which gives you procps-ng watch 4.0.7 with the same flags as on Linux.
How do I save watch output to a file?
Redirecting watch itself captures screen-drawing codes, not clean text. Put tee -a inside the quoted command, as in watch 'date | tee -a log.txt', or use a shell while loop with sleep instead.
Check on long runs from your phone
Change one import and every tqdm bar prints a link you can open on any device. Get a Discord or Slack message when the run finishes, fails or stalls.
pip install tqdm-liveSources
- watch(1) man page man7.org
- procps-ng on GitLab gitlab.com
- Homebrew: watch formulae.brew.sh
- Kubernetes docs: kubectl get kubernetes.io
- Slurm docs: squeue slurm.schedmd.com