如何在 macOS 比對兩個資料夾
資料夾比對(Folder Compare)是找出兩個目錄之間「哪些檔案新增、刪除、或內容不同」的技術,常用於版本管理、備份驗證、以及部署前後的差異確認。
舉幾個你可能天天遇到的情境:確認備份硬碟和原始資料夾是否完全一致、部署網站前比對 build 輸出有沒有意外改動、把同事傳來的專案和自己手上的版本對齊、或是清理重複檔案前先看兩個資料夾差在哪。這些都是資料夾比對要解決的問題。
以下介紹三種在 macOS 上做資料夾比對的方法,從最快上手的 GUI 工具到 Terminal 指令都有,最後附一張對照表幫你選。
方法一:用 Lode(最直觀,推薦)
Lode 是一款原生 macOS 工具(Tauri 2 + Rust),整合了資料夾比對、檔案 Diff、全文搜尋與 Hex 檢視。Folder Compare 是其核心功能之一,後端用 Rust 非同步 I/O,掃描幾千個檔案幾乎是秒出。
操作步驟
- 下載並安裝 Lode
- 開啟 Lode,點選 Folder Compare 模式
- 將左側資料夾拖進左欄、右側資料夾拖進右欄
- Lode 立即展開雙欄樹狀結構並標色
顏色語義
| 顏色 |
意義 |
| 🟢 綠色 |
僅右側有(新增) |
| 🔴 紅色 |
僅左側有(刪除) |
| 🟠 橙色 |
兩側都有,但內容不同(修改) |
| ⬜ 白色 |
完全相同 |
雙擊橙色檔案,Lode 自動切換到 File Compare,側邊並列逐行 diff,逐行高亮顯示差異。比對結果裡還能直接用全文搜尋定位特定檔名或內容,對大型目錄特別有用。
小技巧
- 比對前先排除
.git、node_modules、.DS_Store 等雜訊目錄,結果會乾淨很多。
- 想只看「有差異的」項目時,用 Lode 的篩選把「完全相同(白色)」收起來,一眼就能掃到重點。
Rex 親身經驗:我平時用 Lode 比對 _site/ build 前後的差異,部署前快速確認沒有意外改動。之前用 Terminal 的 diff -rq 輸出太長、很難一眼掃過,Lode 的雙欄樹直覺多了——尤其是要在幾百個檔案裡找出那兩三個改動時,顏色標記比讀文字清單快太多。
方法二:Terminal diff -rq(無需安裝)
macOS 內建 diff 指令,加上 -r(recursive)和 -q(只顯示有差異的檔案)即可快速比對:
diff -rq /path/to/folder-A /path/to/folder-B
輸出會列出三類結果:Only in A:(A 獨有)、Only in B:(B 獨有)、Files A/x and B/x differ(兩邊都有但不同)。
只看特定副檔名(例如 .py):
diff -rq --include="*.py" /path/to/folder-A /path/to/folder-B
排除雜訊目錄:
diff -rq --exclude=.git --exclude=node_modules /path/to/folder-A /path/to/folder-B
優點:零安裝、可寫進腳本與 CI、輸出可被 grep / awk 二次處理。
限制:純文字輸出,大量檔案時難以閱讀;不支援圖形化逐行 diff;要看實際內容差異還得再對單檔跑一次 diff。
方法三:Xcode 內建 FileMerge
如果你已安裝 Xcode Command Line Tools,可以用 opendiff:
opendiff /path/to/folder-A /path/to/folder-B
這會開啟 Apple 的 FileMerge,提供基本的 GUI 比對介面,可以點進單檔看並列 diff。功能比 Lode 陽春(沒有全文搜尋、沒有 hex、UI 較舊),但完全免費且已預裝在裝有 Xcode 工具鏈的 Mac 上,臨時用一下很方便。
若還沒裝 Command Line Tools,執行 xcode-select --install 即可。
三種方法比較
| 工具 |
安裝需求 |
GUI |
即時搜尋 |
Hex 支援 |
適合情境 |
| Lode |
需安裝 |
✅ 雙欄樹 |
✅ |
✅ |
日常開發比對、備份驗證 |
diff -rq |
無(內建) |
❌ |
❌ |
❌ |
快速腳本、CI pipeline |
| FileMerge |
Xcode CLT |
✅ 基本 |
❌ |
❌ |
偶爾用、不想裝額外工具 |
怎麼選? 要寫進自動化腳本或 CI,用 diff -rq;偶爾比一次又不想裝東西,用 FileMerge;如果是天天要做、而且常需要進一步看內容差異或搜尋,Lode 的體驗最順。
常見問題
Q:Lode 支援 M1/M2/M3 嗎?
A:支援。Lode 是原生 Apple Silicon 編譯的 macOS App,在 M1/M2/M3 上執行流暢,啟動不到一秒。
Q:比對含大量小檔案的 node_modules 會很慢嗎?
A:Terminal diff -rq 在 node_modules 這類巨型目錄會很慢。Lode 的 Rust 後端用非同步 I/O 比較快,但仍建議排除 .git 和 node_modules 這類雜訊目錄,結果也比較好讀。
Q:可以只比對特定子目錄嗎?
A:可以。在 Lode 中,左右欄可以各自選不同深度的子目錄;Terminal 則直接傳入目標子目錄路徑即可。
Q:能比對兩顆外接硬碟或網路磁碟機嗎?
A:可以。只要該磁碟在 Finder 掛載得到,三種方法都能指向它的路徑(通常在 /Volumes/磁碟名稱/)。比對網路磁碟機時,速度會受網路頻寬影響。
Q:比對結果可以只看「有差異」的檔案嗎?
A:可以。diff -rq 本來就只列出有差異的;Lode 可以用篩選收起「完全相同」的項目,只留新增、刪除、修改。
How to Compare Two Folders on macOS
Folder comparison is the process of identifying which files were added, deleted, or modified between two directories — essential for version control, backup verification, and pre-deployment checks on macOS.
A few situations you probably hit often: confirming a backup drive exactly matches the source folder, checking a site’s build output for unexpected changes before deploying, aligning a project a colleague sent with your own copy, or seeing where two folders differ before cleaning up duplicates. Folder comparison solves all of these.
Here are three methods, from the most visual GUI tool to a built-in Terminal command, with a comparison table at the end to help you choose.
Method 1: Lode (Recommended — Most Visual)
Lode is a native macOS app (Tauri 2 + Rust) that combines folder compare, file diff, full-text search, and hex viewing in a single workbench. Folder Compare is one of its core modes, with a Rust async I/O backend that scans thousands of files near-instantly.
Steps
- Download and install Lode
- Open Lode and select the Folder Compare mode
- Drag the left folder into the left pane, right folder into the right pane
- Lode instantly renders a dual-tree view with color coding
Color legend
| Color |
Meaning |
| 🟢 Green |
Only on the right (added) |
| 🔴 Red |
Only on the left (deleted) |
| 🟠 Orange |
Present on both sides, content differs (modified) |
| ⬜ White |
Identical |
Double-click any orange file and Lode switches to File Compare — a side-by-side, line-level diff with changes highlighted. You can also full-text search within the results to jump to a specific filename or content, which is especially useful in large directories.
Tips
- Exclude noise directories like
.git, node_modules, and .DS_Store before comparing for much cleaner results.
- To see only what changed, use Lode’s filter to collapse the “identical (white)” entries so the additions, deletions, and modifications stand out.
From Rex’s experience: I use Lode to compare my _site/ build outputs before each deployment. The dual-tree makes it far easier to catch unexpected changes than scrolling through diff -rq plain text — especially when the goal is finding the two or three changes hidden among hundreds of files, where color coding beats reading a text list.
Method 2: Terminal diff -rq (No Install Required)
macOS ships with diff. The -r (recursive) and -q (only show differing files) flags are all you need:
diff -rq /path/to/folder-A /path/to/folder-B
The output lists three kinds of result: Only in A: (unique to A), Only in B: (unique to B), and Files A/x and B/x differ (present on both but different).
Filter by extension:
diff -rq --include="*.py" /path/to/folder-A /path/to/folder-B
Exclude noise directories:
diff -rq --exclude=.git --exclude=node_modules /path/to/folder-A /path/to/folder-B
Pros: Zero install, scriptable into CI, output can be post-processed with grep / awk.
Limitation: Text output only, hard to read at scale, no graphical line-level diff — to see actual content differences you still run diff again on a single file.
Method 3: Xcode FileMerge
If Xcode Command Line Tools are installed, run:
opendiff /path/to/folder-A /path/to/folder-B
This opens Apple’s FileMerge — a basic GUI where you can click into a single file for a side-by-side diff. It’s more bare-bones than Lode (no full-text search, no hex, dated UI), but it’s free and pre-installed on any Mac with the Xcode toolchain, handy for a one-off comparison.
If you don’t have the Command Line Tools yet, run xcode-select --install.
Comparison
| Tool |
Install |
GUI |
Live Search |
Hex |
Best for |
| Lode |
Yes |
✅ Dual-tree |
✅ |
✅ |
Daily dev workflow |
diff -rq |
None (built-in) |
❌ |
❌ |
❌ |
Scripts, CI pipelines |
| FileMerge |
Xcode CLT |
✅ Basic |
❌ |
❌ |
Occasional use |
How to choose? For automation or CI, use diff -rq; for a rare one-off without installing anything, use FileMerge; if you do this daily and often need to inspect content differences or search, Lode is the smoothest experience.
FAQ
Q: Does Lode support Apple Silicon (M1/M2/M3)?
A: Yes. Lode ships as a native Apple Silicon binary built with Rust, running natively on M1, M2, and M3 Macs, and cold-starts in under a second.
Q: Will comparing node_modules be slow?
A: Terminal diff -rq is slow on massive directories like node_modules. Lode’s Rust backend uses async I/O and is faster, but it’s still best to exclude noise directories like .git and node_modules — the results are easier to read too.
Q: Can I compare just a specific subdirectory?
A: Yes. In Lode, each pane can point to a different subdirectory at any depth; in Terminal, just pass the target subdirectory path directly.
Q: Can I compare two external drives or network volumes?
A: Yes. As long as the volume is mounted in Finder, all three methods can point to its path (usually under /Volumes/DriveName/). For network volumes, speed depends on bandwidth.
Q: Can I see only the files that differ?
A: Yes. diff -rq already lists only differing files; Lode can filter out the “identical” entries to leave just additions, deletions, and modifications.
🔨
本文介紹的工具:LodeThe tool featured in this article: Lode
原生 macOS 工作台,整合 Folder Diff、File Diff、Binary Diff、全文搜尋,一個 App 搞定。Native macOS workbench — Folder Diff, File Diff, Binary Diff, and full-text Search in one app.