Kalan's Blog

Software Engineer / Taiwanese / Life in Fukuoka

Current Theme light

xxd is a Linux tool that allows you to view binary files.

Why would you want to view binary files?

  • To compare the compiled program with what you intended
  • To inspect the contents of image or video files
  • Out of pure curiosity

Usage of xxd

xxd filename

This command will output the content of the file 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  ................

It can be divided into three sections: the first one is the hex dump address, each line represents 16 characters (by default), the second section is the file content (in ASCII encoding), and the rightmost section displays the original values of the file. If there are any characters that cannot be displayed, a . will be shown.

xxd -r filename

This command can be used to restore the binary file to its original form.

Some combinations of techniques

  1. xxd filename | vim -: View a binary file using vim
  2. Open vim filename and inside vim, run :%!xxd -r to edit a binary file using vim
  3. xxd filename > dump.hex: Directly save the output to a file, which can be used with diff for comparison.

Prev

Rise of Creators - Programming

Next

Pips are still Important/idea still count

If you found this article helpful, please consider buy me a drink ☕️ It'll make my ordinary day shine✨

Buy me a coffee

作者

Kalan 頭像照片,在淡水拍攝,淺藍背景

愷開 | Kalan

Hi, I'm Kai. I'm Taiwanese and moved to Japan in 2019 for work. Currently settled in Fukuoka. In addition to being familiar with frontend development, I also have experience in IoT, app development, backend, and electronics. Recently, I started playing electric guitar! Feel free to contact me via email for consultations or collaborations or music! I hope to connect with more people through this blog.