Easy way to compare two iMac files to see if they are identical or where they differ?

I have two files with identical names I would like to compare them and see if I can send one to the trash.


[Re-Titled by Moderator]

iMac 21.5″

Posted on May 3, 2025 11:07 PM

Reply
Question marked as Top-ranking reply

Posted on May 3, 2025 11:14 PM

You can compare two files entirely in Terminal—e.g. cmp file1 file2 returns nothing if they’re identical (exit code 0) and nonzero if not, while diff -u file1 file2 shows unified-diff-style line-by-line differences  . For a graphical view, use Xcode’s FileMerge (invoked via opendiff file1 file2), which opens a dual-pane diff window with colored bands highlighting insertions, deletions, and changes  . If you need folder-level comparisons or more polished UIs, third-party tools like DiffMerge, Meld, Beyond Compare, or Kaleidoscope offer side-by-side file and directory diffs with intra-line highlighting and merge capability  . Finally, for a quick binary or integrity check, run md5 file1; md5 file2 (or shasum) to compare checksums—identical hashes mean identical files  .

3 replies
Question marked as Top-ranking reply

May 3, 2025 11:14 PM in response to lmd72

You can compare two files entirely in Terminal—e.g. cmp file1 file2 returns nothing if they’re identical (exit code 0) and nonzero if not, while diff -u file1 file2 shows unified-diff-style line-by-line differences  . For a graphical view, use Xcode’s FileMerge (invoked via opendiff file1 file2), which opens a dual-pane diff window with colored bands highlighting insertions, deletions, and changes  . If you need folder-level comparisons or more polished UIs, third-party tools like DiffMerge, Meld, Beyond Compare, or Kaleidoscope offer side-by-side file and directory diffs with intra-line highlighting and merge capability  . Finally, for a quick binary or integrity check, run md5 file1; md5 file2 (or shasum) to compare checksums—identical hashes mean identical files  .

May 3, 2025 11:24 PM in response to lmd72

In Terminal app…


To compare file1.txt and file2.txt using diff in Terminal: 


diff -s /Users/yourusername/documents/file1.txt /Users/yourusername/documents/file2.txt


If the output is:


Files /Users/yourusername/documents/file1.txt and /Users/yourusername/documents/file2.txt are identical

Then the files are identical. 


open Terminal, type…


diff -s


then a space, then drag 1st file to Terminal then drag 2nd file to terminal press enter.

May 4, 2025 2:37 AM in response to Kaioliver

Sure, Philippe! Here’s your answer in English, fully adapted for macOS users who want to compare two Mac computers—specifically, directory structures and file contents—and identify differences between them.






Accessing Both Systems


To compare directories between two Macs, ensure both are accessible:


  • Use network sharing (SMB or AFP),
  • Mount one as an external disk, or
  • Use SSH / rsync / scp if you’re comfortable with the terminal.


Basic Comparison with diff



If you can access both directories locally (or one is mounted), this is the quickest command:


diff -qr /path/to/folder1 /path/to/folder2


  • -q: brief output (only shows differences)
  • -r: recursive comparison


🔍 This shows:


  • Files that exist in only one directory
  • Files that differ in content


Advanced Comparison with rsync (no copy)



To check for differences without copying anything:


rsync -avun /path/folder1/ /path/folder2/


  • -n: dry-run (no actual transfer)
  • -u: only consider newer files
  • -a: archive mode (preserves metadata)
  • -v: verbose



Graphical Comparison with Meld (recommended)



Install via Homebrew:

brew install --cask meld


Then run:


meld /path/to/folder1 /path/to/folder2


🧩 This gives you a visual diff of:



Deep File-Level Comparison with Hash Checks


For full integrity checks (e.g., duplicates or corrupt files), generate file hashes:


find /path/folder1 -type f -exec shasum {} \; > hash1.txt
find /path/folder2 -type f -exec shasum {} \; > hash2.txt
diff hash1.txt hash2.txt


This detects even subtle differences in binary or text content.




This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Easy way to compare two iMac files to see if they are identical or where they differ?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.