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.txt

The 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.txt

For 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.txt

Navigate 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.txt

Beyond 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:

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

ToolPlatformBest ForCost
diff -uLinux/MacQuick CLI comparisonFree
fcWindowsBasic Windows comparisonFree
VS CodeAllDevelopers with VS CodeFree
Beyond CompareAllPower users, folder diff$35-60
DiffSnapWebQuick online diff, sharingFree

Try DiffSnap

Compare text, JSON, CSV, code, and images — free, unlimited, no signup.

Open DiffSnap →