The od command in Linux: dump files in octal and hexadecimal format

Introduction to the od command

The od (octal dump) command is a standard Linux tool that allows dumping the content of any file into different numeric representations, the most used being octal and hexadecimal. Its name comes from octal dump, although over time it has gained the ability to display data in hexadecimal, decimal, ASCII characters, and more. This utility is indispensable for programmers, system administrators, and security analysts who need to inspect binary data, verify file integrity, or debug applications at a low level.

Basic syntax

The simplest way to use od is to specify the file to examine and, optionally, the output format. The general syntax is:

od [options] file

If no file is indicated, od reads from standard input, allowing it to be combined with pipes and other commands.

Octal dump

By default, od displays data in octal, two bytes per word (format -o or simply without options). Each line begins with the offset address in octal followed by groups of octal values.

Basic example:

od -o file.bin

This will produce an output where each number represents three bits, useful when needing to inspect file permissions or data structures that align on three-bit boundaries.

Hexadecimal dump

To obtain a hexadecimal representation, the option -x (two-byte hexadecimal) or -X (four-byte hexadecimal) is used. This format is the most common in debugging because it matches the way most hex editors display data.

Example:

od -x file.bin

Each line shows the offset in octal (by default) followed by 16-bit hexadecimal values. If you prefer the offset also to appear in hexadecimal, you can add -A x.

Other useful formats

This post is also available in ESPAÑOL.

Leave a Reply

Your email address will not be published. Required fields are marked *

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .