VMware ESXi and vSphere Cluster Management
Using the od Command for Octal, Hexadecimal, Decimal, and Character Dumps in Linux
Learn how to use Linux od to inspect files and standard input as octal, hexadecimal, decimal, and character data, including offsets, ranges, and control characters.
od is a Unix and Linux command whose name is short for octal dump. It reads bytes from a file or from standard input and renders those bytes in a selected display format.
Its traditional default display is octal, but od can also show hexadecimal, decimal, character, and several combined representations. This makes it useful when ordinary text tools cannot clearly show the contents of a file.
What od is used for
A byte is a unit of file data, commonly consisting of eight bits. A byte may represent a printable character, part of a multibyte encoded character, a control character, or arbitrary binary data.
od is useful for inspecting:
- Binary files and executable program files
- File headers and data structures
- Control characters such as tabs, carriage returns, null bytes, and newlines
- Unexpected whitespace or line endings
- Character encoding details
- A short region of a large file without opening the entire file in an editor
od is read-only: it displays input and does not modify the input file.
Basic syntax
od [options] [file]
When you provide a file operand, od reads that file. If you omit the file, it reads standard input, the input stream supplied by a pipe, redirection, or interactive entry.
od sample.txt
printf 'Hello\n' | od -c
Option names and some older option forms vary slightly between GNU/Linux and other Unix implementations. On the system you are using, consult man od.
Reading the default octal output
Octal is a base-8 number system using digits from 0 through 7. With no display-format option, od uses octal output.
printf 'Hi\tthere\n' > sample.txt
od sample.txt
A typical GNU/Linux result on a little-endian system is:
0000000 064510 072011 062550 062562 000012
0000011
The input contains nine bytes: H, i, a tab, t, h, e, r, e, and a newline. The final offset 0000011 is octal for decimal 9.
The leading value on each data line is an offset: the byte position in the input where that line's displayed data begins. The default offset is octal, and the default values are octal too. Traditional default output may group bytes into wider integer units, so one displayed number is not necessarily one visible character or one byte. For a one-byte-at-a-time view, use a type string such as -t o1.
Comparing common output formats
The underlying bytes do not change when the display format changes. Only their textual representation changes.
Hexadecimal output
Hexadecimal is base 16. It uses digits 0 through 9 and letters A through F. One hexadecimal digit represents four bits, so two hexadecimal digits map directly to one byte.
od -x sample.txt
od -t x1 sample.txt
The -x form commonly displays grouped hexadecimal integers. The -t x1 form explicitly requests one-byte hexadecimal values, which is usually clearer for raw binary data.
od -Ax -t x1 sample.txt
Here, -A x requests hexadecimal offsets and -t x1 requests hexadecimal byte values. For example, a byte shown as 48 is hexadecimal for decimal 72, the ASCII value for H. The offset tells you where that byte occurs in the file.
Decimal output and signed values
Decimal is the base-10 numbering system. The abbreviated option -i selects signed decimal integer output:
od -i sample.txt
A signed integer representation treats the highest bit of the selected integer width as a sign bit. Consequently, values with that bit set can appear as negative numbers.
Be careful when interpreting -i: it generally displays grouped integer units, not independent bytes. Whether a negative result appears depends on the selected width and the surrounding bytes. If you need signed one-byte values specifically, use a one-byte signed type such as -t d1. If you need ordinary byte values from 0 through 255, use the unsigned form:
od -t u1 sample.txt
Character output and hidden control characters
The -c option displays printable bytes as characters and represents nonprintable bytes with escapes or symbolic notation.
od -c sample.txt
Typical character-oriented output can make data such as the following visible:
- Newline, commonly shown as
\n - Horizontal tab, commonly shown as
\t - Carriage return, commonly shown as
\r - Null, commonly shown as
\0or a symbolic equivalent - Other nonprintable bytes using escaped or named notation
This is useful for detecting trailing whitespace and checking whether a text file ends with a newline.
printf 'with-newline\n' > with-newline.txt
printf 'without-newline' > without-newline.txt
od -c with-newline.txt
od -c without-newline.txt
In common ASCII-compatible environments, newline is one byte. That is not a universal property of every possible character encoding: some encodings or line-ending conventions can represent a line break with multiple bytes, such as carriage return followed by newline.
Selecting formats with -t
The -t option uses a flexible type string. A type string selects a representation and may include a width suffix.
c— characters, including escaped control characterso— octal integersu— unsigned decimal integersd— signed decimal integersx— hexadecimal integers
Common width suffixes are C, S, I, and L, where supported. They select character-sized, short-sized, integer-sized, and long-sized units. A numeric suffix such as 1 explicitly requests one-byte units:
od -t o1 sample.txt
od -t u1 sample.txt
od -t x1 sample.txt
od -t x1c sample.txt
Multiple type letters can request multiple representations of the same input:
od -t x1c sample.txt
This produces hexadecimal byte values together with character-oriented output, which is convenient for matching a raw byte to its printable or escaped character equivalent.
Offsets, address radices, skipping, and limits
An offset is a byte position, usually counted from the beginning of the input. A radix is the number base used to display a value.
od -Ax -t x1 binaryfile
od -Ad -t x1 binaryfile
-A x displays offsets in hexadecimal, while -A d displays them in decimal. The default address radix is commonly octal.
Use -j to skip an initial number of bytes and -N to limit the number of bytes read:
od -An -j 16 -N 32 -t x1 binaryfile
This command skips the first 16 bytes, reads at most the next 32 bytes, and displays individual bytes in hexadecimal. -A n suppresses the offset column, which can make a small selected range easier to copy or compare.
A practical workflow for a known region is:
- Use a tool that identifies the interesting location, or begin with a small header range.
- Use
-jto move to the suspected byte offset. - Use
-Nto restrict the inspection window. - Use
-A x -t x1for a byte-oriented hexadecimal view. - Use
-cor-t x1cwhen printable text may be embedded in the binary data.
Repeated-line suppression
When consecutive output lines are identical, od may replace the repeated lines with a single line containing an asterisk. This commonly occurs in long runs of zero bytes or other repeated data.
od -t x1 binaryfile
od -v -t x1 binaryfile
The -v option forces every repeated line to be printed. Use it when the exact length and position of a repeated region matter.
Reading piped data
You do not need to create a temporary file to inspect command output:
printf 'Hello\n' | od -c
printf 'ABC' | od -An -t x1
The pipe sends the output of printf to od's standard input. This is useful for checking generated data, protocol fragments, encoded values, and shell command output.
Aliases for interactive use
An alias is a shell-defined shorthand for another command. These temporary aliases last only for the current interactive shell:
alias odhex='od -Ax -t x1'
alias odchar='od -c'
alias odoct='od -t o1'
To make them available in future Bash sessions, append them to ~/.bashrc and reload that file:
printf "%s\n" "alias odhex='od -Ax -t x1'" "alias odchar='od -c'" "alias odoct='od -t o1'" >> ~/.bashrc
source ~/.bashrc
Aliases are shell-specific and are intended mainly for interactive convenience. Do not rely on them in scripts. Use the complete od command and its options in scripts instead.
Byte offsets versus text line numbers
od reports byte offsets, not text line numbers. A line number counts logical text lines, while a byte offset counts stored bytes from the start of the input.
nl -ba sample.txt
Use nl or another text-oriented command when your question is “which text line contains this content?” Use od when your question is “which bytes are stored at this position?”
How to interpret an od line
Safe and effective usage
- Quote paths containing spaces, wildcard characters, dollar signs, or other shell-special characters:
od -c 'data files/sample one.bin'. - Use
-Nfor large files so you do not produce an overwhelming amount of output. - Pipe long output through a pager such as
less:od -Ax -t x1 large.bin | less. - Use
-jand-Nwhen investigating a known byte range. - Use
-vwhen suppressed repeated lines would hide information you need. - Check the local manual page because supported type strings, widths, and option forms can differ between implementations.
Troubleshooting
The first column does not match decimal byte positions
The default offset is commonly octal. Use -A x for hexadecimal offsets or -A d for decimal offsets.
An asterisk replaces repeated data lines
od has compressed consecutive identical output lines. Add -v to print every line.
Decimal output contains negative numbers
The chosen output interprets grouped values as signed integers. Use -t u1 for unsigned individual byte values, or -t d1 when signed one-byte interpretation is specifically required.
The output contains strange symbols or backslash sequences
The input probably contains nonprintable bytes or control characters. Use -c to identify common controls, or -t x1 for an unambiguous hexadecimal byte view.
The output is too large
Limit the range with -j and -N, and optionally use less as a pager.
The command is being used to find a text line number
od reports byte offsets. Use nl -ba sample.txt for visible text line numbers.
An alias works interactively but not in a script
Aliases are often disabled or unavailable in noninteractive shells. Replace the alias with the complete command and options.
Exam-relevant notes
odmeans octal dump and reads files or standard input.- Its default display is octal, including commonly octal offsets.
-xselects hexadecimal integer output;-iselects signed decimal integer output;-cselects character output.-tprovides flexible type strings such asu1,o1,x1, andx1c.-Aselects the radix or suppresses offsets,-jskips bytes,-Nlimits input, and-vdisables repeated-line suppression.- Offsets are byte positions, not text line numbers.
- Use unsigned byte output when values from 0 through 255 are required.
Quick reference
od sample.txt # Default octal view
od -x sample.txt # Hexadecimal integers
od -i sample.txt # Signed decimal integers
od -c sample.txt # Characters and escaped controls
od -t o1 sample.txt # One-byte octal values
od -t u1 sample.txt # One-byte unsigned decimal values
od -t x1 sample.txt # One-byte hexadecimal values
od -t x1c sample.txt # Hexadecimal bytes plus characters
printf 'Hello\n' | od -c # Read standard input
od -Ax -t x1 binaryfile # Hexadecimal offsets and bytes
od -An -j 16 -N 32 -t x1 binaryfile # Inspect a bounded byte range
od -v -t x1 binaryfile # Print repeated lines
nl -ba sample.txt # Number text lines
man od # Read local documentation