TrumanWong

od

Output the bytes encoded in octal, hexadecimal and other formats of the file

Supplementary instructions

od command is used to output octal, hexadecimal or other format-encoded bytes of the file. It is usually used to display or view characters in the file that cannot be directly displayed on the terminal.

Common files are text files and binary files. This command is mainly used to view the values saved in binary files. 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. If you want to view this data, the od command comes in handy. In my opinion, the od command is mainly used to format output file data, that is, to interpret the data in the file unambiguously. Whether it is floating point numbers in IEEE754 format or ASCII codes, the od command can output their values as required.

grammar

od(option)(parameter)

Options

-a: The effect of this parameter is the same as specifying the "-ta" parameter at the same time;
-A: <Character base>: Select the base to use to calculate character codes;
-b: The effect of this parameter is the same as specifying the "-toC" parameter at the same time;
-c: The effect of this parameter is the same as specifying the "-tC" parameter at the same time;
-d: The effect of this parameter is the same as specifying the "-tu2" parameter at the same time;
-f: The effect of this parameter is the same as specifying the "-tfF" parameter at the same time;
-h: The effect of this parameter is the same as specifying the "-tx2" parameter at the same time;
-i: The effect of this parameter is the same as specifying the "-td2" parameter at the same time;
-j<Number of characters> or --skip-bytes=<Number of characters>: Skip the set number of characters;
-l: The effect of this parameter is the same as specifying the "-td4" parameter at the same time;
-N<number of characters> or --read-bytes=<number of characters>: until the set character tree;
-o: The effect of this parameter is the same as specifying the "-to2" parameter at the same time;
-s<number of characters in string> or --strings=<number of characters in string>: Only display strings that match the specified number of characters;
-t<output format> or --format=<output format>: set the output format;
-v or --output-duplicates: Do not omit duplicate data when outputting;
-w <Number of characters per column> or --width=<Number of characters per column>: Set the maximum number of characters per column;
-x: The effect of this parameter is the same as specifying the "-h" parameter at the same time;
--help: online help;
--version: Display version information.

Parameters

File: Specify the file to display.

Example

[linuxde@localhost ~]$ echo abcdef g > tmp
[linuxde@localhost ~]$ cat tmp
abcdef g

Instructions: First prepare a tmp file

[linuxde@localhost ~]$ od -b tmp
0000000 141 142 143 144 145 146 040 147 012
0000011

Description: Use single-byte octal interpretation for output. Note that the default address format on the left is eight bytes.

[linuxde@localhost ~]$ od -c tmp
0000000 a b c d e f g \n
0000011

Description: Use ASCII code for output, note that it includes escape characters

[linuxde@localhost ~]$ od -t d1 tmp
0000000 97 98 99 100 101 102 32 103 10
0000011

Description: Use single-byte decimal for interpretation

[linuxde@localhost ~]$ od -A d -c tmp
0000000 a b c d e f g \n
0000009

Description: Set the address format to decimal.

[linuxde@localhost ~]$ od -A x -c tmp
000000 a b c d e f g \n
000009

Description: Set the address format to hexadecimal

[linuxde@localhost ~]$ od -j 2 -c tmp
0000002 c d e f g \n
0000011

Description: Skip the first two bytes

[linuxde@localhost ~]$ od -N 2 -j 2 -c tmp
0000002cd
0000004

Description: Skip the first two bytes and output only two bytes

[linuxde@localhost ~]$ od -w1 -c tmp
0000000a
0000001b
0000002c
0000003d
0000004 e
0000005f
0000006
0000007g
0000010\n
0000011

Description: Only output 1 byte per line

[linuxde@localhost ~]$ od -w2 -c tmp
0000000 a b
0000002cd
0000004 e f
0000006g
0000010\n
0000011

Description: Output two bytes per line

[linuxde@localhost ~]$ od -w3 -b tmp
0000000 141 142 143
0000003 144 145 146
0000006 040 147 012
0000011

Description: Output 3 bytes per line and use octal single byte for interpretation