Using rsync
:
rsync --dry-run --recursive --delete --links --checksum --verbose /dir1/ /dir2/ > dirdiff_2.txt
# or same in short
rsync -nrlcv --delete /dir{1,2}/ > dirdiff_2.txt
Alternatively, using diff
:
diff --brief --recursive --no-dereference --new-file --no-ignore-file-name-case /dir1 /dir2 > dirdiff_1.txt
# or same in short
diff -qrN --no-dereference --no-ignore-file-name-case /dir{1,2} > dirdiff_1.txt
They are functionally equivalent, but performance may vary depending on:
- If the directories are on the same drive, rsync is faster.
- If the directories reside on two separate drives, diff is faster.
This is because diff puts an almost equal load on both directories in parallel, maximizing load on the two drives. rsync calculates checksums in large chunks before actually comparing them. That groups the i/o operations in large chunks and leads to a more efficient processing when things take place on a single drive.