Linux od command: dumps files in octal and other formats
Linux od command Function Description
Use the od command to dump the specified file to the standard output in octal form (the default). If more than one file parameter is specified, the program automatically consolidates the input into a list and outputs it in the same form.
The common files are text files and binary files. This command is mainly used to view the values saved in the binary file. For example, a program may output a large number of data records, each of which is a single-precision floating-point number. These data records are stored in a file, and if you want to view this data, this is where the od command comes in handy.
In my opinion, the od command is mainly used to format the output file data, i.e., to interpret the data in the file in a non-dualistic way. Whether it is floating point numbers in IEEE754 format or ASCII codes, the od command can output their values as required.
Linux od command Syntax
od [Option] [File]
The meaning of each option in the command is shown in the following table.
Option | Description |
---|---|
-A <Initial Offset> |
Sets the initial offset of the file to be displayed |
-j <Byte count> |
Skip the specified number of bytes of input |
-N <Byte count> |
Limit the number of input bytes to be dumped to the specified number of bytes |
-S <Byte count> |
Output the corresponding string containing at least the specified number of bytes of characters |
-t <Type> |
Select the output format type |
-v |
Masked lines are not marked with an * character |
-w <Byte count> |
Each line outputs only the specified number of bytes |
The od command can be used in the formats shown in the following table. Traditional format commands can be mixed and different formats can be overlaid.
Format | Description |
---|---|
-a |
Use named characters and ignore higher-order bits |
-b |
Use octal single-byte characters |
-c |
Use ASCII characters, or special characters with backslash proper names |
-d |
Use unsigned decimal double-byte characters |
-f |
Specifies the floating-point comparison output format |
-i |
Specifies the decimal integer comparison output format |
-l |
Specifies the output format of the decimal long integer comparison |
-o |
Specify the cross-reference output format for double-byte unit octal numbers |
-s |
Specify the cross-reference output format for double-byte unit decimal numbers |
-x |
Specify the cross-reference output format for double-byte unit hexadecimal numbers |
Linux od command Examples
View the contents of /root/mbr files in double-byte unit hexadecimal number cross-reference output format, using named characters and ignoring high-order bits
od -xa /root/mbr
Output:
[root@rhel ~]# dd if=/dev/sda of=/root/mbr bs=512 count=1
// Backup MBR (master boot sector) information to /root/mbr file
[root@rhel ~]# od -xa /root/mbr
0000000 48eb 1090 d08e 00bc b8b0 0000 d88e c08e
k H dle dle so P <nul 0 8 nul nul so X so @
0000020 befb 7c00 00bf b906 0200 a4f3 21ea 0006
{ >nul | ?nul ack 9 nul stx s $ j !ack nul
0000040 be00 07be 0438 0b75 c683 8110 fefe 7507
nul > >bel 8 eot u vt etx F dle soh ~ ~bel u
0000060 ebf3 b416 b002 bb01 7c00 80b2 748a 0203
s k syn 4 stx 0 soh ;nul | 2 nul nl t etx stx
0000100 0080 8000 86e2 0000 0800 90fa f690 80c2
nul nul nul nul b ack nul nul nul bs z dle dle v B nul
0000120 0275 80b2 59ea 007c 3100 8ec0 8ed8 bcd0
u stx 2 nul j Y |nul nul 1 @ so X so P <
0000140 2000 a0fb 7c40 ff3c 0274 c288 f652 80c2
nul sp { sp @ | <del t stx bs B R v B nul
0000160 5474 41b4 aabb cd55 5a13 7252 8149 55fb
t T 4 A ; * U M dc3 Z R r I soh { U
0000200 75aa a043 7c41 c084 0575 e183 7401 6637
* u C sp A |eot @ u enq etx a soh t 7 f
0000220 4c8b be10 7c05 44c6 01ff 8b66 441e c77c
vt L dle >enq | F D del soh f vt rs D | G
0000240 1004 c700 0244 0001 8966 085c 44c7 0006
eot dle nul G D stx soh nul f ht \ bs G D ack nul
0000260 6670 c031 4489 6604 4489 b40c cd42 7213
p f 1 @ ht D eot f ht D ff 4 B M dc3 r
0000300 bb05 7000 7deb 08b4 13cd 0a73 c2f6 0f80
enq ;nul p k } 4 bs M dc3 s nl v B nul si
0000320 f084 e900 008d 05be c67c ff44 6600 c031
eot p nul i cr nul >enq | F D del nul f 1 @
0000340 f088 6640 4489 3104 88d2 c1ca 02e2 e888
bs p @ f ht D eot 1 R bs J A b stx bs h
0000360 f488 8940 0844 c031 d088 e8c0 6602 0489
bs t @ ht D bs 1 @ bs P @ h stx f ht eot
0000400 a166 7c44 3166 66d2 34f7 5488 660a d231
f ! D | f 1 R f w 4 bs T nl f 1 R
0000420 f766 0474 5488 890b 0c44 443b 7d08 8a3c
f w t eot bs T vt ht D ff ; D bs } < nl
0000440 0d54 e2c0 8a06 0a4c c1fe d108 6c8a 5a0c
T cr @ b ack nl L nl ~ A bs Q nl l ff Z
0000460 748a bb0b 7000 c38e db31 01b8 cd02 7213
nl t vt ;nul p so C 1 [ 8 soh stx M dc3 r
0000500 8c2a 8ec3 4806 607c b91e 0100 db8e f631
* ff C so ack H | ' rs 9 nul soh so [ 1 v
0000520 ff31 f3fc 1fa5 ff61 4226 be7c 7d7f 40e8
1 del | s % us a del & B | >del } h @
0000540 eb00 be0e 7d84 38e8 eb00 be06 7d8e 30e8
nul k so >eot } h 8 nul k ack > so } h 0
0000560 be00 7d93 2ae8 eb00 47fe 5552 2042 4700
nul >dc3 } h *nul k ~ G R U B sp nul G
0000600 6f65 006d 6148 6472 4420 7369 006b 6552
e o m nul H a r d sp D i s k nul R e
0000620 6461 2000 7245 6f72 0072 01bb b400 cd0e
a d nul sp E r r o r nul ;soh nul 4 so M
0000640 ac10 003c f475 00c3 0000 0000 0000 0000
dle , <nul u t C nul nul nul nul nul nul nul nul nul
0000660 0000 0000 0000 0000 4c36 0003 0000 2080
nul nul nul nul nul nul nul nul 6 L etx nul nul nul nul sp
0000700 0021 df83 0c13 0800 0000 2000 0003 df00
!nul etx _dc3 ff nul bs nul nul nul sp etx nul nul _
0000720 0c14 fe83 ffff 2800 0003 0000 12c0 fe00
dc4 ff etx ~del del nul (etx nul nul nul @dc2 nul ~
0000740 ffff fe82 ffff 2800 12c3 0000 0040 0000
del del stx ~del del nul ( C dc2 nul nul @nul nul nul
0000760 0000 0000 0000 0000 0000 0000 0000 aa55
nul nul nul nul nul nul nul nul nul nul nul nul nul nul U *
0001000
Description: Prepare a tmp file first
[linuxde@localhost ~]echo abcdef g>tmp
[linuxde@localhost ~] cat tmp
abcdef g
Description: Output using single-byte octal interpretation, note that the default address format on the left is eight bytes
[linuxde@localhost ~]$ od -b tmp
0000000 141 142 143 144 145 146 040 147 012
0000011
Description: Output using ASCII code, note that it includes escaped characters
[linuxde@localhost ~]$ od -c tmp
0000000 a b c d e f g \n
0000011
Note: Use single-byte decimal for interpretation
[linuxde@localhost ~]$ od -t d1 tmp
0000000 97 98 99 100 101 102 32 103 10
0000011
Description: Set the address format to decimal.
[linuxde@localhost ~]$ od -A d -c tmp
0000000 a b c d e f g \n
0000009
Description: Set the address format to hexadecimal
[linuxde@localhost ~]$ od -A x -c tmp
000000 a b c d e f g \n
000009
Description: Skip the first two bytes
[linuxde@localhost ~]$ od -j 2 -c tmp
0000002 c d e f g \n
0000011
Description: Skip the first two bytes, and output only two bytes
[linuxde@localhost ~]$ od -N 2 -j 2 -c tmp
0000002 c d
0000004
Description: Output only 1 byte per line
[linuxde@localhost ~]$ od -w1 -c tmp
0000000 a
0000001 b
0000002 c
0000003 d
0000004 e
0000005 f
0000006
0000007 g
0000010 \n
0000011
Description: Two bytes per line of output
[linuxde@localhost ~]$ od -w2 -c tmp
0000000 a b
0000002 c d
0000004 e f
0000006 g
0000010 \n
0000011
Description: Output 3 bytes per line and interpreted using octal single bytes
[linuxde@localhost ~]$ od -w3 -b tmp
0000000 141 142 143
0000003 144 145 146
0000006 040 147 012
0000011