4

I'm using cmp (GNU diffutils) 3.7 and I'm confused by the output of cmp -l/--verbose ("output byte numbers and differing byte values").

I have two files that are almost identical except for a few bytes at the beginning:

$ ls -n x*
-rw-rw-r-- 1 1000 1000 345776 Jun 16 10:41 x-6.xz
-rw-rw-r-- 1 1000 1000 345776 Jun 16 10:04 x-9.xz
$ hexdump -C x-6.xz | head -3
00000000  fd 37 7a 58 5a 00 00 04  e6 d6 b4 46 02 00 21 01  |.7zXZ......F..!.|
00000010  16 00 00 00 74 2f e5 a3  e2 1c bb ef ff 5d 00 39  |....t/.......].9|
00000020  18 4a a7 22 04 94 b3 4a  c8 bc d2 00 4b 8c be aa  |.J."...J....K...|
$ hexdump -C x-9.xz | head -3
00000000  fd 37 7a 58 5a 00 00 04  e6 d6 b4 46 02 00 21 01  |.7zXZ......F..!.|
00000010  1c 00 00 00 10 cf 58 cc  e2 1c bb ef ff 5d 00 39  |......X......].9|
00000020  18 4a a7 22 04 94 b3 4a  c8 bc d2 00 4b 8c be aa  |.J."...J....K...|
$ diff <(hexdump -C x-6.xz) <(hexdump -C x-9.xz)
2c2
< 00000010  16 00 00 00 74 2f e5 a3  e2 1c bb ef ff 5d 00 39  |....t/.......].9|
---
> 00000010  1c 00 00 00 10 cf 58 cc  e2 1c bb ef ff 5d 00 39  |......X......].9|
$ 

What puzzles me is when I do cmp -l:

$ cmp -l x-6.xz x-9.xz 
    17  26  34
    21 164  20
    22  57 317
    23 345 130
    24 243 314
$ 

It seems to say that byte 17 has value 26 in x-6.xz and value 34 in x-9.xz. That's wrong: in fact, byte 16 (i.e. 0x10) has values 0x16 and 0x1c (22 and 28 respectively). Furthermore, cmp says byte 23 has value 345. How can a byte possibly be more than 255? I must be misinterpreting the meaning of the output, but man cmp doesn't seem to say what it is.

1
  • 1
    While man cmp only shows a concise description, info diffutils cmp includes the details too. – fra-san Jun 16 at 10:26
10

cmp counts offsets starting from 1 and displays byte values in octal:

17  26  34

means that the byte at offset 17 (0x10 in the hexdump output, since it starts at 0) has value 026 octal, i.e. 22 decimal, in the first file, and 034 octal, i.e. 28 decimal, in the second file.

1
  • 3
    Thanks! Octal usage is so rare these days, I often forget that many utilities still use it for backwards compatibility. – k314159 Jun 16 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.