What is the fastest way to check whether two directories match

Back to list2026-02-07
You

What is the fastest way to check whether two directories match?

ChatGPT

Checksums of the file list, not a byte-by-byte diff:

cd a && find . -type f -exec sha256sum {} + | sort -k2 > /tmp/a.txt
cd ../b && find . -type f -exec sha256sum {} + | sort -k2 > /tmp/b.txt
diff /tmp/a.txt /tmp/b.txt

This also tells you which side differs, which diff -r on large trees takes far longer to reach.

You

What should be at the top of every bash script?

ChatGPT

Three lines that turn silent breakage into loud breakage:

#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

-e stops on error, -u rejects unset variables, pipefail makes a failing command inside a pipe fail the whole pipe. The last one is what catches curl ... | tar x quietly producing nothing.