How to Compare Two Folders in Linux
Find missing and changed files between two directories with diff, verify contents with sha256sum, compare folders across servers with rsync, or use Meld for a visual diff.
Quick Answer
To compare two folders in Linux, run diff -rq dir1 dir2. It lists files that exist in only one folder and files whose contents differ, including all subdirectories. For folders on different servers, use rsync -rcni --delete dir1/ server:dir2/, which shows the differences without copying anything.
Every command below is part of a standard Linux install (GNU diffutils, coreutils, rsync) and works the same way on Ubuntu, Debian, Fedora, Arch, and in WSL. The example output comes from two test folders, dir1 and dir2, where b.txt has different content and each side has one file the other lacks.
Method 1: diff -rq (the Standard Way)
$ diff -rq dir1 dir2
Files dir1/b.txt and dir2/b.txt differ
Only in dir1/sub: only1.txt
Only in dir2/sub: only2.txt-rrecurses into subdirectories.-qreports only whether files differ. Leave it out and diff prints every changed line inside every text file, which is useful for two copies of a source tree and overwhelming for anything else.Only in dir1/sub: only1.txtmeans the file exists only on that side.- No output and exit code 0 means the folders match. Exit code 1 means differences were found, so
diff -rq a b >/dev/null && echo sameworks in scripts.
Useful flags
# Also list files that are identical
diff -rqs dir1 dir2
# Skip folders and file types
diff -rq --exclude=".git" --exclude="*.log" dir1 dir2
# Treat a missing file as empty: reported as "differ" instead of "Only in"
diff -rqN dir1 dir2diff ignores dates and permissions
diff compares names and bytes only. A file copied without preserving its timestamp or mode still counts as identical. That is usually what you want when checking a backup, but not when auditing permissions. For metadata, see the rsync method below.
Method 2: Compare File Lists Only
On very large trees, reading every byte is slow. If you only need to know which files are missing, compare the file lists with find and comm (Bash or zsh):
$ comm -3 <(cd dir1 && find . -type f | sort) <(cd dir2 && find . -type f | sort)
./sub/only1.txt
./sub/only2.txtThe first column lists files only in dir1; the tab-indented second column lists files only in dir2. Use comm -23 to print just the first column (files missing from dir2). This finishes in seconds even on millions of files, but it cannot tell you whether a file present in both folders has changed.
Method 3: Compare by SHA-256 Checksum
Checksums are the most reliable way to prove that two folders hold the same data, and the list you create doubles as a record you can check again later. Build a sorted SHA-256 list for each folder and diff them:
(cd dir1 && find . -type f -exec sha256sum {} + | sort -k2) > dir1.sha256
(cd dir2 && find . -type f -exec sha256sum {} + | sort -k2) > dir2.sha256
diff dir1.sha256 dir2.sha256Any line that appears on only one side is a missing file or a file whose hash changed. Because the paths are relative (./b.txt), the two lists can come from different machines: run the first line on the old server and the second on the new one, then copy one file across.
To check a copy directly against the saved list, run sha256sum in verify mode inside the copy:
$ cd dir2 && sha256sum -c --quiet ../dir1.sha256
./b.txt: FAILED
sha256sum: ./sub/only1.txt: No such file or directory
./sub/only1.txt: FAILED open or read--quiet hides the OK lines, so only problems are printed. This direction finds files missing from or changed in the copy, but not extra files added to it. Our sha256sum verification guide covers the checksum format and common errors in more detail.
Method 4: rsync Dry Run (Best for Remote Folders)
rsync is normally a copy tool, but with -n (dry run) it only reports what it would do, which makes it a fast directory comparison that also works over SSH:
# Local folders
rsync -rcni --delete dir1/ dir2/
# Local folder vs a folder on another server
rsync -rcni --delete dir1/ user@server:/srv/dir2/-nis the dry run. Never drop it while comparing: with--delete, a real run removes files fromdir2.-ccompares contents by checksum instead of size and modification time.-iitemizes each difference:>f+++++++++is a file only indir1,>fcis a file whose content differs, and*deletingis a file only indir2.- Keep the trailing slash on
dir1/. Without it, rsync comparesdir1as a subfolder insidedir2and reports everything as new. - Add
-tor-pto also flag different timestamps or permissions.
GUI: Meld and KDiff3
For a visual comparison, Meld is the usual choice on GNOME-based desktops. Install it from your package manager (sudo apt install meld or sudo dnf install meld) and run meld dir1 dir2. It shows both trees side by side, colors missing and changed files, and lets you open any changed text file in a line diff. KDiff3 offers a similar directory view and fits KDE desktops. Both are free.
No desktop, or comparing a folder you copied from Windows or a Mac? The free Folder Compare tool runs in any browser: upload two folders (up to 100 files and 50 MB each) and it hashes them in memory on our server, without storing them, and lists missing, added, and changed files.
Repeatable Checks and Reports
The commands above answer βare these two folders the same right now?β They get awkward when you need to check the same folders every week, share the result with someone who doesn't use a terminal, or keep proof that a migration was complete before deleting the source.
FolderManifest does this as a desktop app for Linux, Windows 10/11, and macOS. It compares two folders by SHA-256, saves a folder manifest (every file with its path, size, dates, and hash), and exports the result as an HTML, CSV, or Markdown report. Its command-line interface ships inside the Linux app, so the same check can run from cron:
foldermanifest compare-folders /mnt/old-nas/projects /srv/projectsLike diff, it exits with code 1 when the folders differ, so scripts can alert on drift. Files are read locally and never uploaded. See the CLI documentation for every command, or our guides to comparing folders on Windows and on a Mac.
Frequently Asked Questions
How do I compare two directories in Linux?
Run diff -rq dir1 dir2. It walks both directories recursively and prints one line per difference: "Only in dir1/sub: file" for files that exist on one side only, and "Files dir1/x and dir2/x differ" for files whose contents differ. No output means the directories are identical.
How do I see only file names that differ, not the content?
Add -q (brief) to diff: diff -rq dir1 dir2. Without -q, diff -r prints the line-by-line changes inside every text file that differs, which is hard to read for large trees.
How do I compare two folders on different Linux servers?
Use rsync in dry-run mode: rsync -rcni --delete dir1/ user@server:/path/dir2/. The -n flag makes it change nothing; it only lists the files it would copy or delete. Alternatively, build a sha256sum list on each server and diff the two lists.
Does diff -r compare file dates and permissions?
No. diff compares names and contents only. Two files with the same bytes but different modification times or permissions are reported as identical. Use rsync -rcni with -t or -p, or ls -l, if metadata matters.
Is there a GUI to compare folders on Linux?
Yes. Meld (meld dir1 dir2) shows both trees side by side with missing and changed files highlighted, and KDiff3 offers a similar directory view. Both are in the package repositories of most distributions.
How do I exclude files or folders from the comparison?
diff accepts --exclude with a shell pattern, repeatable as needed: diff -rq --exclude=".git" --exclude="*.log" dir1 dir2. rsync uses the same idea: --exclude=".git".
Compare and Verify Folders on Linux Without Scripting
SHA-256 folder comparison, saved manifests, shareable reports, and a CLI for cron. Linux, Windows, and Mac. 7-day free trial, no card required, 30-day money-back guarantee.
