blob: b0cb18378530227281a1b732c771f00979638220 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001.TH XXD 1 "August 1996" "Manual page for xxd"
2.\"
3.\" 21st May 1996
4.\" Man page author:
5.\" Tony Nugent <tony@sctnugen.ppp.gu.edu.au> <T.Nugent@sct.gu.edu.au>
6.\" Changes by Bram Moolenaar <Bram@vim.org>
7.SH NAME
8.I xxd
9\- make a hexdump or do the reverse.
10.SH SYNOPSIS
11.B xxd
12\-h[elp]
13.br
14.B xxd
15[options] [infile [outfile]]
16.br
17.B xxd
18\-r[evert] [options] [infile [outfile]]
19.SH DESCRIPTION
20.I xxd
21creates a hex dump of a given file or standard input.
22It can also convert a hex dump back to its original binary form.
23Like
Bram Moolenaar4317d9b2005-03-18 20:25:31 +000024.BR uuencode (1)
Bram Moolenaar071d4272004-06-13 20:20:40 +000025and
Bram Moolenaar4317d9b2005-03-18 20:25:31 +000026.BR uudecode (1)
Bram Moolenaar071d4272004-06-13 20:20:40 +000027it allows the transmission of binary data in a `mail-safe' ASCII representation,
28but has the advantage of decoding to standard output.
29Moreover, it can be used to perform binary file patching.
30.SH OPTIONS
31If no
32.I infile
33is given, standard input is read.
34If
35.I infile
36is specified as a
37.RB \` \- '
38character, then input is taken from standard input.
39If no
40.I outfile
41is given (or a
42.RB \` \- '
43character is in its place), results are sent to standard output.
44.PP
45Note that a "lazy" parser is used which does not check for more than the first
46option letter, unless the option is followed by a parameter.
47Spaces between a single option letter and its parameter are optional.
48Parameters to options can be specified in decimal, hexadecimal or octal
49notation.
50Thus
51.BR \-c8 ,
52.BR "\-c 8" ,
53.B \-c 010
54and
55.B \-cols 8
56are all equivalent.
57.PP
58.TP
59.IR \-a " | " \-autoskip
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020060Toggle autoskip: A single '*' replaces nul-lines. Default off.
Bram Moolenaar071d4272004-06-13 20:20:40 +000061.TP
62.IR \-b " | " \-bits
63Switch to bits (binary digits) dump, rather than hexdump.
64This option writes octets as eight digits "1"s and "0"s instead of a normal
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000065hexadecimal dump. Each line is preceded by a line number in hexadecimal and
Bram Moolenaar071d4272004-06-13 20:20:40 +000066followed by an ascii (or ebcdic) representation. The command line switches
67\-r, \-p, \-i do not work with this mode.
68.TP
69.IR "\-c cols " | " \-cols cols"
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020070Format
Bram Moolenaar071d4272004-06-13 20:20:40 +000071.RI < cols >
72octets per line. Default 16 (\-i: 12, \-ps: 30, \-b: 6). Max 256.
Erik Auerswaldc0a1d372022-01-14 11:58:48 +000073No maxmimum for \-ps. With \-ps, 0 results in one long line of output.
Bram Moolenaar071d4272004-06-13 20:20:40 +000074.TP
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020075.IR \-C " | " \-capitalize
76Capitalize variable names in C include file style, when using \-i.
77.TP
Bram Moolenaar071d4272004-06-13 20:20:40 +000078.IR \-E " | " \-EBCDIC
79Change the character encoding in the righthand column from ASCII to EBCDIC.
80This does not change the hexadecimal representation. The option is
81meaningless in combinations with \-r, \-p or \-i.
82.TP
Bram Moolenaar4dcdf292015-03-05 17:51:15 +010083.IR \-e
84Switch to little-endian hexdump.
85This option treats byte groups as words in little-endian byte order.
86The default grouping of 4 bytes may be changed using
87.RI "" \-g .
88This option only applies to hexdump, leaving the ASCII (or EBCDIC)
89representation unchanged.
90The command line switches
91\-r, \-p, \-i do not work with this mode.
92.TP
Bram Moolenaar071d4272004-06-13 20:20:40 +000093.IR "\-g bytes " | " \-groupsize bytes"
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020094Separate the output of every
Bram Moolenaar071d4272004-06-13 20:20:40 +000095.RI < bytes >
96bytes (two hex characters or eight bit-digits each) by a whitespace.
97Specify
98.I \-g 0
99to suppress grouping.
100.RI < Bytes "> defaults to " 2
Bram Moolenaar4dcdf292015-03-05 17:51:15 +0100101in normal mode, \fI4\fP in little-endian mode and \fI1\fP in bits mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102Grouping does not apply to postscript or include style.
103.TP
104.IR \-h " | " \-help
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200105Print a summary of available commands and exit. No hex dumping is performed.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106.TP
107.IR \-i " | " \-include
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200108Output in C include file style. A complete static array definition is written
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109(named after the input file), unless xxd reads from stdin.
110.TP
111.IR "\-l len " | " \-len len"
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200112Stop after writing
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113.RI < len >
114octets.
115.TP
David Gow83e11802022-06-29 20:24:49 +0100116.I "\-n name " | " \-name name"
117Override the variable name output when \-i is used. The array is named
118\fIname\fP and the length is named \fIname\fP_len.
119.TP
Bram Moolenaar4dcdf292015-03-05 17:51:15 +0100120.I \-o offset
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200121Add
Bram Moolenaar4dcdf292015-03-05 17:51:15 +0100122.RI < offset >
123to the displayed file position.
124.TP
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125.IR \-p " | " \-ps " | " \-postscript " | " \-plain
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200126Output in postscript continuous hexdump style. Also known as plain hexdump
Bram Moolenaar071d4272004-06-13 20:20:40 +0000127style.
128.TP
129.IR \-r " | " \-revert
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200130Reverse operation: convert (or patch) hexdump into binary.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131If not writing to stdout, xxd writes into its output file without truncating
132it. Use the combination
133.I \-r \-p
134to read plain hexadecimal dumps without line number information and without a
135particular column layout. Additional Whitespace and line-breaks are allowed
136anywhere.
137.TP
138.I \-seek offset
139When used after
Bram Moolenaar4317d9b2005-03-18 20:25:31 +0000140.IR \-r :
141revert with
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142.RI < offset >
143added to file positions found in hexdump.
144.TP
Bram Moolenaar4317d9b2005-03-18 20:25:31 +0000145.I \-s [+][\-]seek
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200146Start at
Bram Moolenaar071d4272004-06-13 20:20:40 +0000147.RI < seek >
148bytes abs. (or rel.) infile offset.
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000149\fI+ \fRindicates that the seek is relative to the current stdin file position
Bram Moolenaar071d4272004-06-13 20:20:40 +0000150(meaningless when not reading from stdin). \fI\- \fRindicates that the seek
151should be that many characters from the end of the input (or if combined with
Bram Moolenaar4317d9b2005-03-18 20:25:31 +0000152\fI+\fR: before the current stdin file position).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000153Without \-s option, xxd starts at the current file position.
154.TP
155.I \-u
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200156Use upper case hex letters. Default is lower case.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157.TP
158.IR \-v " | " \-version
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200159Show version string.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000160.SH CAVEATS
161.PP
162.I xxd \-r
163has some builtin magic while evaluating line number information.
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000164If the output file is seekable, then the linenumbers at the start of each
Bram Moolenaar071d4272004-06-13 20:20:40 +0000165hexdump line may be out of order, lines may be missing, or overlapping. In
166these cases xxd will lseek(2) to the next position. If the output file is not
167seekable, only gaps are allowed, which will be filled by null-bytes.
168.PP
169.I xxd \-r
170never generates parse errors. Garbage is silently skipped.
171.PP
172When editing hexdumps, please note that
173.I xxd \-r
174skips everything on the input line after reading enough columns of hexadecimal
175data (see option \-c). This also means, that changes to the printable ascii (or
176ebcdic) columns are always ignored. Reverting a plain (or postscript) style
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000177hexdump 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.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178.PP
179Note the difference between
180.br
181\fI% xxd \-i file\fR
182.br
183and
184.br
Bram Moolenaar4317d9b2005-03-18 20:25:31 +0000185\fI% xxd \-i < file\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000186.PP
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000187.I xxd \-s +seek
Bram Moolenaar071d4272004-06-13 20:20:40 +0000188may be different from
Bram Moolenaar4317d9b2005-03-18 20:25:31 +0000189.IR "xxd \-s seek" ,
190as lseek(2) is used to "rewind" input. A '+'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000191makes a difference if the input source is stdin, and if stdin's file position
192is not at the start of the file by the time xxd is started and given its input.
193The following examples may help to clarify (or further confuse!)...
194.PP
195Rewind stdin before reading; needed because the `cat' has already read to the
196end of stdin.
197.br
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000198\fI% sh \-c "cat > plain_copy; xxd \-s 0 > hex_copy" < file\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000199.PP
200Hexdump from file position 0x480 (=1024+128) onwards.
201The `+' sign means "relative to the current position", thus the `128' adds to
202the 1k where dd left off.
203.br
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000204\fI% sh \-c "dd of=plain_snippet bs=1k count=1; xxd \-s +128 > hex_snippet" < file\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000205.PP
Bram Moolenaar4317d9b2005-03-18 20:25:31 +0000206Hexdump from file position 0x100 ( = 1024\-768) on.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000207.br
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000208\fI% sh \-c "dd of=plain_snippet bs=1k count=1; xxd \-s +\-768 > hex_snippet" < file\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000209.PP
210However, this is a rare situation and the use of `+' is rarely needed.
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000211The author prefers to monitor the effect of xxd with strace(1) or truss(1), whenever \-s is used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000212.SH EXAMPLES
213.PP
214.br
215Print everything but the first three lines (hex 0x30 bytes) of
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000216.BR file .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000217.br
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000218\fI% xxd \-s 0x30 file\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000219.PP
220.br
221Print 3 lines (hex 0x30 bytes) from the end of
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000222.BR file .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000223.br
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000224\fI% xxd \-s \-0x30 file\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000225.PP
226.br
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000227Print 120 bytes as continuous hexdump with 20 octets per line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000228.br
229\fI% xxd \-l 120 \-ps \-c 20 xxd.1\fR
230.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002312e54482058584420312022417567757374203139
Bram Moolenaar071d4272004-06-13 20:20:40 +0000232.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000023339362220224d616e75616c207061676520666f72
Bram Moolenaar071d4272004-06-13 20:20:40 +0000234.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000023520787864220a2e5c220a2e5c222032317374204d
Bram Moolenaar071d4272004-06-13 20:20:40 +0000236.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000237617920313939360a2e5c22204d616e2070616765
Bram Moolenaar071d4272004-06-13 20:20:40 +0000238.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000023920617574686f723a0a2e5c2220202020546f6e79
Bram Moolenaar071d4272004-06-13 20:20:40 +0000240.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000241204e7567656e74203c746f6e79407363746e7567
Bram Moolenaar071d4272004-06-13 20:20:40 +0000242.br
243
244.br
245Hexdump the first 120 bytes of this man page with 12 octets per line.
246.br
247\fI% xxd \-l 120 \-c 12 xxd.1\fR
248.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002490000000: 2e54 4820 5858 4420 3120 2241 .TH XXD 1 "A
Bram Moolenaar071d4272004-06-13 20:20:40 +0000250.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000251000000c: 7567 7573 7420 3139 3936 2220 ugust 1996"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000252.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002530000018: 224d 616e 7561 6c20 7061 6765 "Manual page
Bram Moolenaar071d4272004-06-13 20:20:40 +0000254.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002550000024: 2066 6f72 2078 7864 220a 2e5c for xxd"..\\
Bram Moolenaar071d4272004-06-13 20:20:40 +0000256.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002570000030: 220a 2e5c 2220 3231 7374 204d "..\\" 21st M
Bram Moolenaar071d4272004-06-13 20:20:40 +0000258.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000259000003c: 6179 2031 3939 360a 2e5c 2220 ay 1996..\\"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000260.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002610000048: 4d61 6e20 7061 6765 2061 7574 Man page aut
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002630000054: 686f 723a 0a2e 5c22 2020 2020 hor:..\\"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000264.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002650000060: 546f 6e79 204e 7567 656e 7420 Tony Nugent
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000267000006c: 3c74 6f6e 7940 7363 746e 7567 <tony@sctnug
Bram Moolenaar071d4272004-06-13 20:20:40 +0000268.PP
269.br
270Display just the date from the file xxd.1
271.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000272\fI% xxd \-s 0x36 \-l 13 \-c 13 xxd.1\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002740000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275.PP
276.br
277Copy
278.B input_file
279to
280.B output_file
281and prepend 100 bytes of value 0x00.
282.br
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000283\fI% xxd input_file | xxd \-r \-s 100 > output_file\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000284.br
285
286.br
287Patch the date in the file xxd.1
288.br
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000289\fI% echo "0000037: 3574 68" | xxd \-r \- xxd.1\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000291\fI% xxd \-s 0x36 \-l 13 \-c 13 xxd.1\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000292.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002930000036: 3235 7468 204d 6179 2031 3939 36 25th May 1996
Bram Moolenaar071d4272004-06-13 20:20:40 +0000294.PP
295.br
296Create a 65537 byte file with all bytes 0x00,
297except for the last one which is 'A' (hex 0x41).
298.br
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000299\fI% echo "010000: 41" | xxd \-r > file\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000300.PP
301.br
302Hexdump this file with autoskip.
303.br
304\fI% xxd \-a \-c 12 file\fR
305.br
3060000000: 0000 0000 0000 0000 0000 0000 ............
307.br
308*
309.br
310000fffc: 0000 0000 40 ....A
311.PP
312Create a 1 byte file containing a single 'A' character.
313The number after '\-r \-s' adds to the linenumbers found in the file;
314in effect, the leading bytes are suppressed.
315.br
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000316\fI% echo "010000: 41" | xxd \-r \-s \-0x10000 > file\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317.PP
318Use xxd as a filter within an editor such as
319.B vim(1)
320to hexdump a region marked between `a' and `z'.
321.br
322\fI:'a,'z!xxd\fR
323.PP
324Use xxd as a filter within an editor such as
325.B vim(1)
326to recover a binary hexdump marked between `a' and `z'.
327.br
328\fI:'a,'z!xxd \-r\fR
329.PP
330Use xxd as a filter within an editor such as
331.B vim(1)
332to recover one line of a hexdump. Move the cursor over the line and type:
333.br
334\fI!!xxd \-r\fR
335.PP
336Read single characters from a serial line
337.br
338\fI% xxd \-c1 < /dev/term/b &\fR
339.br
340\fI% stty < /dev/term/b \-echo \-opost \-isig \-icanon min 1\fR
341.br
342\fI% echo \-n foo > /dev/term/b\fR
343.PP
344.SH "RETURN VALUES"
345The following error values are returned:
346.TP
3470
348no errors encountered.
349.TP
350\-1
351operation not supported (
352.I xxd \-r \-i
353still impossible).
354.TP
3551
356error while parsing options.
357.TP
3582
359problems with input file.
360.TP
3613
362problems with output file.
363.TP
3644,5
365desired seek position is unreachable.
366.SH "SEE ALSO"
367uuencode(1), uudecode(1), patch(1)
368.br
369.SH WARNINGS
370The tools weirdness matches its creators brain.
371Use entirely at your own risk. Copy files. Trace it. Become a wizard.
372.br
373.SH VERSION
374This manual page documents xxd version 1.7
375.SH AUTHOR
376.br
377(c) 1990-1997 by Juergen Weigert
378.br
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000379<jnweiger@informatik.uni\-erlangen.de>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380.LP
381Distribute freely and credit me,
382.br
383make money and share with me,
384.br
385lose money and don't ask me.
386.PP
387Manual page started by Tony Nugent
388.br
389<tony@sctnugen.ppp.gu.edu.au> <T.Nugent@sct.gu.edu.au>
390.br
391Small changes by Bram Moolenaar.
392Edited by Juergen Weigert.
393.PP