Comparing file modifications and reviewing code patches in the Linux terminal traditionally relies on the standard GNU diff utility or git diff. Standard diffs present changes as a unified vertical stream where removed and added lines are stacked on top of one another. For complex code refactors, configuration drift analysis, and long string comparisons, deciphering inline differences in a single column is visually fatiguing. icdiff (Improved Coloured Diff) is a lightweight Python-based command-line tool that renders two-column, side-by-side terminal diffs with vibrant colours and precise character-level change highlighting.
Why Use icdiff Over Standard Unified Diff
icdiff is engineered specifically to make code and text comparisons instantly readable in command-line terminals:
- Side-by-Side Two-Column Layout: Displays the original file on the left and the modified file on the right, keeping identical surrounding context visually aligned.
- Intra-Line Character Highlighting: Rather than simply highlighting whole lines, icdiff highlights the exact words, characters, or punctuation marks that were modified within a line.
- Seamless Git Integration: Can be configured as a native Git difftool, replacing standard Git diff outputs with two-column terminal views.
- Line Wrapping Control: Gracefully truncates or wraps long code lines without breaking column boundaries.
- Zero Heavy Dependencies: Written in pure Python without requiring node runtimes or complex compilation toolchains.
Installing icdiff on Linux
icdiff is available across distribution package managers, Python package repositories, and standalone shell scripts:
| Distribution / Platform | Package Manager | Command |
|---|---|---|
| Ubuntu / Debian | APT | sudo apt update && sudo apt install -y icdiff |
| Arch Linux / Manjaro | Pacman (Extra) | sudo pacman -S icdiff |
| Python / Pipx (Universal) | pipx | pipx install icdiff |
| Direct Standalone Script | cURL → /usr/local/bin | Downloadable single Python executable |
To install directly from GitHub without package managers:
curl -s https://raw.githubusercontent.com/jeffkaufman/icdiff/release-2.0.7/icdiff | sudo tee /usr/local/bin/icdiff > /dev/null
sudo chmod +x /usr/local/bin/icdiff
Comparing Files Side by Side in the Terminal
The basic usage syntax requires passing the original file and the modified file as arguments:
icdiff original_config.yaml updated_config.yaml
Terminal instantly prints a two-column comparison. Identical lines remain plain text, while deleted characters on the left appear in red and new additions on the right appear in green.
Configuring icdiff as Your Default Git Difftool
To integrate icdiff into your daily Git workflow so that executing git difftool automatically renders side-by-side comparisons:
- Open your terminal and configure Git global preferences:
git config --global diff.tool icdiff git config --global difftool.icdiff.cmd 'icdiff --head=5000 "$LOCAL" "$REMOTE"' git config --global difftool.prompt false - Create a convenient Git alias in your
~/.gitconfig:git config --global alias.d icdiff - Now, whenever you run:
Git will stream all staged or unstaged file changes directly through icdiff’s side-by-side coloured view.git difftool
Useful Command-Line Flags and Options
Tailor icdiff to your terminal window width and scripting needs:
| Flag / Option | Function | Example Usage |
|---|---|---|
--line-numbers / -N |
Displays line numbers adjacent to both columns for precise code auditing. | icdiff -N file1.py file2.py |
--cols=<N> |
Specifies a custom terminal column width (default is auto-detected). | icdiff --cols=160 file1.txt file2.txt |
--highlight / -H |
Enables background colour highlighting for subtle character edits. | icdiff -H file1.json file2.json |
--recursive / -r |
Recursively compares all files across two directory trees. | icdiff -r folder_v1/ folder_v2/ |