Overview
od (octal dump) is a utility that reads file contents byte by byte and converts them into various human-readable formats. As its name 'octal' suggests, it primarily outputs in octal format, but through options, it can also output in hexadecimal, decimal, etc. While `hexdump` is mainly used for hexadecimal output, `od` is characterized by offering more output formats and control options. It is also utilized for binary file structure analysis and data forensics.
Key Features
The key features of the od command are as follows:
- Converts and outputs file contents in octal, hexadecimal, decimal, etc.
- Suitable for binary file analysis and debugging.
- Provides powerful options to specify various formats and output layouts.
- Can process the output of other commands via pipes (|).
Differences from hexdump
od and hexdump are functionally similar, but they differ in detailed output methods and options.
- od: Default output is octal, and it supports dumping a wider range of data types (integers, floating-point numbers, etc.).
- hexdump: Default output is hexadecimal, and its primary format is
canonical, which shows offset, hexadecimal values, and ASCII strings together.
Key Options
Commonly used `od` command options are grouped by purpose.
1) Output Format Control
2) Filtering and Control
3) Help
Generated command:
Try combining the commands.
Description:
`od` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Learn the functionalities of the `od` command through various usage examples.
Output File Contents in Octal
od /bin/cat | head
Outputs the contents of the binary file `/bin/cat` in octal. This is the default behavior of `od`.
Output in Hexadecimal and ASCII Characters
echo 'Hello World!' | od -t x1c
Outputs file contents simultaneously in hexadecimal bytes and ASCII characters. The `-t x1c` option is a format that outputs hexadecimal (x1) and ASCII characters (c) together.
Output Only a Specific Part of a File
od -t x1 -N 100 /bin/ls
Outputs 100 bytes of content from the beginning of the `/bin/ls` file in hexadecimal.
Analyze File with Newline Characters
echo 'Hello\nWorld' | od -c
Checks the contents of a text file containing newline (`\n`) characters in ASCII characters and octal codes. `012` is the octal code for a newline.
Tips & Cautions
Important points to note when using the `od` command are summarized here.
Tips
odprovides more diverse output formats (via the-toption) thanhexdump, making it useful for interpreting dumped data in various data types.- When running the
odcommand, outputting the entire file can freeze the terminal. Therefore, it's recommended to limit the output length using the-Noption or by piping to theheadcommand. - The output format of
odis not identical tohexdump's-Coption, so for a more familiar layout,hexdumpmight be more convenient to use.