- Last update:

How To Find Differences Between Two Directories On Linux

Different ways to diff two folders

🕒 Less than 1 min read

Category: Linux

Tags: linux, shell, diff

diff

Compares filenames and lines. Very slow.

/usr/bin/diff -qr /dirA /dirB

comm + find

Only compares filenames. Fast.

comm -3 <(find /dirA -type f -printf "%f\n"|sort) <(find /dirB -type f -printf "%f\n"|sort)

Also works with diff.

diff + find + md5sum

Compares filenames and content. Slow.

/usr/bin/diff <(find /dirA -type f -printf "%p " -exec md5sum '{}' \; | cut -d '/' -f1 | sort) \
    <(find /dirB -type f -printf "%p " -exec md5sum '{}' \; | cut -d '/' -f1 | sort)

git

Compares filenames and content. Slow.

git diff -D --no-index /dirA /dirB

Hope this helps.