System and processes

The watch command

Runs a command every few seconds and redraws the screen with the result, to keep an eye on a change: memory, free space, connections... It exits with Ctrl+C.

Syntax

watch [opciones] comandoTry it in the terminal →

Most useful options

-n <segundos>How many seconds between runs. Default is 2; decimals such as 0.5 are allowed
-dHighlights what changes between one run and the next
-tHides the header with the time and the command, for a clean output
-eExits as soon as the command fails, with a non-zero exit code
-gExits as soon as the output changes: useful to wait for something to happen
-xRuns the command directly, without sh -c: pipes and redirections then do not work

Copy-ready examples

$ watch -n 1 free -hmemory and swap every second.

Example output

Every 1.0s: free -h                  portatil: Tue Nov  3 11:20:04 2026

               total        used        free
Mem:            15Gi       6.2Gi       1.1Gi
$ watch -d 'ss -tn state established | wc -l'counts the established TCP connections and highlights the changes.
$ watch -g -n 10 'ls /srv/descargas | wc -l'waits until the number of files changes, then exits on its own.
$ watch -t -n 0.5 'date +%T'a clock updated every half second, without header.
$ watch -n 5 'systemctl is-active nginx'checks every 5 seconds whether nginx is still active.
$ watch -x df -h /runs df directly, without a shell, to avoid quoting problems.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
sh: 1: ll: not foundwatch runs the command with sh, not your shell: your aliases from ~/.bashrc do not exist there. On Debian and Ubuntu, sh is dash.Write the full command without aliases, or move the logic into a script.

Typical mistakes

  • Without quotes, the pipe applies to watch, not to the command: watch ls | wc -l counts the lines watch prints.
  • Your shell aliases do not exist inside watch, because it runs the command with sh -c.

Differences from similar commands

  • top: shows processes in real time with its own screen and controls. watch repeats any command.
  • tail: tail -f follows a file that grows without rerunning anything. watch runs a whole command again.
  • timeout: limits how long a command may run. watch, on the other hand, repeats it indefinitely.

Security

watch keeps running the command. If what it repeats changes something (deleting, writing to the network, restarting a service), it does so every few seconds. Use watch only to look.

Related commands

FAQ

How do I exit watch?

With Ctrl+C. With -e or -g it also exits on its own when the condition is met.

How do I see only what changes?

With -d, each refresh highlights the characters that changed. With -d=cumulative, all the changes seen are kept.

Why does the screen flicker?

watch clears and redraws the whole screen on each run. With -t you remove the header, which changes every second.

More System and processes commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course