If you have any questions or feedback, pleasefill out this form
This post is translated by ChatGPT and originally written in Mandarin, so there may be some inaccuracies or mistakes.
xxd
is a Linux tool that allows you to view binary files.
Why Would You Want to Look at Binary Files?
- To check if the compiled program matches your expectations
- To inspect the content of image or video files
- Pure curiosity
Using xxd
xxd filename
This command will output the file content like this:
00000000: 4500 6d00 7000 7400 7900 0000 0000 0000 E.m.p.t.y.......
00000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................
The output can be divided into three sections: the first is the hex dump address, with each line dumping 16 characters (by default), the second is the file content (displayed in ASCII encoding), and the far right shows the raw values of the file. If there are any unprintable characters, they will be represented by a .
.
xxd -r filename
This command can revert the binary file back to its original form.
Some Helpful Combinations
xxd filename | vim -
: View the binary file usingvim
- Open
vim filename
and then within it type:%!xxd -r
to edit the binary file using vim xxd filename > dump.hex
: Save the output directly to a file, which can be used withdiff
for comparison
If you found this article helpful, please consider buying me a coffee ☕ It'll make my ordinary day shine ✨
☕Buy me a coffee