LinuxCommandLibrary

xxd

Create hexdumps (hexadecimal representation) of files

TLDR

Generate a hexdump from a binary file and display the output

$ xxd [input_file]
copy

Generate a hexdump from a binary file and save it as a text file
$ xxd [input_file] [output_file]
copy

Display a more compact output, replacing consecutive zeros (if any) with a star
$ xxd [[-a|-autoskip]] [input_file]
copy

Display the output with 10 columns of one octet (byte) each
$ xxd [[-c|-cols]] [10] [input_file]
copy

Display output only up to a length of 32 bytes
$ xxd [[-l|-len]] [32] [input_file]
copy

Display the output in plain mode, without any gaps between the columns
$ xxd [[-p|-postscript]] [input_file]
copy

Revert a plaintext hexdump back into binary, and save it as a binary file
$ xxd [[-r|-revert]] [[-p|-postscript]] [input_file] [output_file]
copy

SYNOPSIS

xxd [options] [file]
xxd -r [options] [infile] [outfile]

PARAMETERS

-a
    Toggle autoskip: replace lines of zeroes with a single asterisk.

-b
    Binary dump: display bits (0s and 1s) instead of hexadecimal values.

-c cols
    Format cols bytes per line.

-g group_size
    Separate group_size bytes with spaces in the hex output.

-i
    Output in C include file style (unsigned char array).

-l len
    Limit to len bytes of input.

-o offset
    Add offset to the file position shown.

-p
    Plain dump: no address or ASCII part, only hexadecimal bytes.

-r
    Reverse operation: convert a hex dump back to binary.

-s offset
    Start at offset bytes into the input file.

-u
    Use upper case hex letters (A-F).

DESCRIPTION

xxd is a versatile command-line utility for creating hex dumps of files or standard input, and for converting hex dumps back into their original binary form. It is often used by programmers, system administrators, and security researchers to inspect the raw content of binary files, executables, memory dumps, or network packets.

Unlike some other hex dump utilities, xxd is renowned for its ability to convert back, making it useful for patching binaries or embedding data. It offers various formatting options, allowing users to control the number of bytes per line, group bytes, display ASCII or EBCDIC representations, and even generate C-style array definitions. Its dual functionality of dumping and reversing makes it a powerful tool for low-level data manipulation and analysis.

CAVEATS

When using xxd -r, the input hex dump must adhere strictly to xxd's own output format, or a very similar structure, for successful conversion. It is not a general-purpose hex parser for arbitrary formats.

Generating hex dumps of extremely large files can create very large text files, potentially consuming significant disk space and memory if loaded into an editor.

C INCLUDE FILE STYLE

When using the -i option, xxd generates output suitable for inclusion in C or C++ source code as an array of unsigned characters. This is extremely useful for embedding binary data (like images, firmware, or small resources) directly into compiled applications. The output includes an array declaration with the data in hexadecimal format and a variable holding the total length.

REVERSE CONVERSION USE CASES

The -r (reverse) option allows xxd to convert a hex dump back into its original binary form. This is invaluable for tasks such as patching binary files (editing a hex dump and then converting it back), recreating binary data from textual representations, or even for simple data obfuscation/de-obfuscation in scripts.

HISTORY

xxd was originally written by Jorg Schilling for the Vim editor project in 1990. It has been a part of the Vim distribution (often included in vim-common or vim-full packages) for a long time, providing its hex dumping and reverse conversion capabilities directly alongside the editor's development. Its close association with Vim ensures its continued maintenance and widespread availability on Unix-like systems.

SEE ALSO

od(1), hexdump(1), cat(1), less(1), more(1)

Copied to clipboard