How to compare two folders and know they really match
8 min readUpdated September 2026100% local

Comparing two folders sounds trivial until the answer matters — a deploy that must match a build, a backup you have to trust, a client hand-off you are about to sign off on. The difficulty is not walking the directory tree; it is deciding what counts as a difference. This guide goes through the four definitions of “identical”, why file timestamps are a weak signal, when SHA-256 hashing earns its cost, and how to keep generated files from burying the changes you actually care about.
Four different meanings of “identical”
Two folders can be the same in at least four senses: they contain the same set of relative paths; the files at those paths have the same sizes; the files have the same bytes; or the files also carry the same metadata — modification time, permissions, owner, extended attributes. Most comparison tools silently pick one of these and present the result as the truth.
Which definition you need depends entirely on the question. Verifying that a deployed directory matches a build artifact is a question about bytes; metadata is irrelevant. Verifying a backup of a Unix server is also a question about permissions and ownership, because a restored file that nobody can execute is not a successful restore. Checking whether a refactor changed the output of a generator is a question about a subset of paths only.
Decide before you start. The choice determines how long the comparison takes (metadata-only walks finish in seconds, full hashing is bound by disk throughput) and it determines what you are entitled to claim afterwards. “No differences found” is only meaningful if you can say what was compared.
Names and sizes first, hashes second
A path-and-size comparison is nearly free: one recursive walk that reads directory entries and file metadata without opening a single file. It finds every added and removed path immediately, and it finds most changed files too, because almost any edit to a text file changes its length.
The gap is same-size, different-content pairs, and they are more common than intuition suggests. A version string changed from 1.0.3 to 1.0.4, a boolean flipped from “yes” to “no” by a sed script, a date rewritten, a swapped image of identical dimensions, a corrupted block in an otherwise intact archive — all keep the byte count exactly the same. Size equality is evidence, not proof.
That is what a cryptographic hash is for. SHA-256 reads every byte and produces a 32-byte fingerprint; two files with the same digest are, for any practical purpose, the same file. The efficient strategy is layered: hash only the pairs that already share a path and a size, because every other pair has been resolved by the cheap pass already.
Timestamps are a hint, never proof
Modification time is metadata, and metadata is trivially rewritten. Plain cp gives the copy a fresh mtime; cp -p and rsync -t preserve the original one; a build system may deliberately set a fixed timestamp for reproducible output. Git does not store mtime at all, so a fresh clone stamps every file with the moment of checkout — two identical working trees routinely show completely different timestamps.
Precision differs across filesystems too. ext4 and APFS keep nanosecond-scale timestamps, while FAT32 and exFAT store them with two-second granularity in local time — so the same file copied to a USB stick can appear one second older, or shift by a whole hour after a daylight-saving change. Network shares, container layers and archive formats each round differently.
The error runs in both directions. A different timestamp does not mean the content changed, and an identical timestamp does not mean it did not: any process can write new bytes and then restore the old mtime. Use timestamps to decide what to look at first, and use content to decide what actually differs.
Ignore what the machine generates
A raw recursive comparison of two project folders is usually drowned in noise: node_modules and .venv, .git and .svn, dist, build, target and .next, __pycache__ and coverage reports, plus the debris operating systems leave behind — .DS_Store on macOS, Thumbs.db and desktop.ini on Windows. None of it answers the question you asked.
Some generated artefacts differ on every single build by design: bundles with a content hash in the filename, source maps, archives that embed the creation time, binaries with an embedded build id. Comparing them produces guaranteed differences that carry no information, and worse, they train you to skim past the diff instead of reading it.
The opposite mistake is excluding too much. Lockfiles such as package-lock.json, poetry.lock or Cargo.lock are the record of what was actually installed and belong in the comparison. So do migration directories, .env templates and CI configuration. Keep the ignore list written down and versioned rather than improvised for each run — an ignore rule you cannot recall is a difference you never saw.
Symlinks, letter case and Unicode file names
Symbolic links force a choice: compare the link itself (its target string) or follow it and compare what it points at. Following links can walk out of the tree entirely, can loop forever on a cycle, and can make a directory of links look identical to a directory of real files. Comparing link targets as text is usually the honest option.
Case sensitivity is a classic source of “it works on my machine”. macOS with the default APFS setting and Windows NTFS treat README.md and Readme.md as the same name, Linux does not. A rename that only changes case is invisible on a case-insensitive machine and breaks the build on the Linux server that deploys it.
Unicode normalization is the quieter version of the same problem. macOS stores file names decomposed (NFD), most Linux tooling writes them composed (NFC), so a name like café.txt can exist as two different byte sequences that look identical on screen. A comparison that matches paths byte-for-byte will report one added file and one removed file where a human sees no change at all.
A three-pass workflow that scales
Pass one is structure. Compare the two sets of relative paths and resolve the added and removed entries before anything else. This is where the big surprises live — a directory that was moved, an export that never ran, a whole locale folder missing from the release.
Pass two is size. Among the paths present on both sides, flag every size mismatch; each one is a guaranteed change, so read those files first. In most real comparisons this pass plus the first one accounts for nearly every difference, at a cost of a few seconds.
Pass three is the hash, and only this pass can prove equality. If hashing everything is too slow, cap it by file size — but record which pairs you skipped and treat them as “assumed identical” rather than “identical”. A verification that quietly downgrades its own guarantee is worse than no verification at all.
Doing it locally, without uploading anything
Folder comparison used to mean installing a desktop tool, because the browser could not see a directory. That changed: a directory input (the webkitdirectory attribute) and the File System Access API both hand a page a list of local files with their relative paths and sizes, and neither transmits anything. The page receives handles, not uploads.
Hashing works the same way. crypto.subtle.digest is a native Web Crypto function, so SHA-256 over a file runs inside the tab at close to native speed. DiffBundle’s folder compare uses exactly this: it lists files up to 50 MB, hashes same-size pairs below a configurable cap, and tells you plainly which pairs were too large to verify.
The practical benefit is not convenience but scope. Source trees, client exports, database dumps and anything covered by an NDA can be compared without a discussion about which server saw the data, because no server did.
More guides
All guides
Comparing .env files safely across environments
Why environment files drift, which differences actually break things, and how to review keys without ever exposing a production secret.
8 min read · Updated September 2026

How to read diff output without misreading it
Unified diffs, hunk headers and side-by-side views — and why whitespace and line endings turn a one-character change into a huge diff.
9 min read · Updated September 2026