The od command in Linux is used to dump files in octal and other formats, including hexadecimal, decimal, and ASCII. This can be handy when you need to view files that aren’t ordinarily human readable, such as a binary file that’s already been compiled. But it can also prove useful in a slew of other, admittedly niche, scenarios.
In this guide, you’ll learn how to use the od command in Linux through examples. Follow along below to learn about the various options that you can use with this command.
In this tutorial you will learn:
- How to use the od command on Linux
od command in Linux Basic and Advanced Examples
- By default, the od command will convert all input to octal. Simply specify the path to a file that you wish to convert.
$ od file 0000000 067157 005145 073564 005157 064164 062562 005145 067546 0000020 071165 063012 073151 005145 071412 074151 000012 0000035
- Use the
-c
option to represent values in a file as ASCII.$ od -c file 0000000 o n e \n t w o \n t h r e e \n f o 0000020 u r \n f i v e \n \n s i x \n 0000035
- Use the
-x
option to convert the input to hexadecimal format.$ od -x file 0000000 6e6f 0a65 7774 0a6f 6874 6572 0a65 6f66 0000020 7275 660a 7669 0a65 730a 7869 000a 0000035
- If you need to skip an initial number of bytes in the file, use the
-j
option and specify the amount to skip.$ od -j 5 file 0000005 067567 072012 071150 062545 063012 072557 005162 064546 0000025 062566 005012 064563 005170 0000035
- Use the
-d
option to convert the input to decimal format.$ od -d file 0000000 28271 2661 30580 2671 26740 25970 2661 28518 0000020 29301 26122 30313 2661 29450 30825 10 0000035
- Note that you can specify multiple files if you’d like. The input will simply be concatenated and then processed.
$ od file1 file2 file3
You can always use the man command to read more about the od command and its official documentation. Click the previous link to see how to open the manual pages for any command on a Linux system.
Closing Thoughts
In this guide, we learned all about the od command on Linux which is useful when you need to do an octal dump of a file, but also comes in handy to convert files to hexadecimal, decimal, and ASCII.