The Linux od command is described in detail with examples of its usage

  • 2020-05-17 07:23:34
  • OfStack

Linux od command details

Function of 1.

The od command is used to display the contents of a specified file in hexadecimal, hexadecimal, hexadecimal, floating point, or ASCII encoded characters. It is usually used to display or view characters in a file that cannot be displayed directly at the terminal. The od command system displays in base 8 by default, named after Octal Dump.

Common files are text files and base 2 files. The od command is primarily used to view the values stored in a binary file, interpret the data in the file in a specified format, and output them, whether they are floating point Numbers in IEEE754 or ASCII codes.

You can also see the 1 hexdump command, which outputs in base 106, but it feels like the hexdump command is as powerful as the od command.

2. Command format


od [< options >< parameter >] [< The file name >]

3. Command options


A<RADIX>,--address-radix=RADIX : select the base to represent the address offset; 
-j<BYTES>,--skip-bytes=BYTES : skips the specified number of bytes; 
-N,--read-bytes=BYTES : output the specified number of bytes; 
-S<BYTES>, --strings[=BYTES] : a string whose output length is not less than the specified number of bytes; 
-v,--output-duplicates : output without omitting duplicate data;  
-w<BYTES>,--width=<BYTES> : sets the number of bytes displayed per line, od By default, each line is displayed 16 Bytes. If the option --width Does not follow the number, default display 32 Bytes; 
-t<TYPE> . --format=TYPE : specifies the output format, which includes a , c , d , f , o , u and x , with the following meanings: 
 a : named character; 
 c : ASCII Character or backslash; 
 d[SIZE] : 10 In base, both positive and negative Numbers, SIZE A byte composed of 1 a 10 Base integer; 
 f[SIZE] : floating point, SIZE A byte composed of 1 Floating point number; 
 o[SIZE] : 8 Into the system, SIZE A byte composed of 1 a 8 Hexadecimal number. 
 u[SIZE] : no symbols 10 Base, which only contains positive Numbers, SIZE A byte composed of 1 An unsigned 10 Base integer; 
 x[SIZE] : 106 Into the system, SIZE In bytes 106 Base output, that is, output time 1 Column contains SIZE Bytes. 
--help : online help;  
--version : display version information. 

4. Usage examples

(1) set the offset address of the first column to be displayed in decimal system.


od -Ad testfile

The offset address shows cardinality: d for decimal, o for octal, x for hexadecimal or n for none.

(2) the od command does not display the first column offset address.


od -An testfile

(3) output in base 106 and display in 1 group (1 column) of 4 bytes by default.


od -tx testfile

(4) output in base 106, 1 byte per column.


od -tx1 testfile

(5) display the names of ASCII characters and ASCII characters. Note the difference in the way the newline character is displayed.


# According to ASCII character 
[b3335@localhost]$ echo lvlv|od -a
0000000  l  v  l  v nl
0000005

# According to ASCII The name of the character 
[b3335@localhost]$ echo lvlv|od -tc
0000000  l  v  l  v \n
0000005

(6) display the original character while displaying in base 106.


[b3335@localhost]$ echo lvlv|od -tcx1
0000000  l  v  l  v \n
     6c 76 6c 76 0a
0000005

(7) specify that each line displays 512 bytes.


od -w512 -tx1 testfile

(8) when the od command is output, the space character between the columns is removed.

When we need to display the contents of a file in hexadecimal, we need to output contiguous single bytes, each byte in hexadecimal. At this point we can use the od command to group the file in a single byte, with the output in base 106 on the same line, and remove the Spaces between each byte. It is not yet known how to remove the space between columns by specifying the relevant options for the od command, which may not be supported by the od command itself. Here's what I did:

(8.1) -An is used to output no offset address;
(8.2) repeated data are not omitted when -v is used for output;
(8.3) use -tx1 to output a single byte as a group in base 106, and -w1 to output 1 byte per column;
(8.4) finally, the standard input passed through the pipeline to awk will output all the lines through awk without a line feed, which is splicing into 1 line output.

The specific commands are as follows:


od -An -w1 -tx1 testfile|awk '{for(i=1;i<=NF;++i){printf "%s",$i}}'

reference

[1]od help document

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: