Skip to content

Linux od command

The ‘od’ command in Linux is a versatile tool for analyzing file contents in different formats. It can display data in octal, decimal, hexadecimal, and ASCII, making it ideal for examining binary files. With various options to customize the output, such as byte order and data representation, ‘od’ is commonly used for debugging and data analysis tasks.

od Syntax:

Terminal window
od [options] [file]

Options:

OptionDescription
-ASpecify the output format
-tSpecify the data type format
-jSkip a specified number of bytes
-NLimit the number of bytes to output
-vDisplay all input data
-wSpecify the number of bytes per line
-xDisplay output in hexadecimal format
-cDisplay output as ASCII characters

Parameters:

ParameterDescription
fileThe input file to display in octal

od Usage:

Display File in Octal Format

Terminal window
od /path/to/file.txt

This command displays the contents of the file in octal format.

Display File in Hexadecimal Format

Terminal window
od -x /path/to/file.txt

Using the -x option with the od command, the file contents are displayed in hexadecimal format.

Display Specific Number of Bytes in File

Terminal window
od -N 20 /path/to/file.txt

By specifying the -N option followed by a number, you can display a specific number of bytes from the file.

Output Characters with Non-Graphic Formats as Octal

Terminal window
od -c /path/to/file.txt

With the -c option, the command displays characters with non-graphic formats in octal.

Common Questions on od Usage:

How do I use od in Linux?

To use the od command in Linux, execute the following command:

Terminal window
od file.txt

What are common options used with od in Linux?

Common options used with the od command in Linux include:

Terminal window
od -t x1 file.txt

How can I display a specific number of bytes per line with od in Linux?

To display a specific number of bytes per line with the od command in Linux, use the following command:

Terminal window
od -N4 file.txt

How can I skip a certain number of bytes before starting to dump with od in Linux?

To skip a certain number of bytes before starting to dump with the od command in Linux, use the following command:

Terminal window
od -j2 file.txt

How do I interpret binary data using od in Linux?

To interpret binary data using the od command in Linux, use the following command:

Terminal window
od -b file.txt

How can I display the hexadecimal offset within each line using od in Linux?

To display the hexadecimal offset within each line using the od command in Linux, use the following command:

Terminal window
od -A x file.txt

How can I change the output format to decimal using od in Linux?

To change the output format to decimal using the od command in Linux, use the following command:

Terminal window
od -t d2 file.txt

Applications of the od command

  1. Displaying the content of binary files
  2. Viewing non-text files in a human-readable format
  3. Extracting data from binary files
  4. Checking file encoding
  5. Debugging files and data structures
  6. Converting data between different formats
  7. Inspecting memory dumps
  8. Analyzing file formats