The Linux Page

xxd to convert binary files to hexadecimal

Colors in Hexadecimal

See Binary File Contents

The Linux system comes with a tool named xxd, which is very useful to print binary files to a list of hexadecimal bytes.

It is pretty well thought of. I had my own atype command, but I now tend to use xxd because it's by default on most Linux systems, so no need to compile & install my own tool.

The most interesting feature, which I found out today, is that the tool is capable of doing the inverse (see the -r option): it can read its own output and generate a binary file again. It actually doesn't need to be output from xxd, just hexadecimal codes.

The command supports input with or without the address and ASCII columns.

Another interesting feature is the control of the number of the number of columns you can output with the -c command line option.

Why is xxd useful anyway?

Many times, when I create a binary file, I need to verify that it looks correct. This is one of the most useful way to do so. I also like the vbindiff tool, which allows me to compare two binary files or just interactively look at one binary file. However, this tool has much less flexibility in terms of number of columns and such. Yet, the vbindiff allows you to edit the file (but no Insert and no Delete of bytes).