{"tool":"watch","name":"watch","description":"Runs a command repeatedly and shows its output full-screen, highlighting what changes between runs.","tags":["monitoring","repetition"],"docs":"https://man7.org/linux/man-pages/man1/watch.1.html","install":{"apt":"sudo apt install procps","brew":"brew install watch"},"related":["top","tail"],"total_commands":75,"commands":[{"id":1,"category":"Basic Command Monitoring","command":"watch date","example":"watch date","explanation":"Executes the date command repeatedly to display the current system time in real time."},{"id":2,"category":"Basic Command Monitoring","command":"watch ls","example":"watch ls","explanation":"Monitors the contents of the current directory, updating every 2 seconds by default."},{"id":3,"category":"Basic Command Monitoring","command":"watch -h","example":"watch -h","explanation":"Displays the help message summarizing available flags and usage syntax."},{"id":4,"category":"Basic Command Monitoring","command":"watch -v","example":"watch -v","explanation":"Outputs the version information of the watch utility."},{"id":5,"category":"Interval and Timing Control","command":"watch -n 5 date","example":"watch -n 5 date","explanation":"Changes the update interval to run the command every 5 seconds instead of the default."},{"id":6,"category":"Interval and Timing Control","command":"watch --interval 10 uptime","example":"watch --interval 10 uptime","explanation":"Uses the long-form flag to set a 10-second refresh rate for monitoring system uptime."},{"id":7,"category":"Interval and Timing Control","command":"watch -n 0.1 ls -l","example":"watch -n 0.1 ls -l","explanation":"Sets a sub-second interval of 100 milliseconds for high-frequency monitoring."},{"id":8,"category":"Output and Difference Highlighting","command":"watch -d date","example":"watch -d date","explanation":"Highlights the specific characters that change between updates to visualize differences."},{"id":9,"category":"Output and Difference Highlighting","command":"watch --differences ls -l","example":"watch --differences ls -l","explanation":"Uses the long-form flag to highlight changes in file attributes or directory contents."},{"id":10,"category":"Output and Difference Highlighting","command":"watch --differences=permanent date","example":"watch --differences=permanent date","explanation":"Keeps changed highlights persistent on screen (cumulative) rather than clearing them."},{"id":11,"category":"Output and Difference Highlighting","command":"watch -d=cumulative uptime","example":"watch -d=cumulative uptime","explanation":"Accumulates highlights over time to track all changes that have occurred since start."},{"id":12,"category":"Header and Title Control","command":"watch -t date","example":"watch -t date","explanation":"Suppresses the header line showing the interval and command to display only output."},{"id":13,"category":"Header and Title Control","command":"watch --no-title ls","example":"watch --no-title ls","explanation":"Removes the default title bar using the long-form flag for cleaner output."},{"id":14,"category":"Header and Title Control","command":"watch -n 1 -t echo 'Custom Monitor'","example":"watch -n 1 -t echo 'Custom Monitor'","explanation":"Runs a command without a header to create a simple static display or banner."},{"id":15,"category":"Color and Formatting","command":"watch -c ls --color=always","example":"watch -c ls --color=always","explanation":"Interprets ANSI color codes in the command output to preserve colored text."},{"id":16,"category":"Color and Formatting","command":"watch --color tree -C","example":"watch --color tree -C","explanation":"Enables color interpretation for commands like tree that support forced color output."},{"id":17,"category":"Error and Exit Handling","command":"watch -e cat /tmp/status.txt","example":"watch -e cat /tmp/status.txt","explanation":"Freezes the watch display if the command returns a non-zero exit code (error)."},{"id":18,"category":"Error and Exit Handling","command":"watch --errexit ls /root/secret","example":"watch --errexit ls /root/secret","explanation":"Stops updates immediately if the command fails, allowing the user to see the error."},{"id":19,"category":"Error and Exit Handling","command":"watch -b /path/to/script.sh","example":"watch -b /path/to/script.sh","explanation":"Emits a beep sound if the command exits with a non-zero status code."},{"id":20,"category":"Error and Exit Handling","command":"watch --beep ls /nonexistent","example":"watch --beep ls /nonexistent","explanation":"Audible alert triggered repeatedly on every interval where the command fails."},{"id":21,"category":"Automation and Triggers","command":"watch -g ls -l /tmp/trigger_file","example":"watch -g ls -l /tmp/trigger_file","explanation":"Exits the watch utility completely as soon as the output of the command changes."},{"id":22,"category":"Automation and Triggers","command":"watch --chgexit du -sh /var/log","example":"watch --chgexit du -sh /var/log","explanation":"Monitors directory size and terminates the loop automatically when the size changes."},{"id":23,"category":"Precision and Timing","command":"watch -p -n 2 date","example":"watch -p -n 2 date","explanation":"Enables precise timing mode to attempt running exactly every N seconds, compensating for drift."},{"id":24,"category":"Precision and Timing","command":"watch --precise -n 1 sleep 0.5","example":"watch --precise -n 1 sleep 0.5","explanation":"Maintains strict interval timing even if the command execution takes significant time."},{"id":25,"category":"Quoting and Shell Handling","command":"watch \"ps aux | grep nginx\"","example":"watch \"ps aux | grep nginx\"","explanation":"Uses double quotes to pass a pipeline string to the shell for execution."},{"id":26,"category":"Quoting and Shell Handling","command":"watch 'ls -l | wc -l'","example":"watch 'ls -l | wc -l'","explanation":"Uses single quotes to prevent local shell expansion and pass the pipe to the watch shell."},{"id":27,"category":"Quoting and Shell Handling","command":"watch -n 1 \"echo $RANDOM\"","example":"watch -n 1 \"echo $RANDOM\"","explanation":"Double quotes allow the variable to be expanded once at the start (static output)."},{"id":28,"category":"Quoting and Shell Handling","command":"watch -n 1 'echo $RANDOM'","example":"watch -n 1 'echo $RANDOM'","explanation":"Single quotes ensure the variable is expanded inside the loop (dynamic output)."},{"id":29,"category":"Quoting and Shell Handling","command":"watch -x ls -l","example":"watch -x ls -l","explanation":"Uses the exec flag to run the command directly without wrapping it in sh -c (if supported)."},{"id":30,"category":"System Administration Monitoring","command":"watch free -m","example":"watch free -m","explanation":"Monitors system memory usage in megabytes in real time."},{"id":31,"category":"System Administration Monitoring","command":"watch df -h","example":"watch df -h","explanation":"Tracks disk space usage across all mounted filesystems with human-readable sizes."},{"id":32,"category":"System Administration Monitoring","command":"watch uptime","example":"watch uptime","explanation":"Continuously displays system load averages and uptime duration."},{"id":33,"category":"System Administration Monitoring","command":"watch -n 1 \"ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head\"","example":"watch -n 1 \"ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head\"","explanation":"Monitors the top CPU-consuming processes, updating every second."},{"id":34,"category":"System Administration Monitoring","command":"watch -d \"cat /proc/loadavg\"","example":"watch -d \"cat /proc/loadavg\"","explanation":"Highlights changes in the raw system load average values from the proc filesystem."},{"id":35,"category":"Network Monitoring (Lab Safe)","command":"watch ss -tuln","example":"watch ss -tuln","explanation":"Monitors listening TCP and UDP ports in real time."},{"id":36,"category":"Network Monitoring (Lab Safe)","command":"watch -n 1 \"netstat -an | grep ESTABLISHED\"","example":"watch -n 1 \"netstat -an | grep ESTABLISHED\"","explanation":"Tracks active established network connections updating every second."},{"id":37,"category":"Network Monitoring (Lab Safe)","command":"watch ip addr show","example":"watch ip addr show","explanation":"Monitors network interface status and IP address assignments."},{"id":38,"category":"Network Monitoring (Lab Safe)","command":"watch -d \"ip route show\"","example":"watch -d \"ip route show\"","explanation":"Highlights any changes to the system routing table."},{"id":39,"category":"SOC Monitoring Use Cases","command":"watch -n 5 w","example":"watch -n 5 w","explanation":"Monitors logged-in users and their current activities every 5 seconds."},{"id":40,"category":"SOC Monitoring Use Cases","command":"watch -d \"who\"","example":"watch -d \"who\"","explanation":"Highlights new user logins or logouts immediately."},{"id":41,"category":"SOC Monitoring Use Cases","command":"watch \"last -n 10\"","example":"watch \"last -n 10\"","explanation":"Constantly displays the last 10 login entries to catch recent access."},{"id":42,"category":"SOC Monitoring Use Cases","command":"watch -n 1 \"journalctl -n 10 --no-pager\"","example":"watch -n 1 \"journalctl -n 10 --no-pager\"","explanation":"Tails the systemd journal logs in real time without using a pager."},{"id":43,"category":"Blue Team Defensive Validation","command":"watch -d -n 0.5 \"ls -la /tmp\"","example":"watch -d -n 0.5 \"ls -la /tmp\"","explanation":"Monitors the temporary directory at high speed to detect file drops during attacks."},{"id":44,"category":"Blue Team Defensive Validation","command":"watch -d \"md5sum /etc/passwd\"","example":"watch -d \"md5sum /etc/passwd\"","explanation":"Tracks the checksum of a critical file to visually alert on integrity tampering."},{"id":45,"category":"Blue Team Defensive Validation","command":"watch -n 1 \"ps -ef --forest\"","example":"watch -n 1 \"ps -ef --forest\"","explanation":"Visualizes the process tree hierarchy to spot suspicious parent-child relationships."},{"id":46,"category":"Blue Team Defensive Validation","command":"watch -d \"ls -l /etc/cron.d /etc/cron.hourly\"","example":"watch -d \"ls -l /etc/cron.d /etc/cron.hourly\"","explanation":"Monitors cron directories for the persistence mechanism creation."},{"id":47,"category":"Incident Response Simulation","command":"watch -n 1 \"lsof -i -P -n | grep LISTEN\"","example":"watch -n 1 \"lsof -i -P -n | grep LISTEN\"","explanation":"Real-time tracking of listening ports to identify unauthorized services or backdoors."},{"id":48,"category":"Incident Response Simulation","command":"watch -n 0.5 -d \"cat /proc/interrupts\"","example":"watch -n 0.5 -d \"cat /proc/interrupts\"","explanation":"Monitors hardware interrupts to detect keylogging or device anomalies."},{"id":49,"category":"Incident Response Simulation","command":"watch -n 1 \"tail -f /var/log/auth.log\"","example":"watch -n 1 \"tail -f /var/log/auth.log\"","explanation":"Simulates a dashboard for authentication logs to spot brute force attempts."},{"id":50,"category":"Advanced Workflow Integration","command":"watch -n 300 /usr/local/bin/backup_check.sh","example":"watch -n 300 /usr/local/bin/backup_check.sh","explanation":"Runs a custom maintenance script every 5 minutes for passive monitoring."},{"id":51,"category":"Advanced Workflow Integration","command":"watch -n 1 \"dmesg | tail -n 20\"","example":"watch -n 1 \"dmesg | tail -n 20\"","explanation":"Monitors the kernel ring buffer for hardware or driver errors."},{"id":52,"category":"Advanced Workflow Integration","command":"watch -t -n 0.5 \"echo 'System Status'; date; uptime\"","example":"watch -t -n 0.5 \"echo 'System Status'; date; uptime\"","explanation":"Combines multiple commands into a custom status dashboard with no header."},{"id":53,"category":"Advanced Workflow Integration","command":"watch -c -n 1 \"git status -s\"","example":"watch -c -n 1 \"git status -s\"","explanation":"Monitors a git repository for changes in real time, useful during development."},{"id":54,"category":"Advanced Workflow Integration","command":"watch -g \"pidof process_name\"","example":"watch -g \"pidof process_name\"","explanation":"Waits for a specific process to start or stop by exiting when the PID list changes."},{"id":55,"category":"Complex Monitoring Logic","command":"watch -n 1 'if [ -f /tmp/lock ]; then echo \"Locked\"; else echo \"Open\"; fi'","example":"watch -n 1 'if [ -f /tmp/lock ]; then echo \"Locked\"; else echo \"Open\"; fi'","explanation":"Executes shell logic inside the watch loop to monitor application state files."},{"id":56,"category":"Complex Monitoring Logic","command":"watch -d \"stat -c '%y %n' *\"","example":"watch -d \"stat -c '%y %n' *\"","explanation":"Monitors modification timestamps of all files in the directory."},{"id":57,"category":"Complex Monitoring Logic","command":"watch -n 0.2 \"cat /sys/class/thermal/thermal_zone0/temp\"","example":"watch -n 0.2 \"cat /sys/class/thermal/thermal_zone0/temp\"","explanation":"High-frequency monitoring of CPU temperature sensors."},{"id":58,"category":"Docker and Container Monitoring","command":"watch docker ps","example":"watch docker ps","explanation":"Monitors running Docker containers in real time."},{"id":59,"category":"Docker and Container Monitoring","command":"watch -n 1 \"docker stats --no-stream\"","example":"watch -n 1 \"docker stats --no-stream\"","explanation":"Captures a snapshot of container resource usage every second."},{"id":60,"category":"Docker and Container Monitoring","command":"watch -d \"podman ps -a\"","example":"watch -d \"podman ps -a\"","explanation":"Highlights state changes in Podman containers (start/stop/exit)."},{"id":61,"category":"Kubernetes Monitoring (Lab)","command":"watch kubectl get pods","example":"watch kubectl get pods","explanation":"Monitors the status of Kubernetes pods in the current namespace."},{"id":62,"category":"Kubernetes Monitoring (Lab)","command":"watch -d \"kubectl get events --sort-by=.metadata.creationTimestamp\"","example":"watch -d \"kubectl get events --sort-by=.metadata.creationTimestamp\"","explanation":"Highlights new cluster events sorted by creation time."},{"id":63,"category":"Systemd Service Monitoring","command":"watch -n 1 \"systemctl list-units --type=service --state=running\"","example":"watch -n 1 \"systemctl list-units --type=service --state=running\"","explanation":"Tracks currently running systemd services."},{"id":64,"category":"Systemd Service Monitoring","command":"watch -d \"systemctl status nginx\"","example":"watch -d \"systemctl status nginx\"","explanation":"Monitors the detailed status output of a specific service for state changes."},{"id":65,"category":"File System Forensics","command":"watch -n 1 \"find /tmp -mmin -1\"","example":"watch -n 1 \"find /tmp -mmin -1\"","explanation":"Lists files in the temp directory modified within the last minute."},{"id":66,"category":"File System Forensics","command":"watch -d \"ls -lR /etc/ | sha256sum\"","example":"watch -d \"ls -lR /etc/ | sha256sum\"","explanation":"Monitors the integrity of the entire etc directory listing structure."},{"id":67,"category":"User and Group Management","command":"watch -d \"cat /etc/group\"","example":"watch -d \"cat /etc/group\"","explanation":"Highlights any changes to system groups, useful for privilege escalation monitoring."},{"id":68,"category":"User and Group Management","command":"watch -d \"cat /etc/shadow\"","example":"watch -d \"cat /etc/shadow\"","explanation":"Monitors the shadow file (permission permitting) to see password hash changes."},{"id":69,"category":"Hardware Resources","command":"watch -n 1 \"grep 'cpu MHz' /proc/cpuinfo\"","example":"watch -n 1 \"grep 'cpu MHz' /proc/cpuinfo\"","explanation":"Monitors current CPU frequency scaling across all cores."},{"id":70,"category":"Hardware Resources","command":"watch -n 1 \"cat /proc/meminfo | grep Dirty\"","example":"watch -n 1 \"cat /proc/meminfo | grep Dirty\"","explanation":"Tracks dirty memory pages waiting to be written to disk."},{"id":71,"category":"Advanced Combined Flags","command":"watch -p -n 0.1 -d -t ls -l","example":"watch -p -n 0.1 -d -t ls -l","explanation":"Combines precision, sub-second interval, diff highlighting, and no title for minimal high-speed monitoring."},{"id":72,"category":"Advanced Combined Flags","command":"watch -c -n 5 -b /path/to/healthcheck.sh","example":"watch -c -n 5 -b /path/to/healthcheck.sh","explanation":"Runs a colorized health check every 5 seconds and beeps if the check fails."},{"id":73,"category":"Advanced Combined Flags","command":"watch -g -n 2 \"curl -s -I http://localhost:8080\"","example":"watch -g -n 2 \"curl -s -I http://localhost:8080\"","explanation":"Polls a local web server headers and exits if the response changes."},{"id":74,"category":"Advanced Combined Flags","command":"watch --differences=permanent --interval=1 \"ps -eo pid,cmd,user | grep root\"","example":"watch --differences=permanent --interval=1 \"ps -eo pid,cmd,user | grep root\"","explanation":"Permanently highlights new root processes appearing in the process list."},{"id":75,"category":"Advanced Combined Flags","command":"watch -n 1 'date +%T; echo \"---\"; uptime; echo \"---\"; free -h'","example":"watch -n 1 'date +%T; echo \"---\"; uptime; echo \"---\"; free -h'","explanation":"Constructs a multi-section text dashboard using a single command string."}],"slug":"watch","category":"utilities","url":"https://terminal.rokibulroni.com/tool/utilities/watch","markdown":"https://terminal.rokibulroni.com/api/v1/tools/utilities/watch.md"}