Skip to content

watch

75 commands

Runs a command repeatedly and shows its output full-screen, highlighting what changes between runs.

  • monitoring
  • repetition

Install watch

sudo apt install procps

Basic Command Monitoring4

watch date

Executes the date command repeatedly to display the current system time in real time.

watch ls

Monitors the contents of the current directory, updating every 2 seconds by default.

watch -h

Displays the help message summarizing available flags and usage syntax.

watch -v

Outputs the version information of the watch utility.

Interval and Timing Control3

watch -n 5 date

Changes the update interval to run the command every 5 seconds instead of the default.

watch --interval 10 uptime

Uses the long-form flag to set a 10-second refresh rate for monitoring system uptime.

watch -n 0.1 ls -l

Sets a sub-second interval of 100 milliseconds for high-frequency monitoring.

Output and Difference Highlighting4

watch -d date

Highlights the specific characters that change between updates to visualize differences.

watch --differences ls -l

Uses the long-form flag to highlight changes in file attributes or directory contents.

watch --differences=permanent date

Keeps changed highlights persistent on screen (cumulative) rather than clearing them.

Link
watch -d=cumulative uptime

Accumulates highlights over time to track all changes that have occurred since start.

Link

Header and Title Control3

watch -t date

Suppresses the header line showing the interval and command to display only output.

Link
watch --no-title ls

Removes the default title bar using the long-form flag for cleaner output.

Link
watch -n 1 -t echo 'Custom Monitor'

Runs a command without a header to create a simple static display or banner.

Link

Color and Formatting2

watch -c ls --color=always

Interprets ANSI color codes in the command output to preserve colored text.

Link
watch --color tree -C

Enables color interpretation for commands like tree that support forced color output.

Link

Error and Exit Handling4

watch -e cat /tmp/status.txt

Freezes the watch display if the command returns a non-zero exit code (error).

Link
watch --errexit ls /root/secret

Stops updates immediately if the command fails, allowing the user to see the error.

Link
watch -b /path/to/script.sh

Emits a beep sound if the command exits with a non-zero status code.

Link
watch --beep ls /nonexistent

Audible alert triggered repeatedly on every interval where the command fails.

Link

Automation and Triggers2

watch -g ls -l /tmp/trigger_file

Exits the watch utility completely as soon as the output of the command changes.

Link
watch --chgexit du -sh /var/log

Monitors directory size and terminates the loop automatically when the size changes.

Link

Precision and Timing2

watch -p -n 2 date

Enables precise timing mode to attempt running exactly every N seconds, compensating for drift.

Link
watch --precise -n 1 sleep 0.5

Maintains strict interval timing even if the command execution takes significant time.

Link

Quoting and Shell Handling5

watch "ps aux | grep nginx"

Uses double quotes to pass a pipeline string to the shell for execution.

Link
watch 'ls -l | wc -l'

Uses single quotes to prevent local shell expansion and pass the pipe to the watch shell.

Link
watch -n 1 "echo $RANDOM"

Double quotes allow the variable to be expanded once at the start (static output).

Link
watch -n 1 'echo $RANDOM'

Single quotes ensure the variable is expanded inside the loop (dynamic output).

Link
watch -x ls -l

Uses the exec flag to run the command directly without wrapping it in sh -c (if supported).

Link

System Administration Monitoring5

watch free -m

Monitors system memory usage in megabytes in real time.

Link
watch df -h

Tracks disk space usage across all mounted filesystems with human-readable sizes.

Link
watch uptime

Continuously displays system load averages and uptime duration.

Link
watch -n 1 "ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head"

Monitors the top CPU-consuming processes, updating every second.

Link
watch -d "cat /proc/loadavg"

Highlights changes in the raw system load average values from the proc filesystem.

Link

Network Monitoring (Lab Safe)4

watch ss -tuln

Monitors listening TCP and UDP ports in real time.

Link
watch -n 1 "netstat -an | grep ESTABLISHED"

Tracks active established network connections updating every second.

Link
watch ip addr show

Monitors network interface status and IP address assignments.

Link
watch -d "ip route show"

Highlights any changes to the system routing table.

Link

SOC Monitoring Use Cases4

watch -n 5 w

Monitors logged-in users and their current activities every 5 seconds.

Link
watch -d "who"

Highlights new user logins or logouts immediately.

Link
watch "last -n 10"

Constantly displays the last 10 login entries to catch recent access.

Link
watch -n 1 "journalctl -n 10 --no-pager"

Tails the systemd journal logs in real time without using a pager.

Link

Blue Team Defensive Validation4

watch -d -n 0.5 "ls -la /tmp"

Monitors the temporary directory at high speed to detect file drops during attacks.

Link
watch -d "md5sum /etc/passwd"

Tracks the checksum of a critical file to visually alert on integrity tampering.

Link
watch -n 1 "ps -ef --forest"

Visualizes the process tree hierarchy to spot suspicious parent-child relationships.

Link
watch -d "ls -l /etc/cron.d /etc/cron.hourly"

Monitors cron directories for the persistence mechanism creation.

Link

Incident Response Simulation3

watch -n 1 "lsof -i -P -n | grep LISTEN"

Real-time tracking of listening ports to identify unauthorized services or backdoors.

Link
watch -n 0.5 -d "cat /proc/interrupts"

Monitors hardware interrupts to detect keylogging or device anomalies.

Link
watch -n 1 "tail -f /var/log/auth.log"

Simulates a dashboard for authentication logs to spot brute force attempts.

Link

Advanced Workflow Integration5

watch -n 300 /usr/local/bin/backup_check.sh

Runs a custom maintenance script every 5 minutes for passive monitoring.

Link
watch -n 1 "dmesg | tail -n 20"

Monitors the kernel ring buffer for hardware or driver errors.

Link
watch -t -n 0.5 "echo 'System Status'; date; uptime"

Combines multiple commands into a custom status dashboard with no header.

Link
watch -c -n 1 "git status -s"

Monitors a git repository for changes in real time, useful during development.

Link
watch -g "pidof process_name"

Waits for a specific process to start or stop by exiting when the PID list changes.

Link

Complex Monitoring Logic3

watch -n 1 'if [ -f /tmp/lock ]; then echo "Locked"; else echo "Open"; fi'

Executes shell logic inside the watch loop to monitor application state files.

Link
watch -d "stat -c '%y %n' *"

Monitors modification timestamps of all files in the directory.

Link
watch -n 0.2 "cat /sys/class/thermal/thermal_zone0/temp"

High-frequency monitoring of CPU temperature sensors.

Link

Docker and Container Monitoring3

watch docker ps

Monitors running Docker containers in real time.

Link
watch -n 1 "docker stats --no-stream"

Captures a snapshot of container resource usage every second.

Link
watch -d "podman ps -a"

Highlights state changes in Podman containers (start/stop/exit).

Link

Kubernetes Monitoring (Lab)2

watch kubectl get pods

Monitors the status of Kubernetes pods in the current namespace.

Link
watch -d "kubectl get events --sort-by=.metadata.creationTimestamp"

Highlights new cluster events sorted by creation time.

Link

Systemd Service Monitoring2

watch -n 1 "systemctl list-units --type=service --state=running"

Tracks currently running systemd services.

Link
watch -d "systemctl status nginx"

Monitors the detailed status output of a specific service for state changes.

Link

File System Forensics2

watch -n 1 "find /tmp -mmin -1"

Lists files in the temp directory modified within the last minute.

Link
watch -d "ls -lR /etc/ | sha256sum"

Monitors the integrity of the entire etc directory listing structure.

Link

User and Group Management2

watch -d "cat /etc/group"

Highlights any changes to system groups, useful for privilege escalation monitoring.

Link
watch -d "cat /etc/shadow"

Monitors the shadow file (permission permitting) to see password hash changes.

Link

Hardware Resources2

watch -n 1 "grep 'cpu MHz' /proc/cpuinfo"

Monitors current CPU frequency scaling across all cores.

Link
watch -n 1 "cat /proc/meminfo | grep Dirty"

Tracks dirty memory pages waiting to be written to disk.

Link

Advanced Combined Flags5

watch -p -n 0.1 -d -t ls -l

Combines precision, sub-second interval, diff highlighting, and no title for minimal high-speed monitoring.

Link
watch -c -n 5 -b /path/to/healthcheck.sh

Runs a colorized health check every 5 seconds and beeps if the check fails.

Link
watch -g -n 2 "curl -s -I http://localhost:8080"

Polls a local web server headers and exits if the response changes.

Link
watch --differences=permanent --interval=1 "ps -eo pid,cmd,user | grep root"

Permanently highlights new root processes appearing in the process list.

Link
watch -n 1 'date +%T; echo "---"; uptime; echo "---"; free -h'

Constructs a multi-section text dashboard using a single command string.

Link