There may be times when, while working on the Linux command line, you might want to display/convert content in a file in/to a form other than its original form, like decimal or octal. Gladly, there’s an inbuilt command line tool that you can use in situations like these.

The od (octal dump) command in Linux is a versatile utility used to display the contents of files in various formats, such as octal, hexadecimal, decimal, and ASCII. This command is handy for viewing binary data or files that contain non-printable characters, allowing users to inspect and debug the raw data. The od command is mainly used by developers and system administrators who need to analyze low-level data structures, perform forensic analysis, or debug software.

In this tutorial, we will discuss this tool’s basics using easy-to-understand examples. All examples discussed here have been tested on Ubuntu 24.04 LTS.

Linux od command

The OD command is used to convert input into Octal format. Following is its syntax:

od [OPTION]... [FILE]...

And here’s what the man page says about it:

Write an unambiguous representation, octal bytes by default, of FILE to standard output. With more 

than one FILE argument, concatenate them in the listed order to form the input. With no FILE, or

when FILE is -, read standard input.

Following are some Q&A-styled examples that will give you a better idea of how the od command works:

Q1. How to use the od command?

Suppose here’s the file you want to convert:

<img alt="How to use the od command" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/od-cat-file.png666d2bdf14f3e.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="279" loading="lazy" src="data:image/svg xml,” width=”500″>

And here’s what happens when you run the od command on it:

<img alt="Linux od command output" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/od-basic-usage1.png666d2bdf408f7.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="238" loading="lazy" src="data:image/svg xml,” width=”500″>

So by default, the od command converts the file into octal format. However, you can also force the tool to convert into other formats. For example, use -x to convert to hexadecimal:

<img alt="The od command converts the file into octal format" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/od-x-hex.png666d2bdf6f792.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="239" loading="lazy" src="data:image/svg xml,” width=”428″>

Similarly, there are options to display the input in character, floating, and integer formats.

Q2. How to make od skip bytes?

If you want to skip some initial bytes, you can do that by passing the number to the -j command line option.

od -j [num] [filename]

For example:

od -j 10 file1

Q3. How to limit output bytes per line?

By default, the od command produces 32 bytes per output line. However, you can customize this number using the -w option.

od -w[num] [filename]

For example:

od -w2 file1

<img alt="How to limit output bytes per line" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/od-w-option.png666d2bdf99efe.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="206" loading="lazy" src="data:image/svg xml,” width=”326″>

Q4. How to make od output duplicates?

Suppose the file you want to convert contains duplicate lines. For example:

<img alt="How to make od output duplicates" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/od-dup.png666d2bdfb75d0.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="270" loading="lazy" src="data:image/svg xml,” width=”500″>

Then by default, od produces * in output for duplicates.

<img alt="duplicate output marked by od command" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/od-dup-star.png666d2be003172.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="205" loading="lazy" src="data:image/svg xml,” width=”357″>

However, if you want, you can change this behavior, something which you can do by using the -v command line option.

od -c -w1 -v file1

<img alt="od command -v option" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/od-v-option.png666d2be0252f1.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="242" loading="lazy" src="data:image/svg xml,” width=”382″>

Q5. How to display byte offsets?

Byte offsets can be displayed using the -A command line option. You need to specify the format in which you want to see the offset – x for hexadecimal, o for octal, and d for decimal.

od -A[format] [filename]

For example:

od -Ad -c file1

<img alt="How to display byte offsets" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/od-a-option.png666d2be0501ad.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="143" loading="lazy" src="data:image/svg xml,” width=”500″>

Q6. How to limit od’s output to set number of bytes?

To limit the overall output to a set number of bytes, use the -N option.

od -N[num] [filename]

For example:

od -N50 file1

<img alt="How to limit od's output to set number of bytes" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/od-N.png666d2be075f16.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="89" loading="lazy" src="data:image/svg xml,” width=”500″>

So you can see the overall output got curtailed.

Conclusion

The OD command offers a lot of features in the form of command line options. We’ve discussed some major ones here. Once you are done practicing these, head to the tool’s man page to learn more about it.