od

fileLinux/Unix
The od command is one of the most frequently used commands in Linux/Unix-like operating systems. od Dump files in octal and other formats

Quick Reference

Command Name:

od

Category:

file

Platform:

Linux/Unix

Basic Usage:

od [options] [arguments]

Common Use Cases

    Syntax

    od [options] [file...]

    Options

    Option Description
    -A, --address-radix=RADIX Output format for file offsets: d (decimal), o (octal), x (hexadecimal), n (none)
    -j, --skip-bytes=BYTES Skip BYTES input bytes before reading
    -N, --read-bytes=BYTES Limit dump to BYTES input bytes
    -S, --strings[=BYTES] Output strings of at least BYTES graphic characters (default 3)
    -t, --format=TYPE Select output format (see table below)
    -v, --output-duplicates Do not use * to mark line suppression
    -w, --width[=BYTES] Output BYTES bytes per output line (default 16)
    --traditional Accept arguments in traditional form
    --help Display help information and exit
    --version Output version information and exit

    Format Types:

    Type Description
    a Named character
    c ASCII character or backslash escape
    d[SIZE] Signed decimal, SIZE bytes per integer
    f[SIZE] Floating point, SIZE bytes per number
    o[SIZE] Octal, SIZE bytes per integer
    u[SIZE] Unsigned decimal, SIZE bytes per integer
    x[SIZE] Hexadecimal, SIZE bytes per integer
    z Printable characters or "." for non-printable

    SIZE Specifiers:

    Specifier Description
    C sizeof(char)
    S sizeof(short)
    I sizeof(int)
    L sizeof(long)
    1 1 byte
    2 2 bytes
    4 4 bytes
    8 8 bytes

    Examples

    How to Use These Examples

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

    # Basic Examples Basic
    od -t x1 file.bin
    Display file content in hexadecimal format, one byte per unit.
    od -c file.txt
    Display file content in character format.
    # Advanced Examples Advanced
    od -t x1z -A x file.bin Display file content in hexadecimal with character interpretation and hexadecimal address. od -j 100 -N 200 -t d4 file.bin Skip 100 bytes, then display 200 bytes in decimal format, 4 bytes per unit. od -t x1 -t c -v file.bin Display file content in both hexadecimal and character formats, showing all duplicate lines. echo "Hello World" | od -a Pipe text to od and display in named character format. od -t x1 -w16 file.bin Display hexadecimal output with 16 bytes per line. od -t fD file.bin Display file content as floating point numbers (double precision). od -t d1 -t c -t x1 file.bin Display file content in decimal, character, and hexadecimal formats. xxd -p file.bin | tr -d '\n' | od -t x1 -A n Use xxd to create continuous hex, then format with od.

    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 od (octal dump) command is a versatile utility in Unix and Linux systems for examining file contents in various formats. Originally designed to display file contents in octal format (hence the name), it has evolved into a powerful tool that can output data in numerous formats including hexadecimal, decimal, character, and floating-point representations. Unlike more specialized file viewers or editors, od is particularly useful for examining binary files, data files with non-printable characters, or any file where you need to see the exact byte values. System administrators, programmers, and security professionals frequently use od for debugging, analysis, and verification tasks. Key features of the od command: 1. Multiple Output Formats: od can display file contents in various formats including octal, decimal, hexadecimal, character, and floating-point, making it suitable for different analysis needs. 2. Customizable Display: The command offers extensive options to control how data is formatted and displayed, including the number of bytes per line, the starting offset, and the amount of data to display. 3. Combination of Formats: od allows displaying the same data in multiple formats simultaneously, which is useful for correlating different representations of the same data. 4. Address Formatting: The command can display file offsets in different bases (decimal, octal, or hexadecimal) or can suppress offset display entirely. 5. Duplicate Line Handling: By default, od replaces consecutive identical lines with an asterisk to reduce output size, but this behavior can be disabled. 6. Data Selection: The command allows specifying which parts of a file to examine by skipping a certain number of bytes from the beginning and limiting the total number of bytes to display. Common use cases for od include: - Examining binary files when you need to see the exact byte values - Debugging programs by examining their input or output data - Verifying file formats or checking for corruption in data files - Inspecting files containing non-printable characters - Analyzing network packet captures or memory dumps - Comparing binary files at the byte level - Educational purposes for understanding data representation While newer tools like hexdump or xxd may offer more user-friendly interfaces for hexadecimal dumps, od remains valuable due to its flexibility in format selection and its universal availability on Unix-like systems. It's part of the GNU Coreutils package, ensuring it's available on virtually all Linux distributions without additional installation. The od command can be combined with other Unix utilities like head, tail, or grep to further refine the analysis process. For instance, you might use head and od together to examine just the beginning of a large file, or pipe the output of od to grep to search for specific byte patterns.

    Related Commands

    These commands are frequently used alongside od 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 od command works in different scenarios.

    $ od
    View All Commands