Luke Oliff.

TIL: Comparing Directory Trees With diff -r

·TIL·1 min read·Luke Oliff

Two directories look the same until they are not. diff -r tells you what differs.

diff -r dist-v1/ dist-v2/

Compares every file in both directories recursively. Output shows which files exist in one but not the other, and which files have different content.

diff -r -q build-old/ build-new/

The -q flag suppresses the actual diff output. Just a list of files that differ. Useful for quick sanity checks.

diff -r -u src/ src-backup/

The -u flag produces unified diff format. Each difference shows context lines around the change.

diff -r --exclude=node_modules --exclude=.git src-1/ src-2/

Exclude common noise directories. Without this every diff includes irrelevant package manager and version control files.

Can I ignore whitespace differences?

Add -w or –ignore-all-space to diff. Useful when comparing files that were formatted differently but contain the same logic.

Does diff work with binary files?

diff reports whether binary files differ but does not show the differences. Use sha256 comparison for binary files.