Diff command: diff stands for difference. This command is used to display the differences in the files by comparing the files line by line. it tells us which lines in one file have is to be changed to make the two files identical.
$ cat file1
shukla p.k.
chanchal singh
s.n.dasgupta
chakroborthy
$_
$ cat file2
barun sengupta
shukla p.k.
anil agrawal
chowdhary
s.n.dasgupta
$_
$ diff file1 file2
oal
> barun sengupta
2c3, 4
-------
> anil agarwal
> chakroborthy
$_
the instruction oa1 indicates that a single line has to appended after line number 0 of the first file and the resultant line will have line number 1 and 2 nd file.
Cmp Command: cmp command in Linux/UNIX is used to compare the two files byte by byte and helps you to find out whether the two files are identical or not.
Example:
$ cmp chap1 chap2
chap1 chap2 differ : char 9, line1
$_
The two files are compared byte by byte and the location of the first mismatch is echoed to the screen. If the two files are identical then cmp displays no message, but simply returns the $ prompt.
The –l (list) option gives detailed list of the byte number and the differing bytes in octal for each character that differs in both the files.
$ cat file1
abcd
xyz
$ cat file2
Abed
wxy
$_