How to compare two folders and see what differs
Comparing by name and size is fast, and wrong often enough to matter. Which level of comparison you need depends on what you are actually asking.
Short answer
Name and size catches most differences instantly. Content catches the rest and costs a full read of both trees. Decide which question you are asking before you start, because the fast answer is wrong precisely when it matters.
Three levels, three costs
By name. Which files exist on one side and not the other. Instant, and it answers “did everything get copied” but not “did it get copied correctly”.
By name, size and modification time. Adds “and are they plausibly the same”. Still instant — the filesystem already knows all three — and it is what almost every sync tool uses. It misses a file whose contents changed without changing length, which is more common than it sounds: a fixed-width record edited in place, an image with its metadata rewritten, a file whose timestamp was restored by the thing that corrupted it.
By content. Read both files and compare, or hash both and compare the hashes. Certain, and it costs a full read of both trees.
The useful habit is to run the cheap comparison first and the expensive one only on what it flagged — plus, if the answer really matters, a sample of what it did not.
Which one your question needs
- “Did my backup copy everything?” — name and size. If a file is missing it will show, and that is the failure you are looking for.
- “Is this copy safe to rely on before I wipe the original?” — content. This is the case where being wrong costs you the data, and it is the one where size-and-time comparison quietly passes a corrupted file. See copying a large folder.
- “Which of these two folders is newer?” — neither, on its own. You need to know what both looked like last time, or you are guessing from timestamps.
- “What did this installer put on my disk?” — a snapshot before and a snapshot after, compared. See what an uninstaller left behind.
The traps
Timestamps lie routinely. Copying a file usually gives the copy a new modification time; some tools preserve it and some do not. FAT32 stores times to two-second precision, so a file can differ by a second and be identical. Daylight saving has historically shifted whole trees by an hour on Windows.
Case. Report.pdf and report.pdf are two files on Linux and one file on
Windows and on a default macOS volume. Comparing across platforms will report
differences that are not there, or hide ones that are.
Symbolic links. Following them compares what they point at, which may be outside the tree entirely, and can loop. Not following them compares the links themselves. Both are defensible; a tool that does not say which it does is not.
Files that are being written. A comparison of a live folder is a comparison of a moving target, and the difference it reports may have stopped being true before it finished printing.
What your machine already does
diff -rq folderA folderB # macOS / Linux: names and contents, recursive
rsync -rvnc --delete A/ B/ # dry run, checksum comparison, both directions of difference
robocopy A B /L /E /NJH /NJS # Windows: /L lists without copying anything
rsync -n is the best single answer on Unix if you already have it: -n makes
it a dry run, -c forces content comparison instead of size-and-time, and the
output is the list of what it would change.
The programs for this
- CopySure —
diffcompares two existing trees by content, andcopydoes the copy and verifies it in one pass. - MirrorFlow —
statusanswers the harder question: given what both sides looked like last time, what changed on each, and where do the two genuinely conflict. That needs a baseline, which is why it has aninit. - AppSweep — snapshot a tree, snapshot it again later, and report what was added, removed and changed between the two. Comparing a folder against its own past rather than against another folder.
- MoveGuard —
--dry-runlists every file that would move and the problems the real run would hit, which is a comparison with a purpose.
Free while we are in preview, one file each, Windows and Mac.