How to Compare Two Text Files on Mac, Windows & Linux
Whether you're debugging config changes, reviewing document edits, or auditing logs, comparing two text files is a daily developer task. Here's how to do it on every platform.
Command-Line Methods
Linux & macOS: The diff Command
The classic Unix diff utility is pre-installed on both Linux and macOS:
# Basic comparison
diff file1.txt file2.txt
# Unified format (most readable)
diff -u file1.txt file2.txt
# Side-by-side view
diff -y file1.txt file2.txt
# Ignore whitespace changes
diff -w file1.txt file2.txtThe unified format (-u) is what you see in git diffs and pull requests. Lines starting with - were removed, + were added.
Windows: The fc Command
Windows has a built-in file compare command:
# Basic text comparison
fc file1.txt file2.txt
# Ignore case
fc /c file1.txt file2.txt
# Compare as Unicode
fc /u file1.txt file2.txtFor a more powerful experience on Windows, install Git for Windows which includes the Unix diff command in Git Bash.
Cross-Platform: vimdiff
If you have Vim installed (available on all platforms), vimdiff opens both files in a split view with highlighted differences:
vimdiff file1.txt file2.txtNavigate between changes with ]c (next) and [c (previous). Merge with :diffget and :diffput.
GUI Applications
VS Code (Free, All Platforms)
VS Code has a built-in diff viewer. Select two files in the explorer, right-click, and choose "Compare Selected". Or from the command line:
code --diff file1.txt file2.txtBeyond Compare (Paid, All Platforms)
The gold standard for file comparison. Handles text, folders, images, and binary files. Worth the license for heavy users.
Meld (Free, Linux/Windows)
Open-source visual diff tool with three-way merge support. Excellent for resolving conflicts.
Online Tools (No Install Required)
When you need a quick comparison without installing anything:
- DiffSnap — Free, unlimited text/JSON/CSV/code/image diff with syntax highlighting and shareable links
- diffchecker.com — Popular but paywalls advanced features like offline mode
Online tools are ideal for quick checks, sharing diffs with teammates, or when you're on a machine without your usual tools installed.
Comparing Large Files
For files over 100MB, command-line tools are your best bet. GUI tools and online comparisons may struggle:
# Only show if files differ (fast check)
diff -q large1.log large2.log
# Compare specific sections with head/tail
diff <(head -1000 large1.log) <(head -1000 large2.log)
# Use comm for sorted files
comm -3 <(sort file1.txt) <(sort file2.txt)Comparing Directory Trees
To compare all files in two directories recursively:
# Recursive directory diff
diff -rq dir1/ dir2/
# With unified output for each file
diff -ru dir1/ dir2/Quick Reference Table
| Tool | Platform | Best For | Cost |
|---|---|---|---|
diff -u | Linux/Mac | Quick CLI comparison | Free |
fc | Windows | Basic Windows comparison | Free |
| VS Code | All | Developers with VS Code | Free |
| Beyond Compare | All | Power users, folder diff | $35-60 |
| DiffSnap | Web | Quick online diff, sharing | Free |