1XXD(1)                      General Commands Manual                     XXD(1)
2
3
4

NAME

6       xxd - make a hexdump or do the reverse.
7

SYNOPSIS

9       xxd -h[elp]
10       xxd [options] [infile [outfile]]
11       xxd -r[evert] [options] [infile [outfile]]
12

DESCRIPTION

14       xxd  creates a hex dump of a given file or standard input.  It can also
15       convert a hex dump back to its original binary form.  Like  uuencode(1)
16       and  uudecode(1)  it allows the transmission of binary data in a `mail-
17       safe' ASCII representation, but has the advantage of decoding to  stan‐
18       dard output.  Moreover, it can be used to perform binary file patching.
19

OPTIONS

21       If  no infile is given, standard input is read.  If infile is specified
22       as a `-' character, then input is taken from  standard  input.   If  no
23       outfile is given (or a `-' character is in its place), results are sent
24       to standard output.
25
26       Note that a "lazy" parser is used which does not check  for  more  than
27       the  first option letter, unless the option is followed by a parameter.
28       Spaces between a single option letter and its parameter  are  optional.
29       Parameters to options can be specified in decimal, hexadecimal or octal
30       notation.  Thus -c8, -c 8, -c 010 and -cols 8 are all equivalent.
31
32       -a | -autoskip
33              toggle autoskip: A single '*' replaces nul-lines.  Default off.
34
35       -b | -bits
36              Switch to bits (binary digits) dump, rather than hexdump.   This
37              option  writes octets as eight digits "1"s and "0"s instead of a
38              normal hexadecimal dump. Each line is preceded by a line  number
39              in  hexadecimal and followed by an ascii (or ebcdic) representa‐
40              tion. The command line switches -r, -p, -i do not work with this
41              mode.
42
43       -c cols | -cols cols
44              format  <cols> octets per line. Default 16 (-i: 12, -ps: 30, -b:
45              6). Max 256.
46
47       -E | -EBCDIC
48              Change the character encoding in the righthand column from ASCII
49              to EBCDIC.  This does not change the hexadecimal representation.
50              The option is meaningless in combinations with -r, -p or -i.
51
52       -g bytes | -groupsize bytes
53              separate the output of every <bytes> bytes (two  hex  characters
54              or eight bit-digits each) by a whitespace.  Specify -g 0 to sup‐
55              press grouping.  <Bytes> defaults to 2 in normal mode and  1  in
56              bits  mode.   Grouping  does  not apply to postscript or include
57              style.
58
59       -h | -help
60              print a summary of available commands and exit.  No hex  dumping
61              is performed.
62
63       -i | -include
64              output  in C include file style. A complete static array defini‐
65              tion is written (named after the input file), unless  xxd  reads
66              from stdin.
67
68       -l len | -len len
69              stop after writing <len> octets.
70
71       -p | -ps | -postscript | -plain
72              output  in  postscript  continuous  hexdump style. Also known as
73              plain hexdump style.
74
75       -r | -revert
76              reverse operation: convert (or patch) hexdump into  binary.   If
77              not  writing  to stdout, xxd writes into its output file without
78              truncating it. Use the combination -r -p to read plain hexadeci‐
79              mal dumps without line number information and without a particu‐
80              lar column layout. Additional  Whitespace  and  line-breaks  are
81              allowed anywhere.
82
83       -seek offset
84              When used after -r: revert with <offset> added to file positions
85              found in hexdump.
86
87       -s [+][-]seek
88              start at <seek> bytes abs. (or rel.) infile offset.  + indicates
89              that  the  seek  is  relative to the current stdin file position
90              (meaningless when not reading from stdin).  - indicates that the
91              seek  should  be  that many characters from the end of the input
92              (or if combined with +: before the current stdin file position).
93              Without -s option, xxd starts at the current file position.
94
95       -u     use upper case hex letters. Default is lower case.
96
97       -v | -version
98              show version string.
99

CAVEATS

101       xxd -r has some builtin magic while evaluating line number information.
102       If the output file is seekable, then the linenumbers at  the  start  of
103       each  hexdump  line may be out of order, lines may be missing, or over‐
104       lapping. In these cases xxd will lseek(2) to the next position. If  the
105       output  file  is  not  seekable,  only  gaps are allowed, which will be
106       filled by null-bytes.
107
108       xxd -r never generates parse errors. Garbage is silently skipped.
109
110       When editing hexdumps, please note that xxd -r skips everything on  the
111       input line after reading enough columns of hexadecimal data (see option
112       -c). This also means, that changes to the printable ascii  (or  ebcdic)
113       columns  are  always  ignored.  Reverting a plain (or postscript) style
114       hexdump with xxd -r -p does not depend on the correct  number  of  col‐
115       umns.  Here  anything  that  looks  like a pair of hex-digits is inter‐
116       preted.
117
118       Note the difference between
119       % xxd -i file
120       and
121       % xxd -i < file
122
123       xxd -s +seek may be different from xxd -s seek, as lseek(2) is used  to
124       "rewind" input.  A '+' makes a difference if the input source is stdin,
125       and if stdin's file position is not at the start of  the  file  by  the
126       time  xxd  is  started and given its input.  The following examples may
127       help to clarify (or further confuse!)...
128
129       Rewind stdin before reading; needed because the `cat' has already  read
130       to the end of stdin.
131       % sh -c "cat > plain_copy; xxd -s 0 > hex_copy" < file
132
133       Hexdump  from  file  position  0x480 (=1024+128) onwards.  The `+' sign
134       means "relative to the current position", thus the `128' adds to the 1k
135       where dd left off.
136       %  sh -c "dd of=plain_snippet bs=1k count=1; xxd -s +128 > hex_snippet"
137       < file
138
139       Hexdump from file position 0x100 ( = 1024-768) on.
140       % sh -c "dd of=plain_snippet bs=1k count=1; xxd -s +-768 > hex_snippet"
141       < file
142
143       However,  this is a rare situation and the use of `+' is rarely needed.
144       The author prefers to monitor the  effect  of  xxd  with  strace(1)  or
145       truss(1), whenever -s is used.
146

EXAMPLES

148       Print everything but the first three lines (hex 0x30 bytes) of file.
149       % xxd -s 0x30 file
150
151       Print 3 lines (hex 0x30 bytes) from the end of file.
152       % xxd -s -0x30 file
153
154       Print 120 bytes as continuous hexdump with 20 octets per line.
155       % xxd -l 120 -ps -c 20 xxd.1
156       2e54482058584420312022417567757374203139
157       39362220224d616e75616c207061676520666f72
158       20787864220a2e5c220a2e5c222032317374204d
159       617920313939360a2e5c22204d616e2070616765
160       20617574686f723a0a2e5c2220202020546f6e79
161       204e7567656e74203c746f6e79407363746e7567
162
163       Hexdump the first 120 bytes of this man page with 12 octets per line.
164       % xxd -l 120 -c 12 xxd.1
165       0000000: 2e54 4820 5858 4420 3120 2241  .TH XXD 1 "A
166       000000c: 7567 7573 7420 3139 3936 2220  ugust 1996"
167       0000018: 224d 616e 7561 6c20 7061 6765  "Manual page
168       0000024: 2066 6f72 2078 7864 220a 2e5c   for xxd"..\
169       0000030: 220a 2e5c 2220 3231 7374 204d  "..\" 21st M
170       000003c: 6179 2031 3939 360a 2e5c 2220  ay 1996..\"
171       0000048: 4d61 6e20 7061 6765 2061 7574  Man page aut
172       0000054: 686f 723a 0a2e 5c22 2020 2020  hor:..\"
173       0000060: 546f 6e79 204e 7567 656e 7420  Tony Nugent
174       000006c: 3c74 6f6e 7940 7363 746e 7567  <tony@sctnug
175
176       Display just the date from the file xxd.1
177       % xxd -s 0x36 -l 13 -c 13 xxd.1
178       0000036: 3231 7374 204d 6179 2031 3939 36  21st May 1996
179
180       Copy input_file to output_file and prepend 100 bytes of value 0x00.
181       % xxd input_file | xxd -r -s 100 > output_file
182
183       Patch the date in the file xxd.1
184       % echo "0000037: 3574 68" | xxd -r - xxd.1
185       % xxd -s 0x36 -l 13 -c 13 xxd.1
186       0000036: 3235 7468 204d 6179 2031 3939 36  25th May 1996
187
188       Create  a  65537 byte file with all bytes 0x00, except for the last one
189       which is 'A' (hex 0x41).
190       % echo "010000: 41" | xxd -r > file
191
192       Hexdump this file with autoskip.
193       % xxd -a -c 12 file
194       0000000: 0000 0000 0000 0000 0000 0000  ............
195       *
196       000fffc: 0000 0000 40                   ....A
197
198       Create a 1 byte file containing a single  'A'  character.   The  number
199       after '-r -s' adds to the linenumbers found in the file; in effect, the
200       leading bytes are suppressed.
201       % echo "010000: 41" | xxd -r -s -0x10000 > file
202
203       Use xxd as a filter within an editor such as vim(1) to hexdump a region
204       marked between `a' and `z'.
205       :'a,'z!xxd
206
207       Use xxd as a filter within an editor such as vim(1) to recover a binary
208       hexdump marked between `a' and `z'.
209       :'a,'z!xxd -r
210
211       Use xxd as a filter within an editor such as vim(1) to recover one line
212       of a hexdump.  Move the cursor over the line and type:
213       !!xxd -r
214
215       Read single characters from a serial line
216       % xxd -c1 < /dev/term/b &
217       % stty < /dev/term/b -echo -opost -isig -icanon min 1
218       % echo -n foo > /dev/term/b
219

RETURN VALUES

221       The following error values are returned:
222
223       0      no errors encountered.
224
225       -1     operation not supported ( xxd -r -i still impossible).
226
227       1      error while parsing options.
228
229       2      problems with input file.
230
231       3      problems with output file.
232
233       4,5    desired seek position is unreachable.
234

SEE ALSO

236       uuencode(1), uudecode(1), patch(1)
237

WARNINGS

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

VERSION

243       This manual page documents xxd version 1.7
244

AUTHOR

246       (c) 1990-1997 by Juergen Weigert
247       <jnweiger@informatik.uni-erlangen.de>
248
249       Distribute freely and credit me,
250       make money and share with me,
251       lose money and don't ask me.
252
253       Manual page started by Tony Nugent
254       <tony@sctnugen.ppp.gu.edu.au> <T.Nugent@sct.gu.edu.au>
255       Small changes by Bram Moolenaar.  Edited by Juergen Weigert.
256
257Manual page for xxd               August 1996                           XXD(1)
Impressum