Basics of od Michelle Craig - Jan 2001 ------------------------------------------------------------------------------- od is a utility to allow you to see the contents of a non-text file. It works ok for a text file too but is not necessary. You can learn about od by typing "man od" on unix but that can be confusing at first. Here are some pointers. I've created a file odExample that contains, some characters, followed by the binary representation of the integer 2 followed by 4 bytes where I individually manipulated the bits. My recommended use of flags for od is -bc which displays the file in individual bytes. On the first line, the octal representation of each byte is given. The second line contains the character with the corresponding ASCII code. So character data looks like an octal number above the character. Notice that the last byte of my file is the code for "m". I didn't intend to have this interpretted as an "m" necessarily. I could have wanted 01101101 in that byte to represent any number of things. >dvp.cs> od -bc odExample > >0000000 123 157 155 145 040 103 150 141 162 141 143 164 145 162 163 000 > S o m e C h a r a c t e r s \0 >0000020 000 000 002 000 010 150 155 > \0 \0 002 \0 \b h m >0000027 The -c option produces the character interpretation of the file. If you know that your bytes don't represent characters you might not find this useful and might want just the -b flag. The produces the octal separately for each byte. >dvp.cs> od -b odExample >0000000 123 157 155 145 040 103 150 141 162 141 143 164 145 162 163 000 >0000020 000 000 002 000 010 150 155 >0000027 Similarly you can omit the -b flag and just use od -c. This gives you characters only whenever the ASCII code corresponds to a printable character. >dvp.cs> od -c odExample >0000000 S o m e C h a r a c t e r s \0 >0000020 \0 \0 002 \0 \b h m >0000027 If you don't choose any flags the default is to group the file into 2-byte pairs. To determine the octal number, each group of 2 bytes is grouped into 3-bit groups and converted to an octal digit. This can be useful but can also be very confusing at first because the 2 higher order bits from the right byte are combined with the lowest order bit from the left byte. >dvp.cs> od odExample >0000000 051557 066545 020103 064141 071141 061564 062562 071400 >0000020 000000 001000 004150 066400 >0000027 If you like hex better than octal, you might want to try od -x which gives you a hexidecimal interpretation. You can combine the x flag with -c as well. >dvp.cs> od -x odExample >0000000 536f 6d65 2043 6861 7261 6374 6572 7300 >0000020 0000 0200 0868 6d00 >0000027