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:

Od Command Tutorial Linux 1617239126 207 Od Command Tutorial Linux

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:

Od Command Tutorial Linux 1617239126 256 Od Command Tutorial Linux

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

Od Command Tutorial Linux 1617239127 351 Od Command Tutorial Linux

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).

Od Command Tutorial Linux 1617239127 375 Od Command Tutorial Linux

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

Od Command Tutorial Linux 1617239128 482 Od Command Tutorial Linux

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

Od Command Tutorial Linux 1617239128 706 Od Command Tutorial Linux

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

Od Command Tutorial Linux 1617239129 797 Od Command Tutorial Linux

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

Od Command Tutorial Linux 1617239129 988 Od Command Tutorial Linux

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

Od Command Tutorial Linux 1617239130 40 Od Command Tutorial Linux

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