ZetCode

Linux od Command

last modified October 23, 2026

The od (octal dump) command prints the bytes of a file in octal, hexadecimal, decimal, or as characters. It shows what a file really contains: invisible characters such as tabs and carriage returns, the bytes of UTF-8 characters, binary integers and floating-point numbers, and the headers of binary formats.

The syntax is od [options] [file...]; without a file, od reads standard input. Its main options are -t (output type), -A (offset format), -N (number of bytes to read), and -j (bytes to skip). The examples use GNU od from coreutils 9.1 on a little-endian x86-64 machine.

Default output

Without options, od prints the data as two-byte octal numbers.

od hello.txt

Each line starts with the offset of its first byte, also in octal. The last line holds only the offset after the final byte, which is the file size: 0000016 in octal is 14 bytes. The default format is a relic of the PDP-11 era and is rarely what you want; the following examples choose the format explicitly.

$ od hello.txt
0000000 062510 066154 026157 053440 071157 062154 005041
0000016

Showing characters

The -c option prints each byte as a character, with escape sequences for non-printable bytes.

od -c hello.txt
od -c dos.txt

This is the quickest way to find invisible characters. The file dos.txt uses tabs (\t) between the columns and Windows line endings (\r\n), which often cause problems in shell scripts and Unix tools. Bytes without a printable form are shown as three-digit octal numbers.

$ od -c hello.txt
0000000   H   e   l   l   o   ,       W   o   r   l   d   !  \n
0000016
$ od -c dos.txt
0000000   n   a   m   e  \t   a   g   e  \r  \n   A   n   n   a  \t   2
0000020   4  \r  \n
0000023

Hexadecimal bytes and offsets

The -t x1 option prints each byte as a two-digit hexadecimal number. The -A option sets the radix of the offsets: o (octal, the default), x, d, or n for none.

od -t x1 hello.txt
od -A x -t x1 hello.txt
od -A n -t x1 hello.txt

With -A x, the final offset 00000e shows the size of 14 bytes directly in hexadecimal. -A n drops the offsets, which is useful when the bytes are processed further.

$ od -t x1 hello.txt
0000000 48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 21 0a
0000016
$ od -A x -t x1 hello.txt
000000 48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 21 0a
00000e
$ od -A n -t x1 hello.txt
 48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 21 0a

Hexadecimal with characters

The z suffix appends the printable characters of each line, as in a classic hex dump. Several -t options print several formats for each line.

od -A x -t x1z hello.txt
od -t x1 -t c hello.txt

With -t x1z, non-printable bytes are shown as dots between the > and < markers. With two -t options, each format gets its own line, and the columns are aligned so that each character stands below its hexadecimal code.

$ od -A x -t x1z hello.txt
000000 48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 21 0a        >Hello, World!.<
00000e
$ od -t x1 -t c hello.txt
0000000  48  65  6c  6c  6f  2c  20  57  6f  72  6c  64  21  0a
          H   e   l   l   o   ,       W   o   r   l   d   !  \n
0000016

Multi-byte words and byte order

The -x option, short for -t x2, prints two-byte words. The bytes of each word are combined in the machine's byte order.

od -x hello.txt
od -t x2 --endian=big hello.txt

On a little-endian machine, the first word is 6548, although the file starts with H (48) followed by e (65). This byte swapping is a common source of confusion; use -t x1 to see bytes in file order. The --endian option selects the byte order explicitly.

$ od -x hello.txt
0000000 6548 6c6c 2c6f 5720 726f 646c 0a21
0000016
$ od -t x2 --endian=big hello.txt
0000000 4865 6c6c 6f2c 2057 6f72 6c64 210a
0000016

Signed and unsigned bytes

The same byte can be read as a signed number, an unsigned number, or a named character.

od -A n -t x1 bytes.bin
od -A n -t d1 bytes.bin
od -A n -t u1 bytes.bin
od -A n -t a bytes.bin

The bytes 80 and ff are -128 and -1 as signed values (d1) and 128 and 255 as unsigned values (u1). The a type prints ASCII names such as nul and del; it ignores the high bit, so 80 is shown as nul and ff as del.

$ od -A n -t x1 bytes.bin
 41 00 7f 80 ff
$ od -A n -t d1 bytes.bin
   65    0  127 -128   -1
$ od -A n -t u1 bytes.bin
  65   0 127 128 255
$ od -A n -t a bytes.bin
   A nul del nul del

Reading binary integers

A number after the type letter sets the size in bytes. The -N option limits how many bytes are read and -j skips bytes at the start.

od -A d -t x1 ints.bin
od -A d -t d4 -N 8 ints.bin
od -A d -t u2 -j 8 ints.bin

The file holds two 32-bit integers, 1 and 1000, followed by a 16-bit unsigned value of 65535, all in little-endian order. The first eight bytes are read as d4 values, and the last two bytes, starting at offset 8, as a u2 value. Decimal offsets (-A d) make the positions easy to follow.

$ od -A d -t x1 ints.bin
0000000 01 00 00 00 e8 03 00 00 ff ff
0000010
$ od -A d -t d4 -N 8 ints.bin
0000000           1        1000
0000008
$ od -A d -t u2 -j 8 ints.bin
0000008 65535
0000010

Floating-point numbers

The f type reads IEEE floating-point numbers: f4 for single precision and f8 for double precision.

od -A d -t f4 -N 4 floats.bin
od -A d -t f8 -j 4 floats.bin

The file contains a 4-byte float with the value 3.14 and an 8-byte double with 2.718281828, written by a small Python struct.pack call. Reading binary data with the wrong type or offset gives meaningless numbers, so the layout of the file must be known.

$ od -A d -t f4 -N 4 floats.bin
0000000            3.14
0000004
$ od -A d -t f8 -j 4 floats.bin
0000004              2.718281828
0000012

Inspecting a file header

Binary formats start with a signature, or magic number. od can read it without loading the whole file.

od -A x -t x1z -N 16 /bin/ls
od -A n -c -N 4 /bin/ls
od -A n -t x1 -j 4 -N 2 /bin/ls

An ELF executable starts with the byte 7f followed by ELF. The next two bytes say that this is a 64-bit file (02) in little-endian order (01). The file command uses the same signatures to identify file types.

$ od -A x -t x1z -N 16 /bin/ls
000000 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00  >.ELF............<
000010
$ od -A n -c -N 4 /bin/ls
 177   E   L   F
$ od -A n -t x1 -j 4 -N 2 /bin/ls
 02 01

Repeated lines

od replaces repeated identical lines with an asterisk. The -v option prints all lines.

head -c 64 /dev/zero | od -A d -t x1
head -c 64 /dev/zero | od -A d -t x1 -v | head -n 3

The 64 zero bytes produce four identical lines, which od shortens to the first line and a *. This keeps dumps of disk images and sparse files short. Use -v when the output is processed by another program.

$ head -c 64 /dev/zero | od -A d -t x1
0000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*
0000064
$ head -c 64 /dev/zero | od -A d -t x1 -v | head -n 3
0000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0000016 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0000032 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Bytes per line

The -w option sets how many bytes are printed per line. The default is 16.

od -A d -t x1 -w8 hello.txt

With -w8, each line holds eight bytes, and the offsets increase by eight.

$ od -A d -t x1 -w8 hello.txt
0000000 48 65 6c 6c 6f 2c 20 57
0000008 6f 72 6c 64 21 0a
0000014

Random numbers

Combined with /dev/urandom, od turns random bytes into numbers or hexadecimal strings.

od -A n -t u4 -N 4 /dev/urandom
od -A n -t x8 -N 8 /dev/urandom | tr -d ' '

The first command prints a random 32-bit unsigned integer, the second a 16-digit hexadecimal string, for example for a temporary token. The output is different on every run.

$ od -A n -t u4 -N 4 /dev/urandom
 3811314404
$ od -A n -t x8 -N 8 /dev/urandom | tr -d ' '
8a0b0368b1f53fdf

od and hexdump

hexdump -C and xxd print a similar canonical hex dump. od is part of coreutils and POSIX, so it is available on practically every system.

hexdump -C hello.txt

The output corresponds to od -A x -t x1z. hexdump comes from util-linux or, on Debian, the bsdextrautils package; xxd comes with Vim.

$ hexdump -C hello.txt
00000000  48 65 6c 6c 6f 2c 20 57  6f 72 6c 64 21 0a        |Hello, World!.|
0000000e

Best practices for od

Source

GNU od manual

In this article, we have used the od command to display files as characters, hexadecimal, and decimal values, read binary integers and floating-point numbers, and inspect file headers.

Author

My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.

List all Linux tutorials.