OD Command Usage Examples

by Ramesh

od command dumps a file in octal, decimal, and other formats.

Use OD on a text file

The following sample text file is used in the examples below.

  1. $ cat sample-file.txt
  2.  
  3. abc de
  4. f h

Option –b and –c are typical usages as shown below.

  • -b is same as option -t oC, select octal bytes
  • -c is same as option -t c, select ASCII characters or backslash escapes
  1. # od -c special-chars.txt
  2.  
  3. 0000000 a b c \t d e \n f \t h
  4. 0000020 \n
  5. 0000021
  6.  
  7. # od -bc special-chars.txt
  8.  
  9. 0000000 141 142 143 040 011 144 145 012 146 040 040 040 040 040 011 150
  10. a b c \t d e \n f \t h
  11. 0000020 012
  12. \n
  13. 0000021

Use OD on a binary file

Read the first 16 bytes and display equivalent ASCII characters or backslash:

  1. # od -N16 -c /usr/bin/h2xs
  2.  
  3. 0000000 # ! / u s r / b i n / p e r l \n
  4. 0000020

Read the first 16 bytes and display equivalent names characters:

  1. # od -N16 -a /usr/bin/h2xs
  2.  
  3. 0000000 # ! / u s r / b i n / p e r l nl
  4. 0000020

Read the first 16 bytes and display octal bytes:

  1. # od -N16 -bc /usr/bin/h2xs
  2.  
  3. 0000000 043 041 057 165 163 162 057 142 151 156 057 160 145 162 154 012
  4. # ! / u s r / b i n / p e r l \n
  5. 0000020