LinuxCommandLibrary

od

Dump file contents in various formats

TLDR

Display file using default settings: octal format, 8 bytes per line, byte offsets in octal, and duplicate lines replaced with *

$ od [path/to/file]
copy

Display file in verbose mode, i.e. without replacing duplicate lines with *
$ od [[-v|--output-duplicates]] [path/to/file]
copy

Display file in hexadecimal format (2-byte units), with byte offsets in decimal format
$ od [[-t|--format]] [x] [[-A|--address-radix]] [d] [[-v|--output-duplicates]] [path/to/file]
copy

Display file in hexadecimal format (1-byte units), and 4 bytes per line
$ od [[-t|--format]] [x1] [[-w|--width=]]4 [[-v|--output-duplicates]] [path/to/file]
copy

Display file in hexadecimal format along with its character representation, and do not print byte offsets
$ od [[-t|--format]] [xz] [[-A|--address-radix]] [n] [[-v|--output-duplicates]] [path/to/file]
copy

Read only 100 bytes of a file starting from the 500th byte
$ od [[-N|--read-bytes]] 100 [[-j|--skip-bytes]] 500 [[-v|--output-duplicates]] [path/to/file]
copy

SYNOPSIS

od [OPTION]... [FILE]...
od -t TYPE [OPTION]... [FILE]...

PARAMETERS

-A RADIX, --address-radix=RADIX
    Determines the base (RADIX) for displaying file offsets. Common options include d (decimal), o (octal), x (hexadecimal), or n (none).

-t TYPE, --format=TYPE
    Specifies the output format. TYPE is a string that can combine character type and size, e.g., a (named char), c (ASCII char), d[SIZE] (decimal), f[SIZE] (float), o[SIZE] (octal), x[SIZE] (hexadecimal). SIZE can be 1, 2, 4, 8, or type codes like C (char), S (short), I (int), L (long).

-j BYTES, --skip-bytes=BYTES
    Skips BYTES bytes from the beginning of the input before dumping. BYTES can be followed by b for blocks (512 bytes), k for kilobytes, m for megabytes, etc.

-N BYTES, --read-bytes=BYTES
    Limits the output to a maximum of BYTES bytes from the input.

-v, --output-duplicates
    Displays all input data explicitly. By default, od replaces lines of identical content with a single line containing an asterisk (*).

-w[BYTES], --width[=BYTES]
    Sets the number of input bytes displayed per output line. If BYTES is omitted, it defaults to 32 bytes.

-b, --octal-bytes
    Displays bytes in octal (equivalent to -t o1).

-c, --characters
    Interprets bytes as ASCII characters or backslash escapes (equivalent to -t c).

-d, --decimal
    Displays short decimal words (equivalent to -t u2, unsigned 2-byte decimal).

-x, --hex-long
    Displays long hexadecimal words (equivalent to -t x4).

-o, --octal
    Displays short octal words (equivalent to -t o2).

DESCRIPTION

The od (octal dump) command is a Unix utility used to display the contents of files in various human-readable formats, such as octal, hexadecimal, decimal, ASCII characters, and floating-point representations. It is primarily used for debugging, examining binary files, or inspecting files that contain non-printable characters. By default, od displays the file content in octal bytes, but its strength lies in its extensive formatting options, allowing users to specify the output radix (base), byte grouping, and data type. It can also skip a certain number of bytes from the input or limit the number of bytes read, making it invaluable for analyzing specific sections of large files.

CAVEATS

While powerful for low-level inspection, od is not suitable for editing files. Its output can be very verbose for large files, making specific data points hard to locate without filtering. Interpretation of multi-byte data types can be sensitive to system endianness, which can sometimes be controlled but requires careful consideration. The traditional od syntax (e.g., specifying an offset as a non-option argument) can be confusing and is generally less flexible than the modern option-based syntax.

DEFAULT OUTPUT BEHAVIOR

By default, od will replace sequences of identical output lines (except the first and last lines) with a single asterisk (*) on a line by itself. This behavior can be suppressed using the -v or --output-duplicates option for a complete dump of the file.

FLEXIBLE FORMATTING WITH -T

The -t TYPE option is extremely versatile. For instance, -t x1 dumps in hexadecimal bytes, -t d4 dumps in 4-byte decimal integers, and -t fL dumps in long double-precision floating-point numbers. Combining different TYPE specifiers (e.g., -t cx2) can display character and 2-byte hexadecimal values side-by-side, offering a comprehensive view.

HISTORY

The od command has a long history, originating in early versions of Unix. It was part of the original AT&T Unix and has been a standard utility in Unix-like operating systems ever since. It is specified in POSIX and is included in the GNU Core Utilities, which are fundamental components of GNU/Linux distributions. Its primary usage has remained consistent: providing a byte-level view of file contents for debugging and analysis.

SEE ALSO

hexdump(1), xxd(1), strings(1), file(1), cat(1)

Copied to clipboard