Search code examples
linuxbinaryfilesfile-typeoctal

what are the numbers shown by od -c -N 16 <filename.png>


I'm using linux and when I typed od -c -N 16 <filename.png>
I got 0000000 211 P N G \r \n 032 \n \0 \0 \0 \r I H D R 0000020. I thought this command tells me the type of the file but I'm curious about what the number 0000000 and 211 means. Can anybody please help?


Solution

  • od means "octal dump" (analogous to the hexdumper hd). It dumps bytes of a file in octal notation.

    211 octal is 2 * 82 + 1 * 81 + 1 = 137, so you have a byte of value 137 there.

    The 0000000 at the beginning of the line and the 0000020 at the beginning of the next are positions in the file, also in octal. If you remove -N 16 from the call, you'll see a column of monotonously ascending octal numbers on the left side of the octal dump; their purpose is to make it instantly visible which part of a dump you're currently reading.

    The parameter

    -N 16
    

    means to read only the first 16 bytes of filename.png, and

    -c
    

    is a format option that tells od

    • to print printable characters as characters themselves rather than the octal code, and
    • to print unprintable characters that have a backslash escape sequence (such as \r or \n) as that escape sequence rather than an octal number.

    It is the reason that not all bytes are dumped in octal.

    If you want to know the file type of a file, use the file utility:

    file filename.png
    

    Side note: You may be interested in the man command, which shows the manual page of (among other things) command line tools. In this particular case,

    man od
    

    could have been enlightening.