hexdump

file managementLinux/Unix
The hexdump command is one of the most frequently used commands in Linux/Unix-like operating systems. hexdump Display file contents in hexadecimal, decimal, octal, or ASCII

Quick Reference

Command Name:

hexdump

Category:

file management

Platform:

Linux/Unix

Basic Usage:

hexdump [options] [arguments]

Common Use Cases

    Syntax

    hexdump [options] file

    Options

    Option Description
    -b, --one-byte-octal One-byte octal display
    -c, --one-byte-char One-byte character display
    -C, --canonical Canonical hex+ASCII display (16 bytes per line)
    -d, --two-bytes-decimal Two-byte decimal display
    -e, --format=format Specify format string for displaying data
    -f, --format-file=file Specify file containing format strings
    -n, --length=length Interpret only length bytes of input
    -o, --two-bytes-octal Two-byte octal display
    -s, --skip=offset Skip offset bytes from the beginning
    -v, --no-squeezing Display all lines (don't omit duplicate lines)
    -x, --two-bytes-hex Two-byte hexadecimal display

    Examples

    How to Use These Examples

    The examples below show common ways to use the hexdump command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    hexdump file.bin
    Display the contents of file.bin in hexadecimal and ASCII.
    hexdump -C file.bin
    Display file contents in canonical hex+ASCII format.
    hexdump -x file.bin
    Display two-byte hexadecimal output. # Advanced Examples Advanced hexdump -e '16/1 "%02x " "\n"' file.bin Use custom format to display 16 bytes per line in hexadecimal. hexdump -n 32 file.bin Display only first 32 bytes of the file. hexdump -s 512 file.bin Skip first 512 bytes and display the rest. hexdump -v file.bin Display all lines, even if identical to previous lines.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The hexdump command displays file contents in various formats, including hexadecimal, decimal, octal, and ASCII. It's particularly useful for examining binary files, debugging data formats, and understanding file structure at the byte level. Key features of hexdump: 1. Multiple Display Formats: hexdump supports various output formats including one-byte octal (-b), one-byte character (-c), two-byte decimal (-d), two-byte octal (-o), and two-byte hexadecimal (-x). 2. Canonical Format: The -C option provides a canonical hex+ASCII display with 16 bytes per line, which is the most commonly used format for binary analysis as it shows both hex values and their ASCII representation. 3. Custom Formatting: The -e option allows for creating custom output formats, giving complete control over how data is presented, which is useful for specialized analysis tasks. 4. Partial File Reading: Using -n and -s options, hexdump can examine specific portions of a file, which is valuable when working with large files or when only certain sections are of interest. 5. Duplicate Line Handling: By default, hexdump uses an asterisk to indicate when multiple lines have the same content; the -v option forces display of all lines. 6. Offset Display: Each line begins with an offset indicating the position in the file, helping to locate specific byte positions. 7. Standard Input Support: When no file is specified, hexdump reads from standard input, allowing it to be used in pipelines with other commands. Hexdump is an essential tool for system administrators, programmers, and digital forensics experts who need to examine file contents at the binary level. It helps identify file types, troubleshoot encoding issues, analyze data structures, and reverse-engineer file formats. The command is particularly valuable when working with executable files, disk images, network packet captures, or any data where the raw byte representation is important.

    Related Commands

    These commands are frequently used alongside hexdump or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the hexdump command works in different scenarios.

    $ hexdump
    View All Commands