{{Short description|Unix octal dump utility}} {{lowercase}} {{Infobox software | name = od | logo = | screenshot = | screenshot size = | caption = | author = AT&T Bell Laboratories | developer = Various open-source and commercial developers | released = {{Start date and age|1971|11|03}} | latest release version = | latest release date = | operating system = Unix, Unix-like, IBM i | platform = Cross-platform | genre = Command | license = coreutils: GPLv3+ | website = }} '''<code>od</code>''' is a command on various operating systems for displaying ("dumping") data in various human-readable output formats. The name is an acronym for "octal dump" since it defaults to printing in the octal data format.
==Overview== The <code>od</code> program can display output in a variety of formats, including octal, hexadecimal, decimal, and ASCII. It is useful for visualizing data that is not in a human-readable format, like the executable code of a program, or where the primary form is ambiguous (e.g. some Latin, Greek and Cyrillic characters looking similar).
<code>od</code> is one of the earliest Unix programs, having appeared in version 1 AT&T Unix. It is also specified in the POSIX standards. The implementation for <code>od</code> used on Linux systems is usually provided by GNU Core Utilities.
Since it predates the Bourne shell, its existence causes an inconsistency in the <code>do</code> loop syntax. Other loops and logical blocks are opened by the name, and closed by the reversed name, e.g. <code>if ... fi</code> and <code>case ... esac</code>, but <code>od</code>'s existence necessitates <code>do ... done</code>.
The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.<ref>{{Cite web|url=https://unxutils.sourceforge.net/|title=Native Win32 ports of some GNU utilities|website=unxutils.sourceforge.net|access-date=2026-02-03|archive-date=2006-02-09|archive-url=https://web.archive.org/web/20060209022842/http://unxutils.sourceforge.net/|url-status=live}}</ref> The {{Mono|od}} command has also been ported to the IBM i operating system.<ref>{{cite web |title=IBM System i Version 7.2 Programming Qshell |language=en |author=IBM |website=IBM |author-link=IBM |url=https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |access-date=2020-09-05 |archive-date=2020-09-18 |archive-url=https://web.archive.org/web/20200918130823/https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |url-status=live }}</ref>
==Example session== Normally a dump of an executable file is very long. The <code>head</code> program prints out the first few lines of the output. Here is an example of a dump of the "Hello world" program, piped through head.
<syntaxhighlight lang="console"> % od hello | head 0000000 042577 043114 000401 000001 000000 000000 000000 000000 0000020 000002 000003 000001 000000 101400 004004 000064 000000 0000040 003610 000000 000000 000000 000064 000040 000006 000050 0000060 000033 000030 000006 000000 000064 000000 100064 004004 0000100 100064 004004 000300 000000 000300 000000 000005 000000 0000120 000004 000000 000003 000000 000364 000000 100364 004004 0000140 100364 004004 000023 000000 000023 000000 000004 000000 0000160 000001 000000 000001 000000 000000 000000 100000 004004 0000200 100000 004004 002121 000000 002121 000000 000005 000000 0000220 010000 000000 000001 000000 002124 000000 112124 004004 </syntaxhighlight>
Here is an example of <code>od</code> used to diagnose the output of <code>echo</code> where the user types {{key press|Ctrl|V|Ctrl|I}} and {{key press|Ctrl|V|Ctrl|C}} after writing "Hello" to literal insert a tab and <code>^C</code> character:
<syntaxhighlight lang="console"> % echo "Hello ^C" | od -cb 0000000 H e l l o \t 003 \n 110 145 154 154 157 011 003 012 0000010 </syntaxhighlight>
{{code|od}} can be used to fetch random numbers from the cryptographic-quality random number generator /dev/urandom. For example:<ref>{{cite web |author=EightBitTony |title=Using /dev/random, /dev/urandom to generate random data |url=https://unix.stackexchange.com/a/268960 |website=Unix & Linux Stack Exchange |language=en}}</ref> <syntaxhighlight lang="console"> $ od -vAn -N1 -td1 < /dev/urandom # 1 byte signed decimal -78 $ od -vAn -N4 -tu4 < /dev/urandom # 4 byte unsigned decimal 3394619386 $ od -vAn -N8 -tx8 < /dev/urandom # 8 byte hexadecimal eed2dedced30591a </syntaxhighlight>
==See also== * Hex editor * Hex dump
==References== {{Reflist}}
==External links== {{Wikibooks|Guide to Unix|Commands}} {{Wikibooks|Od}} * {{man|cu|od|SUS|dump files in various formats}} * [https://www.gnu.org/software/coreutils/manual/html_node/od-invocation.html od - GNU Core Utilities manpage]
{{Unix commands}} {{Core Utilities commands}}
Category:Unix SUS2008 utilities Category:IBM i Qshell commands