blob: ccaeb2279d542f1bc10cf5cbfa5a54ff0b2ce8ad [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
24.BR uuencode(1)
25and
26.BR uudecode(1)
27it 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
60toggle autoskip: A single '*' replaces nul-lines. Default off.
61.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 Moolenaar071d4272004-06-13 20:20:40 +000070format
71.RI < cols >
72octets per line. Default 16 (\-i: 12, \-ps: 30, \-b: 6). Max 256.
73.TP
74.IR \-E " | " \-EBCDIC
75Change the character encoding in the righthand column from ASCII to EBCDIC.
76This does not change the hexadecimal representation. The option is
77meaningless in combinations with \-r, \-p or \-i.
78.TP
79.IR "\-g bytes " | " \-groupsize bytes"
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000080separate the output of every
Bram Moolenaar071d4272004-06-13 20:20:40 +000081.RI < bytes >
82bytes (two hex characters or eight bit-digits each) by a whitespace.
83Specify
84.I \-g 0
85to suppress grouping.
86.RI < Bytes "> defaults to " 2
87in normal mode and \fI1\fP in bits mode.
88Grouping does not apply to postscript or include style.
89.TP
90.IR \-h " | " \-help
91print a summary of available commands and exit. No hex dumping is performed.
92.TP
93.IR \-i " | " \-include
94output in C include file style. A complete static array definition is written
95(named after the input file), unless xxd reads from stdin.
96.TP
97.IR "\-l len " | " \-len len"
98stop after writing
99.RI < len >
100octets.
101.TP
102.IR \-p " | " \-ps " | " \-postscript " | " \-plain
103output in postscript continuous hexdump style. Also known as plain hexdump
104style.
105.TP
106.IR \-r " | " \-revert
107reverse operation: convert (or patch) hexdump into binary.
108If not writing to stdout, xxd writes into its output file without truncating
109it. Use the combination
110.I \-r \-p
111to read plain hexadecimal dumps without line number information and without a
112particular column layout. Additional Whitespace and line-breaks are allowed
113anywhere.
114.TP
115.I \-seek offset
116When used after
117.I \-r
118: revert with
119.RI < offset >
120added to file positions found in hexdump.
121.TP
122.I \-s [\+][\-]seek
123start at
124.RI < seek >
125bytes abs. (or rel.) infile offset.
126\fI\+ \fRindicates that the seek is relative to the current stdin file position
127(meaningless when not reading from stdin). \fI\- \fRindicates that the seek
128should be that many characters from the end of the input (or if combined with
129\fI \+ \fR: before the current stdin file position).
130Without \-s option, xxd starts at the current file position.
131.TP
132.I \-u
133use upper case hex letters. Default is lower case.
134.TP
135.IR \-v " | " \-version
136show version string.
137.SH CAVEATS
138.PP
139.I xxd \-r
140has some builtin magic while evaluating line number information.
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000141If the output file is seekable, then the linenumbers at the start of each
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142hexdump line may be out of order, lines may be missing, or overlapping. In
143these cases xxd will lseek(2) to the next position. If the output file is not
144seekable, only gaps are allowed, which will be filled by null-bytes.
145.PP
146.I xxd \-r
147never generates parse errors. Garbage is silently skipped.
148.PP
149When editing hexdumps, please note that
150.I xxd \-r
151skips everything on the input line after reading enough columns of hexadecimal
152data (see option \-c). This also means, that changes to the printable ascii (or
153ebcdic) columns are always ignored. Reverting a plain (or postscript) style
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000154hexdump 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 +0000155.PP
156Note the difference between
157.br
158\fI% xxd \-i file\fR
159.br
160and
161.br
162\fI% xxd \-i \< file\fR
163.PP
164.I xxd \-s \+seek
165may be different from
166.I xxd \-s seek
167, as lseek(2) is used to "rewind" input. A '+'
168makes a difference if the input source is stdin, and if stdin's file position
169is not at the start of the file by the time xxd is started and given its input.
170The following examples may help to clarify (or further confuse!)...
171.PP
172Rewind stdin before reading; needed because the `cat' has already read to the
173end of stdin.
174.br
175\fI% sh \-c 'cat > plain_copy; xxd \-s 0 > hex_copy' < file
176.PP
177Hexdump from file position 0x480 (=1024+128) onwards.
178The `+' sign means "relative to the current position", thus the `128' adds to
179the 1k where dd left off.
180.br
181\fI% sh \-c 'dd of=plain_snippet bs=1k count=1; xxd \-s +128 > hex_snippet' < file
182.PP
183Hexdump from file position 0x100 ( = 1024-768) on.
184.br
185\fI% sh \-c 'dd of=plain_snippet bs=1k count=1; xxd \-s +-768 > hex_snippet' < file
186.PP
187However, this is a rare situation and the use of `+' is rarely needed.
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000188The 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 +0000189.SH EXAMPLES
190.PP
191.br
192Print everything but the first three lines (hex 0x30 bytes) of
193.B file
194\.
195.br
196\fI% xxd \-s 0x30 file
197.PP
198.br
199Print 3 lines (hex 0x30 bytes) from the end of
200.B file
201\.
202.br
203\fI% xxd \-s \-0x30 file
204.PP
205.br
206Print 120 bytes as continuous hexdump with 40 octets per line.
207.br
208\fI% xxd \-l 120 \-ps \-c 20 xxd.1\fR
209.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002102e54482058584420312022417567757374203139
Bram Moolenaar071d4272004-06-13 20:20:40 +0000211.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000021239362220224d616e75616c207061676520666f72
Bram Moolenaar071d4272004-06-13 20:20:40 +0000213.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000021420787864220a2e5c220a2e5c222032317374204d
Bram Moolenaar071d4272004-06-13 20:20:40 +0000215.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000216617920313939360a2e5c22204d616e2070616765
Bram Moolenaar071d4272004-06-13 20:20:40 +0000217.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000021820617574686f723a0a2e5c2220202020546f6e79
Bram Moolenaar071d4272004-06-13 20:20:40 +0000219.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000220204e7567656e74203c746f6e79407363746e7567
Bram Moolenaar071d4272004-06-13 20:20:40 +0000221.br
222
223.br
224Hexdump the first 120 bytes of this man page with 12 octets per line.
225.br
226\fI% xxd \-l 120 \-c 12 xxd.1\fR
227.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002280000000: 2e54 4820 5858 4420 3120 2241 .TH XXD 1 "A
Bram Moolenaar071d4272004-06-13 20:20:40 +0000229.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000230000000c: 7567 7573 7420 3139 3936 2220 ugust 1996"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000231.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002320000018: 224d 616e 7561 6c20 7061 6765 "Manual page
Bram Moolenaar071d4272004-06-13 20:20:40 +0000233.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002340000024: 2066 6f72 2078 7864 220a 2e5c for xxd"..\\
Bram Moolenaar071d4272004-06-13 20:20:40 +0000235.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002360000030: 220a 2e5c 2220 3231 7374 204d "..\\" 21st M
Bram Moolenaar071d4272004-06-13 20:20:40 +0000237.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000238000003c: 6179 2031 3939 360a 2e5c 2220 ay 1996..\\"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000239.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002400000048: 4d61 6e20 7061 6765 2061 7574 Man page aut
Bram Moolenaar071d4272004-06-13 20:20:40 +0000241.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002420000054: 686f 723a 0a2e 5c22 2020 2020 hor:..\\"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000243.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002440000060: 546f 6e79 204e 7567 656e 7420 Tony Nugent
Bram Moolenaar071d4272004-06-13 20:20:40 +0000245.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000246000006c: 3c74 6f6e 7940 7363 746e 7567 <tony@sctnug
Bram Moolenaar071d4272004-06-13 20:20:40 +0000247.PP
248.br
249Display just the date from the file xxd.1
250.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000251\fI% xxd \-s 0x36 \-l 13 \-c 13 xxd.1\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000252.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002530000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996
Bram Moolenaar071d4272004-06-13 20:20:40 +0000254.PP
255.br
256Copy
257.B input_file
258to
259.B output_file
260and prepend 100 bytes of value 0x00.
261.br
262\fI% xxd input_file | xxd \-r \-s 100 \> output_file\fR
263.br
264
265.br
266Patch the date in the file xxd.1
267.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000268\fI% echo '0000037: 3574 68' | xxd \-r \- xxd.1\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000270\fI% xxd \-s 0x36 \-l 13 \-c 13 xxd.1\fR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000271.br
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002720000036: 3235 7468 204d 6179 2031 3939 36 25th May 1996
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273.PP
274.br
275Create a 65537 byte file with all bytes 0x00,
276except for the last one which is 'A' (hex 0x41).
277.br
278\fI% echo '010000: 41' | xxd \-r \> file\fR
279.PP
280.br
281Hexdump this file with autoskip.
282.br
283\fI% xxd \-a \-c 12 file\fR
284.br
2850000000: 0000 0000 0000 0000 0000 0000 ............
286.br
287*
288.br
289000fffc: 0000 0000 40 ....A
290.PP
291Create a 1 byte file containing a single 'A' character.
292The number after '\-r \-s' adds to the linenumbers found in the file;
293in effect, the leading bytes are suppressed.
294.br
295\fI% echo '010000: 41' | xxd \-r \-s \-0x10000 \> file\fR
296.PP
297Use xxd as a filter within an editor such as
298.B vim(1)
299to hexdump a region marked between `a' and `z'.
300.br
301\fI:'a,'z!xxd\fR
302.PP
303Use xxd as a filter within an editor such as
304.B vim(1)
305to recover a binary hexdump marked between `a' and `z'.
306.br
307\fI:'a,'z!xxd \-r\fR
308.PP
309Use xxd as a filter within an editor such as
310.B vim(1)
311to recover one line of a hexdump. Move the cursor over the line and type:
312.br
313\fI!!xxd \-r\fR
314.PP
315Read single characters from a serial line
316.br
317\fI% xxd \-c1 < /dev/term/b &\fR
318.br
319\fI% stty < /dev/term/b \-echo \-opost \-isig \-icanon min 1\fR
320.br
321\fI% echo \-n foo > /dev/term/b\fR
322.PP
323.SH "RETURN VALUES"
324The following error values are returned:
325.TP
3260
327no errors encountered.
328.TP
329\-1
330operation not supported (
331.I xxd \-r \-i
332still impossible).
333.TP
3341
335error while parsing options.
336.TP
3372
338problems with input file.
339.TP
3403
341problems with output file.
342.TP
3434,5
344desired seek position is unreachable.
345.SH "SEE ALSO"
346uuencode(1), uudecode(1), patch(1)
347.br
348.SH WARNINGS
349The tools weirdness matches its creators brain.
350Use entirely at your own risk. Copy files. Trace it. Become a wizard.
351.br
352.SH VERSION
353This manual page documents xxd version 1.7
354.SH AUTHOR
355.br
356(c) 1990-1997 by Juergen Weigert
357.br
358<jnweiger@informatik.uni-erlangen.de>
359.LP
360Distribute freely and credit me,
361.br
362make money and share with me,
363.br
364lose money and don't ask me.
365.PP
366Manual page started by Tony Nugent
367.br
368<tony@sctnugen.ppp.gu.edu.au> <T.Nugent@sct.gu.edu.au>
369.br
370Small changes by Bram Moolenaar.
371Edited by Juergen Weigert.
372.PP