Introduction to Linux OD
The Linux od command is using to convert the content of the input data or file into different formats like hexadecimal, decimal, signed decimal, unsigned decimal, octal. The default conversation of od command is octal. The Linux od command is especially useful to fix or identify the unwanted changes or characters in the bash/shell scripts or programs. If we are providing one or more inputs files to od command. The od command will concatenate them in the list order from the input. As per the requirement, the output will display in a different format. The Linux od command is written by Jim Meyering.
od [ OPTION ][ FILE ]
- OPTION: as per the requirement we can provide the different option in od command
- FILE: it is the input data or file
How Linux OD Command works?
The Linux OD command is normally used to convert the exiting output into a different format. The od tool gets the input from the input file and converts the actual data of the input file as per the give option in od command. The output of od command may vary as per the option used in the same command.
Examples to Implement Linux OD Command
Here are some examples mentioned:
OD Command for Octal Format: This is the most basic and simple use of od command. We can get the output data in octal format. “-b” option will be used in the od command.
od –b od.txt
Explanation: We are having a sample directory. In the same directory, we have an “od.txt” file with some sample data (refer screenshot 1 (a)). In od command, we are using the “-b” option to get the output result in octal format. It is simply converting the input data file in default octal format. You will get the output data in a converted format (refer screenshot 1 (b)).
OD Command for Character Format: In od command, we are having the functionality to get the input data in character format. We need to use the “-c” option in the od command.
od –c od.txt
Explanation: In the “od.txt” file, we are having the text data in it (refer screenshot 2 (a)). As per the above command, we are using the “-c” option to convert the input data into character format (refer screenshot 2 (b)).
OD Command with Offset Details: In od command, we are having the functionality to remove the offset values or offset information from the output data. To remove the offset information we can use the “-An” option in the od command.
od -An -b od.txt
Explanation: When we are converting the normal input data or file from one format to another format. As per the default standard, the offset values are attached to the output. But if we are having the big file then it is important to remove the offset value to get the short format of output data. In the above od command, we are having the input file “od.txt”. It is contacting the normal text data. After converting into the octal format the output data is coming with offset value (refer screenshot 3 (a)). Now we are using the “-An” option in od command to remove the offset value form the output (refer screenshot 3 (b)).
OD Command with Concatenation: In od command, we can display the output in concatenation format with different values. With the help of the “-A” option, we can add or concatenate different values.
od -Ao -c od.txt
od -Ax -c od.txt
od -Ad -c od.txt
Explanation: As per the above command, we can display the output in different concatenate format. We will get the output in hexadecimal format with concatenating “o” with –A (refer screenshot 4 (a)). Similarly, we will get the output in hexadecimal format with concatenating “x” with –A (refer screenshot 4 (b) likewise concatenate “d” with –A (refer screenshot 4 (c)).
OD Command with User Input: In od command, we are having the functionality to take the live user input to od command and the command will display the output data before pressing ctrl+d.
od -b -
Explanation: Sometimes we need a live interpreter to interpret the user data and convert it at the same movement. The od command is providing the same facility. In the above command, we are providing the input data as “Hello EDUCBA”. The od command will get the input data and convert it into the octal format.
OD Command with Limited Bytes: In od command, we can display the limited bytes in output. We can use “-N” to display the limited bytes.
od -N5 -c od.txt
Explanation: In screenshot 5 (a), we are getting the output in character format. But now we do not display the complete output. we need an output in a limited format. Hence we are using the “-N” option with the number of characters to display (refer screenshot 5 (b)).
OD Command with Width Option: As per the requirement, we can customize the output data width.
od -w5 -c -Ad od.txt
Explanation: In screenshot 6 (a), we will get the default width size of the output display. If we need to changes the output display width size. We can do that in od command using the “-w” option. With the “-w” option we need to specify the width size (refer screenshot 6 (b)).
We have seen the uncut concept of “Linux OD Command” with the proper example, explanation and command with different outputs. The od command is useful to convert the input data into a different format. It is mainly useful for visualizing output data that is not in a human-readable format. It will like the program or executable code.
This is a guide to Linux OD. Here we discuss an introduction to Linux OD, syntax, how does it work, examples with code, output and explanation. You can also go through our other related articles to learn more –