# phpman > man > XXD(1)

> **TLDR:** Create a hexadecimal representation (hexdump) from a binary file, or vice-versa.
>
- Generate a hexdump from a binary file and display the output:
  `xxd {{input_file}}`
- Generate a hexdump from a binary file and save it as a text file:
  `xxd {{input_file}} {{output_file}}`
- Display a more compact output, replacing consecutive zeros (if any) with a star:
  `xxd {{-a|-autoskip}} {{input_file}}`
- Display the output with 10 columns of one octet (byte) each:
  `xxd {{-c|-cols}} {{10}} {{input_file}}`
- Display output only up to a length of 32 bytes:
  `xxd {{-l|-len}} {{32}} {{input_file}}`
- Display the output in plain mode, without any gaps between the columns:
  `xxd {{-p|-postscript}} {{input_file}}`
- Revert a plaintext hexdump back into binary, and save it as a binary file:
  `xxd {{-r|-revert}} {{-p|-postscript}} {{input_file}} {{output_file}}`

*Source: tldr-pages*

---

[XXD(1)](https://www.chedong.com/phpMan.php/man/XXD/1/markdown)                                 General Commands Manual                                [XXD(1)](https://www.chedong.com/phpMan.php/man/XXD/1/markdown)



## NAME
       _xxd_ - make a hexdump or do the reverse.

## SYNOPSIS
       **xxd** -h[elp]
       **xxd** [options] [infile [outfile]]
       **xxd** -r[evert] [options] [infile [outfile]]

## DESCRIPTION
       _xxd_  creates  a  hex  dump of a given file or standard input.  It can also convert a hex dump
       back to its original binary form.  Like [**uuencode**(1)](https://www.chedong.com/phpMan.php/man/uuencode/1/markdown) and [**uudecode**(1)](https://www.chedong.com/phpMan.php/man/uudecode/1/markdown) it allows  the  transmis‐
       sion  of binary data in a `mail-safe' ASCII representation, but has the advantage of decoding
       to standard output.  Moreover, it can be used to perform binary file patching.

## OPTIONS
       If no _infile_ is given, standard input is read.  If _infile_ is specified as  a  `**-**'  character,
       then  input  is  taken from standard input.  If no _outfile_ is given (or a `**-**' character is in
       its place), results are sent to standard output.

       Note that a "lazy" parser is used which does not check for more than the first option letter,
       unless  the option is followed by a parameter.  Spaces between a single option letter and its
       parameter are optional.  Parameters to options can be specified in  decimal,  hexadecimal  or
       octal notation.  Thus **-c8**, **-c** **8**, **-c** **010** and **-cols** **8** are all equivalent.

       _-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 "1"s and "0"s instead of a normal hexadecimal dump. Each line is  pre‐
              ceded by a line number in hexadecimal and followed by an ascii (or ebcdic) representa‐
              tion. The command line switches -r, -p, -i do not work with this mode.

       _-c_ _cols_ | _-cols_ _cols_
              Format <_cols_> octets per line. Default 16 (-i: 12, -ps: 30, -b: 6). Max 256.

       _-C_ | _-capitalize_
              Capitalize variable names in C include file style, when using -i.

       _-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 op‐
              tion 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_ _bytes_ | _-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_ _len_
              Stop after writing <_len_> octets.

       _-o_ _offset_
              Add <_offset_> to the displayed file position.

       _-p_ | _-ps_ | _-postscript_ | _-plain_
              Output in postscript continuous hexdump style. Also known as plain hexdump style.

       _-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 rel‐
              ative 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.

## CAVEATS
       _xxd_ _-r_ has some builtin magic while evaluating line number information.  If the  output  file
       is  seekable,  then  the  linenumbers  at the start of each hexdump line may be out of order,
       lines may be missing, or overlapping. In these cases xxd will [lseek(2)](https://www.chedong.com/phpMan.php/man/lseek/2/markdown) to the next  position.
       If  the  output  file  is  not seekable, only gaps are allowed, which will be filled by null-
       bytes.

       _xxd_ _-r_ never generates parse errors. Garbage is silently skipped.

       When editing hexdumps, please note that _xxd_ _-r_ skips everything on the input line after read‐
       ing  enough columns of hexadecimal data (see option -c). This also means, that changes to the
       printable ascii (or ebcdic) columns are always ignored. Reverting  a  plain  (or  postscript)
       style  hexdump with xxd -r -p does not depend on the correct number of columns. Here anything
       that looks like a pair of hex-digits is interpreted.

       Note the difference between
       _%_ _xxd_ _-i_ _file_
       and
       _%_ _xxd_ _-i_ _<_ _file_

       _xxd_ _-s_ _+seek_ may be different from _xxd_ _-s_ _seek_, as [lseek(2)](https://www.chedong.com/phpMan.php/man/lseek/2/markdown) is used to "rewind" input.  A '+'
       makes  a  difference if the input source is stdin, and if stdin's file position is not at the
       start of the file by the time xxd is started and given its input.  The following examples may
       help to clarify (or further confuse!)...

       Rewind stdin before reading; needed because the `cat' has already read to the end of stdin.
       _%_ _sh_ _-c_ _"cat_ _>_ _plain_copy;_ _xxd_ _-s_ _0_ _>_ _hex_copy"_ _<_ _file_

       Hexdump  from  file  position 0x480 (=1024+128) onwards.  The `+' sign means "relative to the
       current position", thus the `128' adds to the 1k where dd left off.
       _%_ _sh_ _-c_ _"dd_ _of=plain_snippet_ _bs=1k_ _count=1;_ _xxd_ _-s_ _+128_ _>_ _hex_snippet"_ _<_ _file_

       Hexdump from file position 0x100 ( = 1024-768) on.
       _%_ _sh_ _-c_ _"dd_ _of=plain_snippet_ _bs=1k_ _count=1;_ _xxd_ _-s_ _+-768_ _>_ _hex_snippet"_ _<_ _file_

       However, this is a rare situation and the use of `+' is rarely needed.  The author prefers to
       monitor the effect of xxd with [strace(1)](https://www.chedong.com/phpMan.php/man/strace/1/markdown) or [truss(1)](https://www.chedong.com/phpMan.php/man/truss/1/markdown), whenever -s is used.

## EXAMPLES
       Print everything but the first three lines (hex 0x30 bytes) of **file**.
       _%_ _xxd_ _-s_ _0x30_ _file_

       Print 3 lines (hex 0x30 bytes) from the end of **file**.
       _%_ _xxd_ _-s_ _-0x30_ _file_

       Print 120 bytes as continuous hexdump with 20 octets per line.
       _%_ _xxd_ _-l_ _120_ _-ps_ _-c_ _20_ _xxd.1_
       2e54482058584420312022417567757374203139
       39362220224d616e75616c207061676520666f72
       20787864220a2e5c220a2e5c222032317374204d
       617920313939360a2e5c22204d616e2070616765
       20617574686f723a0a2e5c2220202020546f6e79
       204e7567656e74203c746f6e79407363746e7567

       Hexdump the first 120 bytes of this man page with 12 octets per line.
       _%_ _xxd_ _-l_ _120_ _-c_ _12_ _xxd.1_
       0000000: 2e54 4820 5858 4420 3120 2241  .TH XXD 1 "A
       000000c: 7567 7573 7420 3139 3936 2220  ugust 1996"
       0000018: 224d 616e 7561 6c20 7061 6765  "Manual page
       0000024: 2066 6f72 2078 7864 220a 2e5c   for xxd"..\
       0000030: 220a 2e5c 2220 3231 7374 204d  "..\" 21st M
       000003c: 6179 2031 3939 360a 2e5c 2220  ay 1996..\"
       0000048: 4d61 6e20 7061 6765 2061 7574  Man page aut
       0000054: 686f 723a 0a2e 5c22 2020 2020  hor:..\"
       0000060: 546f 6e79 204e 7567 656e 7420  Tony Nugent
       000006c: 3c74 6f6e 7940 7363 746e 7567  <tony@sctnug

       Display just the date from the file xxd.1
       _%_ _xxd_ _-s_ _0x36_ _-l_ _13_ _-c_ _13_ _xxd.1_
       0000036: 3231 7374 204d 6179 2031 3939 36  21st May 1996

       Copy **input**___**file** to **output**___**file** and prepend 100 bytes of value 0x00.
       _%_ _xxd_ _input_file_ _|_ _xxd_ _-r_ _-s_ _100_ _>_ _output_file_

       Patch the date in the file xxd.1
       _%_ _echo_ _"0000037:_ _3574_ _68"_ _|_ _xxd_ _-r_ _-_ _xxd.1_
       _%_ _xxd_ _-s_ _0x36_ _-l_ _13_ _-c_ _13_ _xxd.1_
       0000036: 3235 7468 204d 6179 2031 3939 36  25th May 1996

       Create  a  65537  byte  file  with  all bytes 0x00, except for the last one which is 'A' (hex
       0x41).
       _%_ _echo_ _"010000:_ _41"_ _|_ _xxd_ _-r_ _>_ _file_

       Hexdump this file with autoskip.
       _%_ _xxd_ _-a_ _-c_ _12_ _file_
       0000000: 0000 0000 0000 0000 0000 0000  ............
       *
       000fffc: 0000 0000 40                   ....A

       Create a 1 byte file containing a single 'A' character.  The number after '-r -s' adds to the
       linenumbers found in the file; in effect, the leading bytes are suppressed.
       _%_ _echo_ _"010000:_ _41"_ _|_ _xxd_ _-r_ _-s_ _-0x10000_ _>_ _file_

       Use  xxd  as  a filter within an editor such as [**vim(1)](https://www.chedong.com/phpMan.php/man/vim/1/markdown)** to hexdump a region marked between `a'
       and `z'.
       _:'a,'z!xxd_

       Use xxd as a filter within an editor such as [**vim(1)](https://www.chedong.com/phpMan.php/man/vim/1/markdown)** to recover a binary  hexdump  marked  be‐
       tween `a' and `z'.
       _:'a,'z!xxd_ _-r_

       Use  xxd  as a filter within an editor such as [**vim(1)](https://www.chedong.com/phpMan.php/man/vim/1/markdown)** to recover one line of a hexdump.  Move
       the cursor over the line and type:
       _!!xxd_ _-r_

       Read single characters from a serial line
       _%_ _xxd_ _-c1_ _<_ _/dev/term/b_ _&_
       _%_ _stty_ _<_ _/dev/term/b_ _-echo_ _-opost_ _-isig_ _-icanon_ _min_ _1_
       _%_ _echo_ _-n_ _foo_ _>_ _/dev/term/b_

## RETURN VALUES
       The following error values are returned:

       0      no errors encountered.

       -1     operation not supported ( _xxd_ _-r_ _-i_ still impossible).

       1      error while parsing options.

       2      problems with input file.

       3      problems with output file.

       4,5    desired seek position is unreachable.

## SEE ALSO
       [uuencode(1)](https://www.chedong.com/phpMan.php/man/uuencode/1/markdown), [uudecode(1)](https://www.chedong.com/phpMan.php/man/uudecode/1/markdown), [patch(1)](https://www.chedong.com/phpMan.php/man/patch/1/markdown)

## WARNINGS
       The tools weirdness matches its creators brain.  Use entirely at your own risk.  Copy  files.
       Trace it. Become a wizard.

## VERSION
       This manual page documents xxd version 1.7

## AUTHOR
       (c) 1990-1997 by Juergen Weigert
       <<jnweiger@informatik.uni-erlangen.de>>

       Distribute freely and credit me,
       make money and share with me,
       lose money and don't ask me.

       Manual page started by Tony Nugent
       <<tony@sctnugen.ppp.gu.edu.au>> <<T.Nugent@sct.gu.edu.au>>
       Small changes by Bram Moolenaar.  Edited by Juergen Weigert.

Manual page for xxd                          August 1996                                      [XXD(1)](https://www.chedong.com/phpMan.php/man/XXD/1/markdown)
