Search notes:
Shell command: od
od dumps the content of files. By default, in octal format, but other formats (such as hex numbers) can be chosen
od [OPTION]… [FILE]…
od [-abcdfilosx]… [FILE] [[+]OFFSET[.][b]]
od --traditional [OPTION]… [FILE] [[+]OFFSET[.][b] [+][LABEL][.][b]]
Instead of
FILE,
- can be specified, which reads
stdin.
Options
Arguments to long options are connected to the option name with a = sign.
-A | --address-radix= | RADIX | output format for file offsets (left most column); RADIX is one of [doxn], for Decimal, Octal, Hex or None |
| | --endian= | big or little | swap input bytes according the specified order |
-j | --skip-bytes= | nofBytes | skip nofBytes input bytes first |
-N | --read-bytes= | nofBytes | limit dump to nofBytes input bytes |
-S | --strings= | nofBytes | Output strings of at least nofBytes graphic chars; 3 is implied when optional nofBytes is not specified |
-t | --format= | TYPE | select output format or formats |
-v | --output-duplicates | | Do not use * to mark line suppression |
-w | --width= | nofBytes | put nofBytes per output line; 32 is implied when optional nofBytes is not specified |
| | --traditional | | ? |
| | --help | | |
| | --verion | | Print version. |
TYPE
a | Named character, ignoring high-order bit | -t a can be abbreviated with -a |
c | Printable character or backslash escape | -t c = -c |
d[SIZE] | Signed decimal, SIZE bytes per integer | -t dI = -i, -t dL = -l, -t d2 = -s |
f[SIZE] | Floating point, SIZE bytes per float | -t fF = -f |
o[SIZE] | Octal, SIZE bytes per integer | -t o1 = -b, -t o2 = -o |
u[SIZE] | Unsigned decimal, SIZE bytes per integer | -t u2 = -d |
x[SIZE] | Hexadecimal, SIZE bytes per integer | -t x2 = -x |
Adding a z suffix to any type also displays printable characters at the end of each output line.
SIZE
SIZE is a number. If TYPE is one of d, o, u or x, SIZE can also be specified with one of the following letters:
C | sizeof(char) |
S | sizeof(short) |
I | sizeof(int) |
L | sizeof(long) or sizeof(long double) |
F | sizeof(float) |
D | sizeof(double) |
nofBytes
nofBytes is a hexadecimal number, prefixed with
0x or
0X, and an optional multiplier suffix:
-
b 512
-
KB 1000
-
K 1024
-
MB 1000*1000
-
M 1024*1024
-
G, T, P, E, Z, Y etc.
Binary prefixes can be used, too: KiB=K, MiB=M, and so on.
Showing hexadecimal bytes
$ printf "abc\ndef\ahi" | od -t x1
prints
0000000 61 62 63 0a 64 65 66 07 68 69
0000012
The x specifies to print hexadecimal values, the 1 following it specifies to print one hexadecimal value after another.
$ printf abc@def | od -t x1 -An
61 62 63 40 64 65 66
Show one int per line
od -t d4 --width=4 /path/to/file
Or a bit shorter:
od -i -w4 /path/to/file
Use z to also display printable characters:
od -t d4z --width=4 /path/to/file
Specify range to be dumped
The options -j (how many bytes to skip at the beginning) and -N (how many bytes to read) allow to specify a range that should be dumped:
od -j $startAtByte -N $countBytes $file
Address format
The format of the addresses (printed to the left) is specified with -A
It is
-
d for decimal
-
o for octal
-
x for hexadecimal
-
n for none at all.
Print the hexadecimal values of a sequence of bytes in a file
Print (zero indexed) bytes 16, 17, 18 and 19 from a given file:
$ od --skip-bytes=16 --read-bytes=4 --format=x1 --address-radix=n /tmp/foo/bar
0a 2b 2b e