od command in Linux with example
Last Updated :
10 Sep, 2024
The od (octal dump) command in Linux is a versatile tool used to display file contents in various formats, with the default being octal. This command is particularly useful for debugging scripts, examining binary files, or visualizing non-human-readable data like executable code. It allows users to view data in multiple formats, including octal, hexadecimal, decimal, and ASCII, providing a detailed look into the file’s contents. The ‘od’ command is essential for developers and system administrators when troubleshooting unwanted changes, hidden characters, or encoding issues in files.
Syntax:
od [OPTION]... [FILE]...
This command reads the contents of one or more files and displays the output in the specified format. If multiple files are provided, ‘od’ concatenates them in the listed order before processing.
Common Options of od command
Here are the most commonly used options with the ‘od’ command, along with examples and explanations to help you understand their usage:
1. -b Option: Display in Octal Format
It displays the contents of input in octal format.
Syntax:
$ od -b input.txt
Example:
input :
100
101
102
103
104
105
Output:

Explanation: The first column represents the byte offset in the file, followed by the octal representation of the file contents.
2. -c Option: Display in Character Format
It displays the contents of input in character format.
Syntax:
$ od -c input.txt
Example:
input :
100
101
102
103
104
105
Output:

3. -An Option: Display Without Offsets
It displays the contents of input in character format but with no offset information.
Syntax:
$ od -An -c input.txt
Example:
input :
100
101
102
103
104
105
Output:

4. -A Option: Display with Custom Offsets
It displays the contents of input in different format by concatenation some special character with -A.
For example:
- -Ax for Hexadecimal format(we concatenate x with -A)
- -Ao for Hexadecimal format(we concatenate o with -A)
- -Ad for Hexadecimal format(we concatenate d with -A)
Syntax:
$ od -Ax input.txt
$ od -Ao input.txt
$ od -Ad input.txt
Example:
input :
100
101
102
103
104
105
Output:

5. – Option: Accept Input from the Command Line
Accept input from command line.
Syntax:
$ od -c -
Example:

Here, we see that first the input was given and then after pressing the ctrl+d the od command output was displayed.
6. Display hidden character in a file
Consider the following content of file :
Geek ^Mforgeeks
If a file containing the above string is printed using the cat command, following output is seen :
$ cat file
$ forgeekseek
So, in order to remove it we use,
$ od -c file
Output:
0000000 G e e k f o r \r g e e k s \n
0000020
7. -j Option: Skip Bytes
It displays the output after skipping some bytes.
Syntax:
$ od -j4 -c input.txt
Example:
input :
100
101
102
103
104
105
Output:

Explanation: Here,initial 4 bytes were skipped from output.
8. -N Option: Display Limited Bytes
It display limited bytes in output using -N option.
Syntax:
$ od -N4 -c input.txt
Example:
input :
100
101
102
103
104
105
Output:

Explanation: Here,initial 4 bytes were displayed from output.It is the opposite of -j option.
9. -w Option :
It is used to customize the output width.
Syntax:
$ $ od -w1 -c -Ad input.txt
Example:
input :
100
101
102
103
104
105
Output:

Explanation: So we see that output width was reduced to 1
10. -v Option: Display All Data Including Duplicates
It is used to output duplicate values. As can be observed in the output above, a * was printed. This is done to suppress the output of lines that are same or duplicates. But through -v option these lines can also be printed.
Syntax:
$ $ od -w1 -v -c -Ad input.txt
Example:
input :
100
101
102
103
104
105
Output:

11. -i Option: Display as Decimal Integers
Shows the file content as decimal integers, which is helpful for numerical data analysis.
Syntax:
$ $ od -i input.txt
Example:
input :
100
101
102
103
104
105
Output:

12. -o Option: Display as Octal 2-Byte Units
Converts and displays the data in octal, formatted as 2-byte units.
Syntax:
$ $ od -o input.txt
Example:
input :
100
101
102
103
104
105
Output:

13. -x Option: Display as Hexadecimal 2-Byte Units
Shows the file contents as hexadecimal 2-byte units, ideal for viewing binary data.
Syntax:
$ $ od -x input.txt
Example:
input :
100
101
102
103
104
105
Output:

14. -t Option: Select Specific Output Format
It select output format and display it. Traditional format specifications may be intermixed; they accumulate: ‘-a’ same as ‘-t a’, select named characters, ignoring high-order bit ‘-b’ same as ‘-t o1’, select octal byte ‘-c’ same as ‘-t c’, select printable characters or backslash escapes ‘-d’ same as ‘-t u2’, select unsigned decimal 2-byte units ‘-f’ same as ‘-t fF’, select floats ‘-i’ same as ‘-t dI’, select decimal ints ‘-l’ same as ‘-t dL’, select decimal longs ‘-o’ same as ‘-t o2’, select octal 2-byte units ‘-s’ same as ‘-t d2’, select decimal 2-byte units ‘-x’ same as ‘-t x2’, select hexadecimal 2-byte units.
Syntax:
$ $ od -ta input.txt
Example:
input :
100
101
102
103
104
105
Output:

15. –help Option: Display Help Information
Use this option to display the help information for the ‘od’ command, including details about all available options.
Syntax:
$ $ od --help
Output:

16. –version Option: Display Version Information
Shows the version of the ‘od’ command installed on your system.
Syntax:
$ $ od --version
Output:

Conclusion
The ‘od’ command in Linux is a powerful utility for converting and displaying file contents in various formats. From octal and hexadecimal to ASCII and more, ‘od’ provides a detailed view of data that is not easily readable. Its wide range of options and flexibility make it a go-to tool for debugging, data analysis, and understanding complex file structures.
Similar Reads
md5sum Command in Linux with Examples
The md5sum is designed to verify data integrity using MD5 (Message Digest Algorithm 5). MD5 is 128-bit cryptographic hash and if used properly it can be used to verify file authenticity and integrity. Example : Input : md5sum /home/mandeep/test/test.cppOutput : c6779ec2960296ed9a04f08d67f64422 /home
5 min read
How to Create Directory in Linux | mkdir Command
In Linux, the 'mkdir' command is like a magic wand for creating folders super easily. 'mkdir' stands for "make directory," and it helps you organize your computer stuff by creating folders with just one command. Whether you're making one folder or a bunch of them in a row, 'mkdir' is there to help y
7 min read
modinfo command in Linux with Examples
The modinfo command in Linux is used to display information about a Linux kernel module. It extracts detailed information from the modules available in the system and provides insights into their properties, dependencies, parameters, and more. If the module name is provided without a file name, the
3 min read
more command in Linux with Examples
The 'more' command in Linux is a useful tool for viewing text files in the command prompt, particularly when dealing with large files like log files. It displays the content one screen at a time, allowing users to scroll through the text easily. This command is especially handy for reviewing long ou
4 min read
How to Mount File System in Linux | mount Command
Working with file systems is a fundamental part of managing a Linux system, and knowing how to mount them is a skill every Linux user should have. Whether youâre connecting a USB drive, accessing a network share, or setting up a new partition, the mount command is your go-to tool for making file sys
7 min read
mpstat Command in Linux with Examples
mpstat is a powerful and versatile command-line tool within a Linux system that allows detailed reporting of various processor-related statistics. Indeed, part of the sysstat package, mpstat delivers comprehensive CPU utilization and performance data, thus becoming an essential utility for both syst
5 min read
How to Move File in Linux | mv Command
The `mv` command in Linux is like a superhero tool that can do a bunch of cool stuff with your files and folders. Think of it as a digital moving truck that helps you shift things around in your computer. Whether you want to tidy up your folders, give your files new names, or send them to different
7 min read
Practical Uses of nc(netcat) command in Linux
Netcat is one of the most powerful networking tools, security tools, and network monitoring tools. It is even considered a Swiss army knife of networking tools. It acts like a cat command over a network. It is generally used for the following reasons: Operation related to TCP, UDP, or UNIX-domain so
8 min read
Netstat command in Linux
The netstat command is like a special tool in Linux that helps you understand and check things about how your computer connects to the internet. It can tell you about the connections your computer is making, the paths it uses to send information, and even some technical details like how many packets
7 min read
Manage Network Connections From the Linux Command Line with nmcli
Network connectivity is a critical aspect of modern computing, and Linux provides a robust command-line tool for managing network connections: nmcli. Network Manager Command-Line Interface (nmcli) is a powerful and versatile utility that allows users to control and configure network settings directl
5 min read