· 1 min read
Quick Guide to Using xxd
This article was auto-translated from Chinese. Some nuances may be lost in translation.
xxd is a Linux tool for viewing binary files.
Why Would You Want to Inspect Binary Files?
- To check if the compiled program matches what you expected
- To inspect the contents of image or video files
- Pure curiosity
Using xxd
xxd filename
This outputs the file contents 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 is the address of the hex dump (dumping 16 bytes per line by default); the second is the file contents; and the rightmost is the raw representation of the file, where non-printable characters are printed as ..
xxd -r filename
This command can reverse the hex dump back into the original binary file.
Useful Combos
xxd filename | vim -: View a binary file usingvimvim filenameand then run:%!xxd -rinside it to edit binary files using vimxxd filename > dump.hex: Well… dump it directly to a file, which can then be used withdiff
Related Posts
- When a Measure Becomes a Target: From the Window Tax to Pull Request Counts I once wrote a script to tally how many PRs I contributed in a quarter, how many reviews I left, and how many tickets I closed, hoping to use numbers to prove my output to my manager. My manager simply remarked that performance isn't just about output. Years later, I finally understood—when a measure becomes a target, it ceases to be a good measure. From the British window tax and the Hanoi rat bounty to evaluating developers by PR counts today, the underlying mechanism is exactly the same.
- Using Cloudflare Images for Image Storage and Transformation Putting an image on a webpage is the simplest task in frontend development. But doing it properly—including resizing, generating multiple formats, and withstanding heavy traffic—is actually an entire end-to-end solution. Eventually, I offloaded everything to Cloudflare Images, keeping only a single original image.
- Stop Using AWS Access Keys Access Keys are an easily overlooked security risk in AWS. By pairing OIDC with IAM Roles, GitHub Actions can securely operate AWS resources without storing any secrets.
- Database Primary Keys: AUTO_INCREMENT, UUID, and UUIDv7 Backend developers often face the choice of primary keys: should you use auto-increment or UUID? What about collisions? How does UUIDv7 compare to created_at + index in performance? Here are the design decisions and benchmark results from testing 20 million rows.