Search notes:

Shell command: xxd

xxd creates hex dumps or does the reverse.

Command line options

xxd [options] [infile [outfile]]
xxd -r[evert] [options] [infile [outfile]]
xxd -h[elp]
A command line option has a short form (first column) and sometimes a long alternative (second column).
If the option takes an argument, its listed in the third column.
-a -autoskip Toggle autoskip: A single * replaces nul-lines. Default off.
-b -bits Switch to bits (binary digits) dump, rather than hexdump. This option writes octets as eight digits 1s and 0s instead of a normal hexadecimal dump. Each line is preceded by a line number in hexadecimal and followed by an ASCII (or ebcdic) representation. The command line switches -r, -p, -i do not work with this mode.
-c -cols cols format <cols> octets per line. Default 16 (-i: 12, -ps: 30, -b: 6). Max 256.
-E -EBCDIC Change the character encoding in the righthand column from ASCII to EBCDIC. This does not change the hexadecimal representation. The option is meaningless in combinations with -r, -p or -i.
-e Switch to little-endian hexdump. This option treats byte groups as words in little-endian byte order. The default grouping of 4 bytes may be changed using -g. This option only applies to hexdump, leaving the ASCII (or EBCDIC) representation unchanged. The command line switches -r, -p, -i do not work with this mode.
-g -groupsize <bytes> Separate the output of every <bytes> bytes (two hex characters or eight bit-digits each) by a whitespace. Specify -g 0 to suppress grouping. <bytes> defaults to 2 in normal mode, 4 in little-endian mode and 1 in bits mode. Grouping does not apply to PostScript or include style.
-h -help Print a summary of available commands and exit. No hex dumping is performed.
-i -include Output in C include file style. A complete static array definition is written (named after the input file), unless xxd reads from stdin.
-l -len len Stop after writing <len> octets.
-o offset Add <offset> to the displayed file position.
-p -postscript Output in PostScript continuous hexdump style. Also known as plain hexdump style. Alternative switches are also -ps and -plain.
-r -revert Reverse operation: convert (or patch) hexdump into binary. If not writing to stdout, xxd writes into its output file without truncating it. Use the combination -r -p to read plain hexadecimal dumps without line number information and without a particular column layout. Additional Whitespace and line-breaks are allowed anywhere.
-seek offset When used after -r: revert with <offset> added to file positions found in hexdump.
-s [+][-]seek Start at <seek> bytes abs. (or rel.) infile offset. + indicates that the seek is relative to the current stdin file position (meaningless when not reading from stdin). - indicates that the seek should be that many characters from the end of the input (or if combined with +: before the current stdin file position). Without -s option, xxd starts at the current file position.
-u Use upper case hex letters. Default is lower case.
-v -version Show version string.

Plain dump

The option -p creates a plain dump:
$ printf abc@DEF | xxd -p
61626340444546

Create a file from a hex stream

-r reverses the operation.
$ printf 616263404445460a | xxd -r - out-file
$ cat out-file
abc@DEF

-i

$ dd if=/dev/random bs=20 count=1 2>/dev/null | xxd  -i
  0xf8, 0x91, 0x72, 0x49, 0x7e, 0xec, 0xc4, 0x04, 0xae, 0x42, 0xd0, 0x16,
  0x57, 0x72, 0x2e, 0x9f, 0xa9, 0xea, 0x1c, 0xc9  

See also

The vim source file src/xxd/xxd.c
Shell commands, od

Index