Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I got a mission to compare the content of hundreds of pair files. I have to quickly compare each pair and to provide an answer if that pair is equal (in content) or not. The files could be text or binary files. Can you help me please?

  1. I'm looking for a command that works on ALL UNIX \ Linux editions
  2. I'd prefer to use the most efficient command (in regards to time and performance)
  3. I'd prefer a command that supports text and binary files
  4. I'd prefer a command that is installed as part of the OS (not a 3rd-party)

Thank you!

share|improve this question
I'd recommend diff - man diff – codeling Oct 27 '13 at 7:17

If all you need to know is whether the files differ or not, use cmp. Or, more precisely:

if cmp "$FILE1" "$FILE2"; then
  echo same
  echo different

(Or whatever you need to do when they're equal/not-equal). cmp should be present on any posix-like system, works on both binary and text files, and returns immediately when it finds a difference, which is about as fast as you're going to get. (Also, because it's not line-aware, it doesn't waste time finding line-endings.)

share|improve this answer

diff command should do the job. Use it with -q option to print only the file names which differ in their contents.

diff -q file1 file2

If you want to entire files in a pair of directory, add -r option

diff -r -q dir1 dir2

Refer documentation for more details by typing man diff

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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