File Diff Tools — Best Tools for Comparing Files and Directories
File diff tools show what changed between files or folders. Here's a comparison of command-line diff tools (diff, vimdiff, colordiff), GUI diff tools (Meld, Beyond Compare, VS...
File diff tools compare two files or directories and show what changed. Command-line tools like diff are fast for scripting; GUI tools like Meld or VS Code offer visual comparison for complex changes.
Use the text compare tool to compare two pieces of text online without installing anything.
Command-line: diff
diff is available on every Unix-like system and WSL on Windows:
# Basic comparison:
diff file1.txt file2.txt
# Unified format (most readable, used by git):
diff -u file1.txt file2.txt
# Side-by-side:
diff -y file1.txt file2.txt
# Ignore whitespace differences:
diff -w file1.txt file2.txt
diff -b file1.txt file2.txt # ignore trailing whitespace
diff -B file1.txt file2.txt # ignore blank lines
# Recursive directory comparison:
diff -r dir1/ dir2/
diff -rq dir1/ dir2/ # -q: only show file names, not content
# Context lines:
diff -U 3 file1.txt file2.txt # 3 lines of context (default)
diff -U 0 file1.txt file2.txt # no context
Reading basic diff output:
< line only in file1 (left)
> line only in file2 (right)
---
Reading unified diff output:
-line removed
+line added
unchanged context
Command-line: colordiff
colordiff is a wrapper around diff that adds color:
# Install:
brew install colordiff # macOS
apt install colordiff # Ubuntu/Debian
# Usage: same as diff but colorized:
colordiff -u file1.txt file2.txt
Command-line: wdiff (word-level)
# Install:
brew install wdiff
# Compare word by word (not line by line):
wdiff file1.txt file2.txt
# Output:
# {-removed words-} {+added words+}
Terminal GUI: vimdiff
Opens files side by side in Vim with highlighting:
vimdiff file1.txt file2.txt
# or:
vim -d file1.txt file2.txt
# With 3 files:
vimdiff file1.txt file2.txt file3.txt
vimdiff navigation:
]c— next diff[c— previous diffdo— get change from other file (diff obtain)dp— put change to other file (diff put):qa— quit all
VS Code as a diff tool
VS Code has excellent built-in diff support:
# Open diff in VS Code:
code --diff file1.txt file2.txt
# Configure git to use VS Code for diffs:
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
git difftool
VS Code features:
- Inline or side-by-side view
- Navigate changes with arrow buttons
- Stage individual hunks in Git integration
- Folder comparison (Source Control view)
GUI tools
Meld (Free, Linux/Mac/Windows)
Best free GUI diff tool. Features:
- Side-by-side file comparison with color highlighting
- Directory comparison (shows which files differ)
- Three-way merge for conflict resolution
- Git/SVN integration
brew install --cask meld # macOS
apt install meld # Ubuntu
# Windows: download from meld.app
Beyond Compare (Commercial)
The most powerful diff tool. Supports:
- File and folder comparison
- FTP/cloud storage comparison
- Archive (zip) contents comparison
- Hex comparison
- Three-way merge
Popular with teams that need to compare large directory trees or mixed file types.
WinMerge (Free, Windows)
Windows-specific free tool. Good for Windows users who want a GUI diff tool without installing heavy software.
Kaleidoscope (Mac, Commercial)
Beautiful diff UI for macOS. Supports text, images, and folders. Integrates well with Git.
Directory comparison
diff for directories
# Show files that differ:
diff -rq dir1/ dir2/
# Files dir1/config.yaml and dir2/config.yaml differ
# Only in dir2: newfile.txt
# Full recursive diff:
diff -r dir1/ dir2/
# Exclude files:
diff -r --exclude='*.log' --exclude='.git' dir1/ dir2/
rsync —dry-run
# See what rsync would change (without making changes):
rsync -avun dir1/ dir2/
# -a: archive mode
# -v: verbose
# -u: update (skip files that are newer)
# -n: dry run
Meld directory mode
Open Meld, choose “Directory Comparison”, select two directories. Files that differ are highlighted; you can double-click to open a file diff.
Comparing JSON and YAML
For structured data, use format-aware tools:
# JSON diff (with jq):
diff <(jq -S . file1.json) <(jq -S . file2.json)
# -S: sort keys for consistent comparison
# YAML diff (convert to JSON first):
diff <(python3 -c "import yaml,json,sys; print(json.dumps(yaml.safe_load(sys.stdin), indent=2, sort_keys=True))" < file1.yaml) \
<(python3 -c "import yaml,json,sys; print(json.dumps(yaml.safe_load(sys.stdin), indent=2, sort_keys=True))" < file2.yaml)
Related tools
- Text Diff Tool — compare texts online
- Diff Algorithm Explained — how diff algorithms work
- Git Diff Guide — using git diff effectively
Related posts
- How Diff Tools Work: Myers Algorithm, Unified Format, and Merge Conflicts — A technical walkthrough of how diff works: the Myers algorithm, the three output…
- Diff Algorithm Explained — How Text Comparison Tools Work — Text diff tools use the LCS (Longest Common Subsequence) or Myers diff algorithm…
- Understanding Merge Conflicts — How 3-Way Diff Works — Merge conflicts occur when two branches edit the same lines differently. Learn h…
- Git Diff Guide — Reading and Using git diff Commands — git diff shows what changed between commits, branches, or the working tree. Here…
- Text Diff Online — How to Compare Two Texts Side by Side — Text diff tools compare two versions of text and highlight additions, deletions,…
Related tool
Compare two text blocks line-by-line or word-by-word. Unified and split view. Shows added, removed, and changed segments with full color coding.
Written by Mian Ali Khalid. Part of the Dev Productivity pillar.