-1

$ cmp -s file1 file2

The above command doesn't return anything for the following cases:

  • Case 1: both files (file1 and file2) are different;
  • Case 2: both files (file1 and file2) are same.

I tried all the above cases, but my unix system is insensitive.

closed as off-topic by DopeGhoti, Thomas Dickey, Thomas, msp9011, telcoM Aug 11 '18 at 9:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – DopeGhoti, Thomas Dickey, Thomas, msp9011, telcoM
If this question can be reworded to fit the rules in the help center, please edit the question.

4

-s is for silent, it's to tell cmp not to output anything¹ but only to reflect whether the files are identical or not in its exit status so that it can be used for instance in an if shell statement:

if cmp -s file1 file2; then
  echo same
else
  echo differ or error
fi

Or:

cmp -s file1 file2 && rm file2

If you want it to output something, remove the -s. Then cmp will output a message when the files differ stating where they start to differ.


¹ except with some implementations for error messages when files can't be opened, not when they differ.

  • I got understood. I am new to Unix, I never went to shell programming learning till now. Thanks. – Gopinath Pushpa Thirunavukaras Aug 10 '18 at 17:35
1

I would question your case 1. If cmp doesn't return anything then the files likely are identical. Try diff file1 file and sum file1 file2 to confirm. Is it possible that the differences are in non-printable characters?

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