Monitoring the progress of long-running operations—such as observing file transfers, tracking disk space depletion, watching network interfaces, or awaiting service status changes—is a routine necessity for systems administrators and developers. For decades, the standard Unix watch command has served this purpose by executing a chosen command at fixed intervals and refreshing the terminal screen. However, traditional watch has a critical limitation: it displays only the current instantaneous state, immediately discarding previous snapshots.
To overcome this limitation, hwatch (short for history watch) provides a modern, Rust-built alternative. In addition to periodically re-running commands and displaying output, hwatch records the entire execution history in memory, allowing you to pause monitoring, step backward through past snapshots, and inspect colour-coded unified or side-by-side diffs between different moments in time. This guide explains how to install hwatch on Linux, navigate its interactive user interface, configure execution intervals, and leverage diff inspection modes.
What Is hwatch and How Does It Improve on Traditional watch?
Traditional watch is passive; if a critical spike or error message flashes on your screen for two seconds between refresh intervals, you cannot scroll back to inspect what occurred. In contrast, hwatch operates like an interactive terminal time machine:
- Interactive History Navigation: Use arrow keys or Vim navigation shortcuts (
j/k) to step backward through every historical output recorded since the session began. - Integrated Diff Engines: Toggle instantly between full terminal views, unified diffs, or line-by-line diff views highlighting exact additions and deletions between consecutive execution intervals.
- Output Filtering: Search and filter through historical execution outputs directly inside the TUI without piping to external pagers.
- ANSI Colour Support: Seamlessly preserves ANSI colour codes emitted by commands like
ls --color,systemctl, andgit status.
How to Install hwatch on Linux
You can install hwatch on Linux distributions using Cargo, popular distribution package managers, or pre-compiled binaries.
Method 1: Installing via Cargo
If you have the Rust toolchain configured on your machine, install hwatch directly from crates.io:
cargo install hwatch
Ensure that ~/.cargo/bin is present in your shell’s PATH variable to execute the binary.
Method 2: Installing Pre-Compiled Release Binaries
For systems without Rust installed, download the official static binary release from GitHub:
- Fetch and extract the latest release archive using
curlandtar:curl -sL https://github.com/blacknon/hwatch/releases/latest/download/hwatch-x86_64-unknown-linux-musl.tar.gz | tar xz - Move the binary to your system execution directory:
sudo mv hwatch /usr/local/bin/ - Verify successful installation:
hwatch --version
Basic Usage and Interval Configuration
The core syntax of hwatch mirrors standard watch commands, accepting your command arguments directly:
hwatch [OPTIONS] -- <COMMAND>
Running a Basic Watch Session
To monitor system memory or disk usage, invoke hwatch with your chosen utility:
hwatch -- free -h
By default, hwatch runs the target command every 2 seconds. The upper portion of the terminal renders the command output, while a status banner along the bottom indicates the current history index, total captured cycles, and active keybindings.
Customising Refresh Intervals
To alter the polling frequency, specify the -n (or --interval) flag in seconds (including fractions of a second):
hwatch -n 0.5 -- df -h /home
Navigating History and Diff Modes in the TUI
While an hwatch session is running, you can interact with the live display using intuitive keyboard shortcuts:
Keybindings Overview
- Up / Down Arrow (or j / k): Step backward or forward through historical executions. Moving into the past pauses automatic auto-scrolling so you can study historical states without interruptions.
- Home / End: Jump instantly to the earliest recorded execution or back to the latest live snapshot.
- d: Cycle through diff modes (Plain output, Character diff, Word diff, or Line diff).
- Tab: Switch between the main output window and the history timeline panel.
- / (Slash): Open the interactive search prompt to locate specific text strings within the active output.
- q: Exit
hwatchcleanly and return to your terminal prompt.
Advanced Features: Side-by-Side Diffs and Logging
Beyond basic monitoring, hwatch provides specialised switches for deeper forensic analysis:
Highlighting Exact Changes with Word Diff
To launch hwatch with word-level differences highlighted automatically from the very first cycle, add the --diff flag:
hwatch --diff -- ss -tulpn
Any newly opened network sockets or terminated listening daemons will immediately glow in bright green and red highlights.
Writing History Snapshots to Disk
If you are monitoring a sporadic bug or transient network issue, you can instruct hwatch to dump all recorded history snapshots to a log file upon exit:
hwatch --logfile monitoring_run.json -- ping -c 1 1.1.1.1
Troubleshooting Common Operational Quirks
Keep these best practices in mind when using hwatch in complex terminal sessions:
- Complex Pipelines and Quotes: If your command involves shell pipes (
|) or variable expansions, wrap the entire command string in quotes and pass it to a subshell:hwatch -- "ps aux | grep node | wc -l" - High Frequency Memory Usage: Because
hwatchretains output history in system RAM, polling verbose commands at 100-millisecond intervals over several hours can consume significant memory. Limit long sessions with the--limitparameter to cap the buffer size (e.g.,hwatch --limit 500 -- ...).