Diagnosing network packet captures, debugging compiled executable binaries, inspecting raw partition headers, and reverse-engineering proprietary firmware files in Linux requires visibility into raw byte structures. Standard terminal utilities like cat, less, or text editors cannot display binary payloads safely; non-printable ASCII control characters corrupt terminal emulators, produce distorted visual symbols, or freeze terminal sessions entirely.
The hexdump utility, included in the standard Linux bsdextrautils (or util-linux) package, is a high-speed data stream dumper. It translates binary streams and files into hexadecimal, octal, decimal, or ASCII interpretations, allowing software developers, security analysts, and system administrators to inspect exact byte layouts, verify magic number file signatures, and examine raw data structures safely in the command line.
The Canonical Hexadecimal Display (-C)
By default, executing hexdump without arguments formats data into two-byte octal words, which is unintuitive for modern reverse engineering. The industry standard method for running hexdump is using the canonical hex+ASCII format via the -C flag:
hexdump -C firmware.bin | head -n 20
Understanding the standard three-column canonical output:
00000000 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 |.ELF............|
00000010 03 00 3e 00 01 00 00 00 90 5b 00 00 00 00 00 00 |..>......[......|
- Left Column (Offset): The hexadecimal byte offset indicating where this row begins in the file (e.g.,
00000000). - Centre Column (Hexadecimal Bytes): Sixteen individual bytes rendered as two-character hex values (from
00toFF), split into two groups of eight for rapid scanning. - Right Column (ASCII Characters): The printable text representation of each byte enclosed inside vertical bars (
|). Non-printable bytes (such as null bytes or control characters) are rendered as period dots (.).
Validating File Headers and Magic Signatures
Operating systems and compilers identify file formats using “magic numbers” embedded in the initial bytes of a file. You can restrict hexdump to inspect only the first few bytes using the -n (length) flag:
# Inspect the first 16 bytes of an executable file
hexdump -C -n 16 /bin/bash
Output verification:
00000000 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 |.ELF............|
The leading bytes 7f 45 4c 46 correspond directly to the standard Linux .ELF (Executable and Linkable Format) binary header.
Skipping Direct to an Offset with -s
When analyzing large disk dumps or firmware images, you frequently need to jump past the master boot record (MBR) or bootloader to inspect specific partitions or filesystem superblocks:
# Skip the first 512 bytes (MBR) and inspect the next 64 bytes
hexdump -C -s 512 -n 64 disk_image.raw
You can also specify offsets using hexadecimal notation (for example, -s 0x200).
Inspecting Raw Device Partitions
Because hexdump streams binary bytes directly, you can pipe raw partition reads into it using dd or run hexdump directly against block devices (requires root privileges):
# Inspect the raw boot sector of a storage device
sudo hexdump -C -n 512 /dev/sda
This allows administrators to confirm whether bootloader partition signatures (like the trailing 55 aa MBR signature) are intact on corrupted drives.
Essential hexdump Command Flags Reference
| Flag | Option Name | Description |
|---|---|---|
-C |
Canonical hex+ASCII | Displays 16 hexadecimal bytes alongside printable ASCII characters. |
-n <length> |
Byte count | Interprets only the specified number of bytes before exiting. |
-s <offset> |
Seek offset | Skips the designated number of bytes from the file beginning. |
-v |
Verbose display | Forces display of duplicate lines rather than collapsing them with asterisks (*). |
-b |
One-byte octal | Displays offsets in hexadecimal and data in octal bytes. |
The hexdump utility provides Linux developers and administrators with a dependable, lightweight tool for analyzing low-level binary data, validating file integrity, and debugging embedded firmware systems.