hexdump Command
The hexdump command displays the contents of files in hexadecimal format. It's essential for examining binary files, debugging data structures, and understanding file formats at the byte level.
Syntax
Description
The hexdump command is a versatile utility for displaying file contents in various formats, primarily hexadecimal. It's invaluable for analyzing binary files, debugging programs, and understanding data structures.
Key features:
- Display files in hexadecimal format
- Show ASCII representation alongside hex
- Support for various output formats
- Ability to skip bytes and limit output
- Custom format specifications
Common Options
| Option | Description |
|---|---|
-C |
Canonical hex+ASCII display (16 bytes per line) |
-c |
One-byte character display |
-d |
Two-byte decimal display |
-o |
Two-byte octal display |
-x |
Two-byte hexadecimal display |
-n length |
Interpret only length bytes of input |
-s offset |
Skip offset bytes from beginning |
-v |
Display all input data (no duplicate suppression) |
Examples
Basic hexadecimal display
Displays the file in default hexadecimal format
Canonical hex+ASCII format
Shows hex values with ASCII representation (most commonly used)
Display first 100 bytes
Shows only the first 100 bytes in canonical format
Skip first 50 bytes
Starts display from byte 50 onwards
Character display
Displays characters with escape sequences for non-printable chars
Decimal format
Shows two-byte values in decimal format
Octal format
Displays two-byte values in octal format
Two-byte hex format
Shows two-byte values in hexadecimal
Show all data (no duplicate suppression)
Displays all data without suppressing duplicate lines
Examine specific byte range
Shows 50 bytes starting from offset 100
View file header
Examines the first 32 bytes (header) of a JPEG file
Compare with xxd
Both commands show similar canonical hex+ASCII output
Output Format Examples
Canonical format (-C) output
Shows offset, hex bytes, and ASCII representation
Character format (-c) output
Displays characters with escape sequences
Two-byte hex format (-x) output
Shows two-byte values in hexadecimal (little-endian)
Common Use Cases
When to Use hexdump
- Binary Analysis - Examining executable files and libraries
- File Format Investigation - Understanding file headers and structure
- Data Debugging - Analyzing data corruption or encoding issues
- Network Protocols - Examining packet captures and network data
- Reverse Engineering - Understanding proprietary file formats