Another way to compare the contents of two files at the byte level is to hash both of them and compare the hashes. (it's the entire purpose of digest hashes).
$ dd if=/dev/urandom of=file1 bs=1K count=10
10+0 records in
10+0 records out
10240 bytes (10 kB, 10 KiB) copied, 0.000148608 s, 68.9 MB/s
$ dd if=/dev/urandom of=file2 bs=1K count=10
10+0 records in
10+0 records out
10240 bytes (10 kB, 10 KiB) copied, 0.000145675 s, 70.3 MB/s
$ ls -l
total 24
-rw-r--r-- 1 foo foo 10240 Feb 9 17:47 file1
-rw-r--r-- 1 foo foo 10240 Feb 9 17:47 file2
$ sha256sum *
7986a677d3ef9a4f71ba18a5a7bd3a5f9a0c2d16939b4a43cd49fde86cef5a2f file
+1
3c946e3212d808dbb7471eecc07e454c459352a6a3e25230288fe5faf08af555 file
+2
This shows that despite file1 and file2 having precisely the same size, their contents differ because the SHA256 hashes differ. See sha256sum for more.
|