Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Usage of hexdump command in Linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The hexdump command is generally used to view the hexadecimal code of "binary" files. From the manual, you can see a lot more, such as ascii, decimal, hexadecimal, octal.

Parameters:

Hexdump [- bcCdovx] [- e format_string] [- f format_file] [- n length] [- s skip] file

Example:

Add a new text file and add the following to the test text:

[root@node61 test] # cat test abcdeABCDE

1) the simplest view

[root@node61 test] # hexdump test 0000000 6261 6463 0a65 4241 4443 0a45 000000c

First column: represents the file offset

Second column: hexadecimal with a set of two bytes

Through the above output, the text is translated into: badc0aeBADC0aE (Note: in Linux, the hexadecimal code of the newline character\ n is 0a, in windows, the hexadecimal code of the newline character\ r\ n is: 0d0a), and the following figure shows the binary code corresponding to the ASC code table.

Careful readers may have found out why the translation into text is in reverse order. The content in the text is not: abcde

ABCDE?

In fact, this is caused by the CPU architecture of X86, and another study has been carried out: byte order.

Byte order: is actually the byte order, here is for more than two bytes, a byte there is no sorting, however, in most of the work, we rarely deal directly with byte order.

Two types of byte order classification: Big-Endian and Little-Endian

The relevant definitions are as follows:

I) Little-Endian means that low-order bytes are placed on the low-address side of memory, while high-order bytes are placed on the high-address side of memory. (order adopted by X86 CPU series)

Ii) Big-Endian means that the high-order bytes are placed on the low address side of the memory, and the low-order bytes are placed on the high address side of the memory.

Iii) network byte order: each layer protocol of TCP/IP defines byte order as Big-Endian, so the byte order used in TCP/IP protocol is usually called network byte order.

The following program is used to determine which mode CPU uses?

# includeint main () {union w {int a; char b;} c; c. A = 1; if (c.b==1) {printf ("The CPU is Litle-Endian\ n");} else {printf ("The CPU is Big-Endian\ n");} return 0;} / * end checkCPU*/gcc-o checkCPU.o checkCPU.c [root@node61 test] #. / checkCPU.o The CPU is Litle-Endian

My local virtual machine is in X86 small-end mode.

At this point, the reason why the use of hexdump is reversed.

Is there a more convenient way to view it? Yes, this is also a more common way, see b) introduction below

B) display the characters in the file in hexadecimal and corresponding ASCII characters

[root@node61 test] # hexdump-C test # commonly used 00000000 61 62 63 64 65 0a 41 42 43 44 45 0a | abcde.ABCDE. | 0000000c

It can display both hexadecimal and ascii codes.

C) output in offset format, parameter-s

[root@node61 test] # hexdump-C test 00000000 61 62 63 64 65 0a 41 42 43 44 45 0a | abcde.ABCDE. | 00000C [root @ node61 test] # hexdump-C-s 6 test 00000006 41 42 43 44 45 0a | ABCDE. | 0000000c

The abcde newline on the first line is gone.

There are many other uses of hexdump. For more information, please see man hexdump

The above is the whole content of this article, if there are other questions and do not understand, you can contribute to us or leave a message below.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report