Od Command Tutorial Linux

28

In Linux operating system, “od” is a useful command that converts the input in multiple formats with octal format by-default. As we all know, Octal has a base-8 number used to present binary numbers in a short form.

Linux developers utilize the “od” also known as Octal Dump, to debug scripts.

The “od” is an efficient command that helps to understand the complex data which is not human-readable.

od Command Syntax

The fundamental syntax of the “od” command is:

od [options] .. [file_name]

Od Command with Examples

Before starting with the od command options, create a text file and add numeric content to understand it’s working. I’ve created a file named “test.txt” and added some data.

Let’s read this text file using the cat command in the terminal:

Getting started with od Command Options

To print the “test” file content in octal format, use the “-b” option:

You can see the difference; test file data has been converted into the octal format.

To print “test.txt” file content in character format, use the “-c” option:

When you use “-An” flag with “-c” option, it will print “test.txt” file content in character format but with no offset information:

So, it is visible that when we used the “-An” flag with options, it will display output without byte offset. The “-An” flag can be used with other options as well.

Use the “-w1” flag to customize content width. For example: let’s type “-w1” with “-Ad”. It will customize the width of hexadecimal format (as -A is concatenated with d).

Use the “-i” option to display the result as a decimal integer:

Use the “-o” option to display the result as octal 2-byte units:

Use the “-x” option to print the result as hexadecimal 2-byte units:

To print help regarding the “od” command in the terminal, use the “help” command:

To print version information in the terminal, use the “version” option as follows:

Conclusion

Octal Dump (od) is a command in Linux used to convert file data in different formats with the octal format as default. This tutorial has shown how to use the “od” command in the terminal and its different options to convert data into various formats.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More