What difference between cmp and diff commands?

Cmp - Compares two files byte by byte and displays the first mismatchdiff - tells the changes to be made to make the files identical

Showing Answers 1 - 13 of 13 Answers

parinita

  • Mar 30th, 2006
 

cmp <filename1> <filename2> gives the 1st byteno and lineno of file1 which is to be changed to make filename1 identical to filename2.

diff gives the text of  filename2 which is different from filename1.

we can use directory name in diff, but not in cmp

wow_suraj

  • May 7th, 2008
 

'cmp' and 'diff' both command are used to list the differences, the difference between both the command is that 'cmp' is used to find the difference between files whereas 'diff' is used to find the difference between directories.

cmp will list the line and column number that are different between two files.

diff will list the different files and sub-directories present between two directories.

UncaAlby

  • May 16th, 2010
 

diff is used primarily for files in text format, for example, source code.  It is used to list all of the differences between two files.

It is often used in source code control to get the changes necessary to update one file to the other.  That way, the source code control system can save space by only storing the differences between versions, instead of complete copies.

cmp is used primarily for binary files, and is generally only useful to answer the question, "Are these two binary files byte-for-byte identical? Yes or No."

  Was this answer useful?  Yes

Deepak

  • Sep 3rd, 2014
 

To check the differences between the data of two files cmp command is used. But it displays only the first difference.
Syn: $ cmp file1 file2
To display all the differences between the files diff command is used.
Syn: $ diff file1 file2
Note: Comparison between the files of different users is possible only when the present working user has the access permission on the other user.

  Was this answer useful?  Yes

Anupam Kumar

  • Nov 2nd, 2016
 

Com - will give the difference between two files; data available only in file 1 or file 2; data available in both the file.
Diff - will give difference between two file in a way that how file 1 and be in sync with file 2.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions