About
xxd shows a file as hex bytes beside their text. It can also rebuild a file from a dump. It ships with Vim, so it is almost always to hand.
Install it
pkg install vim
Run this inside Termux. If the package is already present, pkg will say so and
do nothing.
Commands worth knowing
6 of the invocations you will actually reach for. Tap the copy button to put one on your clipboard.
xxd file.bin Dump a file as hex with a text column beside it. The standard way to eyeball binary content. xxd -l 64 file.bin Show only the first sixty-four bytes. Enough to check a header or magic number. xxd -s 512 -l 32 file.bin Start partway into the file and show a short window. Good for one specific offset. xxd file.bin dump.hex Write the dump to a second file instead of the terminal, ready to reverse later. xxd -r dump.hex rebuilt.bin Reverse a hex dump back into binary. This is how you reconstruct a file. xxd -i file.bin Produce a C include file holding the bytes as an array. Handy for embedding data in a program. Worked example
Run xxd -l 32 file.bin and this is what you should see.
$ xxd -l 32 file.bin
00000000: 7f45 4c46 0201 0100 0000 0000 0000 0000 .ELF............
00000010: 0300 b700 0100 0000 0000 0000 0000 0000 ................ The left column is the offset; the right reads the same bytes as text.
Developed by
The Vim project .