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

hexdump [OPTIONS] [FILE...]

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

hexdump file.bin

Displays the file in default hexadecimal format

Canonical hex+ASCII format

hexdump -C file.bin

Shows hex values with ASCII representation (most commonly used)

Display first 100 bytes

hexdump -C -n 100 file.bin

Shows only the first 100 bytes in canonical format

Skip first 50 bytes

hexdump -C -s 50 file.bin

Starts display from byte 50 onwards

Character display

hexdump -c file.txt

Displays characters with escape sequences for non-printable chars

Decimal format

hexdump -d file.bin

Shows two-byte values in decimal format

Octal format

hexdump -o file.bin

Displays two-byte values in octal format

Two-byte hex format

hexdump -x file.bin

Shows two-byte values in hexadecimal

Show all data (no duplicate suppression)

hexdump -C -v file.bin

Displays all data without suppressing duplicate lines

Examine specific byte range

hexdump -C -s 100 -n 50 file.bin

Shows 50 bytes starting from offset 100

View file header

hexdump -C -n 32 image.jpg

Examines the first 32 bytes (header) of a JPEG file

Compare with xxd

hexdump -C file.bin xxd file.bin

Both commands show similar canonical hex+ASCII output

Output Format Examples

Canonical format (-C) output

$ echo "Hello World" | hexdump -C 00000000 48 65 6c 6c 6f 20 57 6f 72 6c 64 0a |Hello World.| 0000000c

Shows offset, hex bytes, and ASCII representation

Character format (-c) output

$ echo "Hello World" | hexdump -c 0000000 H e l l o W o r l d \n 000000c

Displays characters with escape sequences

Two-byte hex format (-x) output

$ echo "Hello World" | hexdump -x 0000000 6548 6c6c 206f 6f57 6c72 0a64 000000c

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

See also