Linux Directory Comparison: 3 Commands to Verify Folders

Quick Linux Tip #118:

Question: I rsync'd two folders. How do I verify they truly match?

Try: diff -rq /source /destination

Info: Recursively compares directories and reports differing files or unique items without printing full diff contents.

Examples:

  • $ diff -rq /a /b | grep -v '^Only'  # Compare file contents only, ignoring missing files
  • $ rsync -avnc --delete src/ dst/  # Perform a dry-run sync preview to check discrepancies
  • $ find /src /dst -type f -exec md5sum {} + | sort | uniq -w32 -u  # Strict cryptographic checksum comparison

Note: diff -q is fast because it compares file sizes and timestamps before reading content. For rigorous verification, use rsync -c (checksum-based) or a file hash pipe.




LinuxTeck.com
linuxteck:~$ diff -rq /source /destination
Only in /source: newfile.txt
Only in /destination: oldfile.txt
Files /source/config.conf and /destination/config.conf differ
Files /source/data/db.json and /destination/data/db.json differ

linuxteck:~$ diff -rq /source /destination | wc -l
4

linuxteck:~$ rsync -avnc /source/ /destination/
sending incremental file list
newfile.txt
config.conf
data/db.json

sent 234 bytes  received 45 bytes  186.00 bytes/sec
total size is 123456  speedup is 442.68 (DRY RUN)
linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #117: Linux Process Environment Variables: 3 Commands to Inspect Running Daemons NEXT ARTICLE Quick Linux Tip #119: Linux Atomic File Rename: Safely Update Config Files
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.