7

I'd like to compare directories with binary files. Actually, I'm not interested in what the actual differences between files are, but to know if there's a differ (and what files differ). Previously I used meld, but it's cannot compare binary files.

What such file comparison tool can do this?

NOTE: It doesn't matter if it's a graphical tool or is just has a command-line.

  • Does the tool need to be graphical like meld or will things like diff and comm do? – terdon Nov 18 '14 at 11:55
  • @terdon - It doesn't matter. Thank you. I expanded the question. – Loom Nov 18 '14 at 12:04
11

This can easily be done with diff. For example:

$ ls -l foo/
total 2132
-rwxr-xr-x 1 terdon terdon 1029624 Nov 18 13:13 bash
-rwxr-xr-x 1 terdon terdon 1029624 Nov 18 13:13 bash2
-rwxr-xr-x 1 terdon terdon  118280 Nov 18 13:13 ls

$ ls -l bar/
total 1124
-rwxr-xr-x 1 terdon terdon 1029624 Nov 18 13:14 bash
-rwxr-xr-x 1 terdon terdon  118280 Nov 18 13:14 ls

$ diff bar/ foo/
Only in foo/: bash2

In the example above, the foo/ and bar/ directories contain binary files and bash2 is only in foo/.

So, you could run something simple like:

$ diff bar/ foo/ && echo "The directories' contents are identical"

That will show you the different files, if any, or print "The directories' contents are identical" if they are. To compare subdirectories and any files they may contain as well, use diff -r. Combine it with -q to suppress the output for text files.

  • 5
    You can recursively compare with diff too using the -r switch. – slm Nov 18 '14 at 12:19
  • 4
    and -q to disable actual diff output for text files. – rush Nov 18 '14 at 13:16
1

You can compare two files using cmp command

usage:

cmp file1 file2

It will give the number bytes difference and line number

  • cmp can't do recursive comparison. The OP wants to compare directories, not files. – Martin C. Martin Jun 14 '17 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.