Hexdump tool and binary view of. TXT file


Recently, when using the txt file for data processing, I suddenly found out how the txt file encodes the data. Is it stored in binary? In order to know this situation, I used the hexdump tool to view the binary form of the txt file, and learned the use of the hexdump file by the way:

Hexdump is generally used to view the hexadecimal encoding of “binary” files, but in fact it can view any file, not only binary files:

Hexdump [options] [file]
-N length: format the first length bytes of the output file
-C: Output specification hexadecimal and ASCII code
-b: Single byte octal display
-c: Single byte character display
-d: Double byte decimal display
-o: Double byte octal display
-x: Double byte hex display
-s: Output from offset
-E specifies the format string, which is enclosed by single quotation marks. The format string is as follows: 'A / b "format1" "format2". Each format string consists of three parts, each of which is divided by a space. For example, a / b indicates that format 1 is applied to each B input bytes, a indicates that format 2 is applied to each a input byte, generally a > b, and B can only be 1,2,4. In addition, a can be omitted, a = 1. In format1 and format2, you can use a Gus string similar to printf. %02D: two decimal
%03x: three hexadecimal
%02O: two digit octal
%c: Single character, etc
%_Ad: mark the serial number of the next output byte, expressed in decimal system
%_Ax: mark the serial number of the next output byte, expressed in hexadecimal
%_Ao: mark the serial number of the next output byte, expressed in octal
%_p: Instead of. For those that cannot be displayed with regular characters
The same line displays multiple format strings, which can be followed by multiple - e options

Common commands:

Format output file

hexdump test

Format output file的前10个字节

hexdump -n 10 test

Format output file的前10个字节,并以16进制显示

hexdump -n 10 -C test

Format 10 bytes of output starting from 20 and display in hexadecimal

hexdump -n 10 -C -s 20

To view a text file using hexdump:

The licenses for most software and other practical works are designed
to take away your freedom to share and change the works.  By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.  We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors.  You can apply it to
your programs, too.
hexdump -C hexdump.txt

View results:

It can be seen that the txt file itself does not have any format, but only translates ASCII characters; therefore, the txt file can also be opened in the form of ‘RB’ binary and can be opened every time

8 bits for reading and parsing;