diff
Using cmp it can only be known if the files compared are other. diff neither displays the extent to that the files are different nor how different they are. diff command compares two files for make differences. It denotes which lines must be modified to make the two files identical. The diff command scans two files and denotes editing modification which must be made to the first file to make it identical to the second file. Editing must involve adding a line, changing a line, deleting a line, and etc.
Syntax
diff file1 file2
In the given syntax file1 and file2 are the files to be compared.
Practice 1
The given example displays the usage of the cmp command in comparing two files - file1 and file2
# cat file2
diff
login
kill
mv
ln
more
pg
^D
# cat file1
diff
id
sh
mv
ln
^D
# diff file1 file2
2,3c2,3
< id
< sh
--
> login
> kill
5a6,7
> more
> pg
From the given above example it can be seen in which lines starting with < are found only in the first file and lines starting with > are found only in the second file. A dashed line separates the two lines which appear in the similar place in the differing files. The numerals denote exactly where and how the differences occur.
In the given output, the second and the third lines from file1 have to be changed with second and third lines of file2 to make the two files agree. This is denotes through 2, 3c2, 3.
Likewise, 5a6, 7 denotes in which the lines 6 and 7 of file2 required to be appended to file1 to make them equal. Likewise sign'd' could be used to delete lines from file1 if these lines do not exist in file2.
Note: diff command create changes in the first file to make it resemble second file. This command is used to compare files on a line to line basis.