od Command
The od (octal dump) command is used to display the contents of files in various human-readable formats, such as octal, hexadecimal, decimal, or ASCII.
Syntax
od [OPTION]... [FILE]...
Description
The od command writes the contents of FILEs to standard output in a user-specified format. If no FILE is specified, or when FILE is -, it reads from standard input.
Common uses include:
- Viewing binary files in a human-readable format.
- Debugging programs by examining raw data.
- Analyzing file structures.
Common Options
| Option | Description |
|---|---|
-a |
Named characters, ignore high bit |
-b |
Octal bytes |
-c |
ASCII characters or backslash escapes |
-d |
Unsigned decimal, 2-byte units |
-f |
Floating point, 4-byte units |
-h |
Hexadecimal, 2-byte units |
-i |
Decimal, 2-byte units |
-o |
Octal, 2-byte units (default) |
-x |
Hexadecimal, 2-byte units |
-N bytes |
Output at most BYTES bytes |
-j skip |
Skip SKIP bytes from the input beginning |
Examples
Dump a file in octal format
od -o myfile.txt
Displays the contents of myfile.txt in octal format.
Dump a file in hexadecimal format
od -x myfile.bin
Displays the contents of myfile.bin in hexadecimal format.
Dump a file in ASCII characters
od -c myfile.txt
Displays the contents of myfile.txt as ASCII characters.
Dump a specific number of bytes in hexadecimal
od -x -N 16 myfile.bin
Displays the first 16 bytes of myfile.bin in hexadecimal format.
Skip bytes and dump in octal
od -o -j 100 myfile.log
Skips the first 100 bytes of myfile.log and then displays the rest in octal format.