About od
The od (octal dump) command is a powerful Unix/Linux utility that displays file contents in various formats including octal, hexadecimal, decimal, and ASCII. It's essential for examining binary files, debugging file formats, inspecting special characters, and analyzing raw data structures.
Common Use Cases:
- Examining binary executables and data files
- Finding hidden or special characters in text files
- Debugging file format issues
- Analyzing network packet captures
- Inspecting configuration files for non-printing characters
- Converting between different number bases
- Verifying file integrity and structure
| Option | Description |
|---|---|
-A [doxn] |
Address base: d=decimal, o=octal, x=hexadecimal, n=none |
-t [acdoux] |
Output format: a=named chars, c=ASCII, d=decimal, o=octal, u=unsigned, x=hex |
-N [bytes] |
Limit output to specified number of bytes |
-j [bytes] |
Skip specified number of bytes before dumping |
-w[bytes] |
Output specified number of bytes per line |
-v |
Show all data (don't use * for repeated lines) |
-c |
Character display (equivalent to -t c) |
-x |
Hexadecimal 2-byte display (equivalent to -t x2) |
Example 1Basic Octal Dump
Display a file in traditional octal format (default behavior):
Explanation:
- First column shows byte offset in octal (0000000 = byte 0)
- Following columns show 2-byte words in octal format
- 062510 = "He" (H=110 octal, e=145 octal, little-endian: 145 110)
- Final line (0000014) shows total bytes (12 decimal = 014 octal)
- Default behavior groups bytes as 16-bit words
-x) or character (-c) formats for better readability.
Example 2Hexadecimal Display
Display file contents in hexadecimal format with ASCII sidebar:
Explanation:
-A x: Show addresses in hexadecimal-t x1: Display bytes as 1-byte hexadecimal valuesz: Add ASCII representation in the right column- 48 = 'H', 65 = 'e', etc. in ASCII hex values
- 0a = newline character
- The > < markers show the ASCII interpretation
hexdump -C and is excellent for examining binary files where you need to see both hex values and their ASCII equivalents.
Example 3Character Display with Special Characters
Display file showing special and control characters by name:
Explanation:
-A d: Show addresses in decimal-c: Display characters with special char names\t: Tab character (ASCII 9)\n: Newline character (ASCII 10)\0: Null character (ASCII 0)- 001, 002: Control characters shown in octal
- Printable characters shown as-is
Example 4Decimal Byte Values
Display file contents as unsigned decimal byte values:
Explanation:
-A n: Don't show address offsets-t u1: Display as unsigned 1-byte decimal values-w1: Show one byte per line- 65 = 'A', 66 = 'B', 67 = 'C' in ASCII decimal
- 10 = newline character
- Useful for converting characters to decimal codes
Example 5Multiple Format Display
Display the same data in multiple formats simultaneously:
Explanation:
- First
-t x1: Shows hexadecimal byte values - Second
-t c: Shows character representation - Both formats use the same address offsets
- 54 65 73 74 = "Test" in hex
- Allows quick cross-referencing between formats
- Can combine as many
-toptions as needed
Example 6Examining Specific Byte Ranges
Skip to a specific location and dump a limited number of bytes:
Explanation:
-j 20: Skip first 20 bytes (jump)-N 16: Read only 16 bytes after skip- Address starts at 000014 (hex) = 20 (decimal)
- Ends at 000024 (hex) = 36 (decimal) = 20+16
- Useful for examining specific sections of large files
- Avoids loading entire file into memory
Example 7Finding Hidden Characters in Text Files
Detect problematic whitespace and control characters:
Explanation:
\r\n: Windows-style line ending (CR+LF)\t: Tab character followed by spaces\n: Unix-style line ending (LF only)- Reveals invisible formatting issues
- Critical for debugging cross-platform text issues
- Shows exact whitespace differences
od to identify these issues quickly.
Example 8Examining Binary File Headers
Inspect magic numbers and file format identifiers:
Explanation:
- First 4 bytes:
7f 45 4c 46= ELF magic number - 45 4c 46 = "ELF" in ASCII
- Byte 4 (02): 64-bit format
- Byte 5 (01): Little-endian encoding
- Byte 6 (01): Current ELF version
-N 32: Only examine first 32 bytes- All Linux executables start with this ELF header
od to verify file types when extensions are missing or incorrect.
Example 9Comparing File Differences at Byte Level
Identify exact byte-level differences between similar files:
Explanation:
- Process substitution feeds
odoutput todiff - Byte 7: 6f (o) vs 61 (a) - the difference
- "World" vs "Warld" difference clearly visible
- Hexadecimal comparison shows exact byte change
- More precise than text diff for binary files
- Useful for detecting subtle corruption or modifications
cmp -l which shows only the differing bytes, or xxd with diff for a more visual side-by-side comparison.
Example 10Creating a Hex Dump for Documentation
Generate a clean, formatted hex dump suitable for documentation or reports:
Explanation:
-A x: Hex addresses for consistency-t x1: Single-byte hex values-w16: Exactly 16 bytes per line (standard width)-v: Show all data (no asterisk abbreviations)- Creates consistent, predictable output format
- Ideal for technical documentation or bug reports
- Easy to copy/paste and annotate
od -A x -t x1z -w16 -v filename. This format is widely recognized and easy to read in technical documentation.
The default octal output is counterintuitive. Most users expect hex.
Solution: Always use -t x1 or -x for hexadecimal output, which is more commonly understood.
By default, od uses asterisk (*) to indicate repeated identical lines, hiding data.
Solution: Use -v flag to show all data without abbreviation: od -v file
Multi-byte formats may show bytes in reverse order due to endianness.
Solution: Use single-byte formats (-t x1) to avoid confusion, or understand your system's endianness.
Running od on huge files without limits can be slow.
Solution: Use -N to limit bytes read, or -j to skip to relevant sections: od -N 1024 largefile
Check file magic numbers to verify file types:
Should show: 89 50 4e 47 for valid PNG files
When text displays incorrectly, check the actual byte values:
High bit set (80-FF) indicates non-ASCII encoding (UTF-8, Latin-1, etc.)
Use od with xxd -r to create binary test files from hex dumps:
Inspect program memory dumps at specific addresses:
Useful for debugging segmentation faults and memory corruption
When examining captured network packets:
First 24 bytes are pcap file header, followed by packet data
od command dates back to AT&T Unix Version 1 (1971). Its name reflects the original emphasis on octal notation, which was more common in early computing. While hexadecimal has become the standard, od remains a essential tool for systems administrators and developers working with binary data.
| Task | Command |
|---|---|
| Basic hex dump with ASCII | od -A x -t x1z file |
| Show special characters | od -c file |
| Decimal byte values | od -A n -t u1 file |
| Skip and limit bytes | od -j 100 -N 50 file |
| 16 bytes per line, all data | od -A x -t x1 -w16 -v file |
| Check file magic number | od -A n -t x1 -N 4 file |
| Multiple format display | od -A x -t x1 -t c file |
| Standard hex dump format | od -A x -t x1z -w16 -v file |