· 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

  1. xxd filename | vim -: View a binary file using vim
  2. vim filename and then run :%!xxd -r inside it to edit binary files using vim
  3. xxd filename > dump.hex: Well… dump it directly to a file, which can then be used with diff

Related Posts

Explore Other Topics