← 返回命令列表

Linux command

xxd 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Create a hex dump

xxd [file]

Create a plain hex dump

xxd -p [file]

Create a binary dump

xxd -b [file]

Dump only first N bytes

xxd -l [16] [file]

Start at a specific offset

xxd -s [0x100] [file]

Output as C include

xxd -i [file]

Convert hex dump back to binary

xxd -r [hexdump.txt] [output.bin]

Convert plain hex

echo "[48656c6c6f]" | xxd -r -p

说明

xxd creates a hexadecimal dump of a file or standard input. The output shows the offset, hexadecimal values, and ASCII representation of the data. It can also reverse a hex dump back to the original binary. The default output format shows 16 bytes per line with the file offset, hex values in groups of 2 bytes, and printable ASCII characters. The -p option produces a continuous hex string without formatting. The -i option generates C source code with the data as an unsigned char array, useful for embedding binary data in programs. The -r option reverses the process, converting a hex dump back to binary. Combined with -p, it can convert plain hex strings to binary data.

参数

-b
Binary digit dump instead of hexadecimal
-c _cols_
Format output with specified columns per line (default: 16)
-g _bytes_
Number of bytes per group (default: 2)
-i
Output as C include file (array definition)
-l _len_
Stop after outputting len bytes
-p, -ps, -plain
Plain hexdump style (continuous hex without addresses)
-r, -revert
Reverse operation: convert hexdump to binary
-s _seek_
Start at specified offset in file
-u
Use uppercase hexadecimal letters
-e
Little-endian dump (group bytes are reversed)

FAQ

What is the xxd command used for?

xxd creates a hexadecimal dump of a file or standard input. The output shows the offset, hexadecimal values, and ASCII representation of the data. It can also reverse a hex dump back to the original binary. The default output format shows 16 bytes per line with the file offset, hex values in groups of 2 bytes, and printable ASCII characters. The -p option produces a continuous hex string without formatting. The -i option generates C source code with the data as an unsigned char array, useful for embedding binary data in programs. The -r option reverses the process, converting a hex dump back to binary. Combined with -p, it can convert plain hex strings to binary data.

How do I run a basic xxd example?

Run `xxd [file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -b do in xxd?

Binary digit dump instead of hexadecimal