How to use the common command hexdump in Linux
Editor to share with you how to use the Linux command hexdump, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The commonly used Linux command hexdump is mainly used to view the hexadecimal coding of "binary" files. * Note: it can view any file, not limited to binary files
Syntax hexdump [options] [file]...
Option-n length: format the first length bytes of the output file
-C: output specification hexadecimal and ASCII codes
-b: single byte octal display
-c: single-byte character display
-d: double-byte decimal display
-o: double-byte octal display
-x: double-byte hexadecimal display
-s: output from offset
-e specifies the format string
The format string is enclosed in single quotation marks and is shaped like:'a format1 b 'format1' and 'format string' Each format string is composed of three parts, each is divided by spaces, such as a format1 b, b means to apply the format2 format to every b input bytes, a means to apply format2 to each an input byte, generally a > b, and b can only be 1Magi 2Q 4, in addition a can be omitted and axiom 1 can be omitted. A Gus string similar to printf can be used in format1 and format2.
D: two-digit decimal
X: three-digit hexadecimal
O: two-digit octal
% c: single character, etc.
% _ ad: marks the sequence number of the next output byte, expressed in decimal
% _ ax: marks the sequence number of the next output byte, expressed in hexadecimal
% _ ao: marks the sequence number of the next output byte, expressed in octal
% _ p: for those that cannot be displayed in regular characters. Replace
Multiple format strings are displayed on the same line, with multiple-e options
Example C language saves binary file test
# include # include int main () {FILE * fp_in; fp_in = fopen ("test", "wb"); if (fp_in = = NULL) {printf ("open test failed\ n"); return-1;} else {for (unsigned char i = 0) I compile: Gmail + main.cpp-o main execute:. / main to generate binary file test format output file
Hexdump test
Format the first 10 bytes of the output file
Hexdump-n 10 test
Format the first 10 bytes of the output file and display it in hexadecimal
Hexdump-n 10-C test
Format the output 10 bytes starting at 10 and display it in hexadecimal
Hexdump-n 10-C-s 20
Format output file characters
H
Hexdump-e'16 test 1 "X" | "'- e'16 shock 1"% _ p ""\ n "'
Hexdump-e '1gamma 1 "0x_ax"-e' 8gamma 1 "X"*"-e '8gamma 1 "% _ p"\ n"' test
Hexdump-e'1 1 "_ ad#"-e'/ 1 "hex = X *"-e'/ 1 "dec = d |"-e'/ 1 "oct = o"-e'/ 1 "_\ n"-n 20 test
The above is all the contents of the article "how to use Linux commands hexdump". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!