Linux Commands

Od Command Tutorial Linux


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:

$ cat test.txt

Getting started with od Command Options

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

$ od -b test.txt

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 -c test.txt

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

$ od -An -c test.txt

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 -w1 -c -Ad test.txt

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

$ od -i test.txt

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

$ od -o test.txt

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

$ od -x test.txt

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

$ od --help

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

$ od --version

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.

About the author

Wardah Batool

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.