xxd: hex dump and restore binary files
View any file's raw bytes as hex on Linux with xxd, convert to plain hex with -p and back with -r.
Run xxd FILE for the classic hex+ASCII dump, xxd -p for hex only, and xxd -r to turn a hex dump back into binary.
01Command
Command
$ xxd file.bin | head -20 && echo -n 'text' | xxd -p && xxd -r -p < hex.txt > out.bin02What it does
xxd (bundled with vim, also in vim-common on most distros) shows each line's offset, 16 bytes in hex, and the printable ASCII rendition — the standard first look inside a binary. The round-trip flags are the real power: xxd -p emits bare hex that's easy to slice with cut, and xxd -r reverses any hex dump (even one you edited) back into bytes, enabling byte-level file patching from the shell.
03Risk
!Warning: xxd -r tolerates only certain formatting; dumps you edit must keep the xxd column layout or the reversal corrupts output.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- xxd(1) — Ubuntu manpageEvidence: Documents xxd hexdump output, -p/-r conversion modes and -g grouping
- xxd(1) — Arch Linux manualEvidence: xxd creates a hex dump; -p outputs plain hex, -r reverses the dump back to binary, -s/-l select offsets and length
Last verified: 2026-09-17 · Category: Developer