7.3 Comparing Files
The easiest way to check if two files are identical is cmp
, which compares files byte by byte and complains at the first byte they differ.
To demonstrate, let’s first create two small files with identical content and then compare them with cmp
:
Since these files are identical, cmp
does not give any output.
Let’s next change one of the files a little and compare again:
Now we are told that these files differ at byte 14 on line 1. That is exactly where a.txt
has a ‘u’ and b.txt
has an ‘n’ (count from the first letter to check).