blob: fba0521d6327dc53e73c77f82b6ad54a4277cca3 [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
65hexacecimal dump. Each line is preceded by a line number in hexadecimal and
66followed 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"
70.IR "\-c cols " | " \-cols cols"
71format
72.RI < cols >
73octets per line. Default 16 (\-i: 12, \-ps: 30, \-b: 6). Max 256.
74.TP
75.IR \-E " | " \-EBCDIC
76Change the character encoding in the righthand column from ASCII to EBCDIC.
77This does not change the hexadecimal representation. The option is
78meaningless in combinations with \-r, \-p or \-i.
79.TP
80.IR "\-g bytes " | " \-groupsize bytes"
81seperate the output of every
82.RI < bytes >
83bytes (two hex characters or eight bit-digits each) by a whitespace.
84Specify
85.I \-g 0
86to suppress grouping.
87.RI < Bytes "> defaults to " 2
88in normal mode and \fI1\fP in bits mode.
89Grouping does not apply to postscript or include style.
90.TP
91.IR \-h " | " \-help
92print a summary of available commands and exit. No hex dumping is performed.
93.TP
94.IR \-i " | " \-include
95output in C include file style. A complete static array definition is written
96(named after the input file), unless xxd reads from stdin.
97.TP
98.IR "\-l len " | " \-len len"
99stop after writing
100.RI < len >
101octets.
102.TP
103.IR \-p " | " \-ps " | " \-postscript " | " \-plain
104output in postscript continuous hexdump style. Also known as plain hexdump
105style.
106.TP
107.IR \-r " | " \-revert
108reverse operation: convert (or patch) hexdump into binary.
109If not writing to stdout, xxd writes into its output file without truncating
110it. Use the combination
111.I \-r \-p
112to read plain hexadecimal dumps without line number information and without a
113particular column layout. Additional Whitespace and line-breaks are allowed
114anywhere.
115.TP
116.I \-seek offset
117When used after
118.I \-r
119: revert with
120.RI < offset >
121added to file positions found in hexdump.
122.TP
123.I \-s [\+][\-]seek
124start at
125.RI < seek >
126bytes abs. (or rel.) infile offset.
127\fI\+ \fRindicates that the seek is relative to the current stdin file position
128(meaningless when not reading from stdin). \fI\- \fRindicates that the seek
129should be that many characters from the end of the input (or if combined with
130\fI \+ \fR: before the current stdin file position).
131Without \-s option, xxd starts at the current file position.
132.TP
133.I \-u
134use upper case hex letters. Default is lower case.
135.TP
136.IR \-v " | " \-version
137show version string.
138.SH CAVEATS
139.PP
140.I xxd \-r
141has some builtin magic while evaluating line number information.
142If the ouput file is seekable, then the linenumbers at the start of each
143hexdump line may be out of order, lines may be missing, or overlapping. In
144these cases xxd will lseek(2) to the next position. If the output file is not
145seekable, only gaps are allowed, which will be filled by null-bytes.
146.PP
147.I xxd \-r
148never generates parse errors. Garbage is silently skipped.
149.PP
150When editing hexdumps, please note that
151.I xxd \-r
152skips everything on the input line after reading enough columns of hexadecimal
153data (see option \-c). This also means, that changes to the printable ascii (or
154ebcdic) columns are always ignored. Reverting a plain (or postscript) style
155hexdump with xxd \-r \-p does not depend on the correct number of columns. Here an thing that looks like a pair of hex-digits is interpreted.
156.PP
157Note the difference between
158.br
159\fI% xxd \-i file\fR
160.br
161and
162.br
163\fI% xxd \-i \< file\fR
164.PP
165.I xxd \-s \+seek
166may be different from
167.I xxd \-s seek
168, as lseek(2) is used to "rewind" input. A '+'
169makes a difference if the input source is stdin, and if stdin's file position
170is not at the start of the file by the time xxd is started and given its input.
171The following examples may help to clarify (or further confuse!)...
172.PP
173Rewind stdin before reading; needed because the `cat' has already read to the
174end of stdin.
175.br
176\fI% sh \-c 'cat > plain_copy; xxd \-s 0 > hex_copy' < file
177.PP
178Hexdump from file position 0x480 (=1024+128) onwards.
179The `+' sign means "relative to the current position", thus the `128' adds to
180the 1k where dd left off.
181.br
182\fI% sh \-c 'dd of=plain_snippet bs=1k count=1; xxd \-s +128 > hex_snippet' < file
183.PP
184Hexdump from file position 0x100 ( = 1024-768) on.
185.br
186\fI% sh \-c 'dd of=plain_snippet bs=1k count=1; xxd \-s +-768 > hex_snippet' < file
187.PP
188However, this is a rare situation and the use of `+' is rarely needed.
189the author prefers to monitor the effect of xxd with strace(1) or truss(1), whenever \-s is used.
190.SH EXAMPLES
191.PP
192.br
193Print everything but the first three lines (hex 0x30 bytes) of
194.B file
195\.
196.br
197\fI% xxd \-s 0x30 file
198.PP
199.br
200Print 3 lines (hex 0x30 bytes) from the end of
201.B file
202\.
203.br
204\fI% xxd \-s \-0x30 file
205.PP
206.br
207Print 120 bytes as continuous hexdump with 40 octets per line.
208.br
209\fI% xxd \-l 120 \-ps \-c 20 xxd.1\fR
210.br
2112e544820585844203120224d616e75616c207061
212.br
213676520666f7220787864220a2e5c220a2e5c2220
214.br
21532317374204d617920313939360a2e5c22204d61
216.br
2176e207061676520617574686f723a0a2e5c222020
218.br
2192020546f6e79204e7567656e74203c746f6e7940
220.br
2217363746e7567656e2e7070702e67752e6564752e
222.br
223
224.br
225Hexdump the first 120 bytes of this man page with 12 octets per line.
226.br
227\fI% xxd \-l 120 \-c 12 xxd.1\fR
228.br
2290000000: 2e54 4820 5858 4420 3120 224d .TH XXD 1 "M
230.br
231000000c: 616e 7561 6c20 7061 6765 2066 anual page f
232.br
2330000018: 6f72 2078 7864 220a 2e5c 220a or xxd"..\\".
234.br
2350000024: 2e5c 2220 3231 7374 204d 6179 .\\" 21st May
236.br
2370000030: 2031 3939 360a 2e5c 2220 4d61 1996..\\" Ma
238.br
239000003c: 6e20 7061 6765 2061 7574 686f n page autho
240.br
2410000048: 723a 0a2e 5c22 2020 2020 546f r:..\\" To
242.br
2430000054: 6e79 204e 7567 656e 7420 3c74 ny Nugent <t
244.br
2450000060: 6f6e 7940 7363 746e 7567 656e ony@sctnugen
246.br
247000006c: 2e70 7070 2e67 752e 6564 752e .ppp.gu.edu.
248.PP
249.br
250Display just the date from the file xxd.1
251.br
252\fI% xxd \-s 0x28 \-l 12 \-c 12 xxd.1\fR
253.br
2540000028: 3231 7374 204d 6179 2031 3939 21st May 199
255.PP
256.br
257Copy
258.B input_file
259to
260.B output_file
261and prepend 100 bytes of value 0x00.
262.br
263\fI% xxd input_file | xxd \-r \-s 100 \> output_file\fR
264.br
265
266.br
267Patch the date in the file xxd.1
268.br
269\fI% echo '0000029: 3574 68' | xxd \-r \- xxd.1\fR
270.br
271\fI% xxd \-s 0x28 \-l 12 \-c 12 xxd.1\fR
272.br
2730000028: 3235 7468 204d 6179 2031 3939 25th May 199
274.PP
275.br
276Create a 65537 byte file with all bytes 0x00,
277except for the last one which is 'A' (hex 0x41).
278.br
279\fI% echo '010000: 41' | xxd \-r \> file\fR
280.PP
281.br
282Hexdump this file with autoskip.
283.br
284\fI% xxd \-a \-c 12 file\fR
285.br
2860000000: 0000 0000 0000 0000 0000 0000 ............
287.br
288*
289.br
290000fffc: 0000 0000 40 ....A
291.PP
292Create a 1 byte file containing a single 'A' character.
293The number after '\-r \-s' adds to the linenumbers found in the file;
294in effect, the leading bytes are suppressed.
295.br
296\fI% echo '010000: 41' | xxd \-r \-s \-0x10000 \> file\fR
297.PP
298Use xxd as a filter within an editor such as
299.B vim(1)
300to hexdump a region marked between `a' and `z'.
301.br
302\fI:'a,'z!xxd\fR
303.PP
304Use xxd as a filter within an editor such as
305.B vim(1)
306to recover a binary hexdump marked between `a' and `z'.
307.br
308\fI:'a,'z!xxd \-r\fR
309.PP
310Use xxd as a filter within an editor such as
311.B vim(1)
312to recover one line of a hexdump. Move the cursor over the line and type:
313.br
314\fI!!xxd \-r\fR
315.PP
316Read single characters from a serial line
317.br
318\fI% xxd \-c1 < /dev/term/b &\fR
319.br
320\fI% stty < /dev/term/b \-echo \-opost \-isig \-icanon min 1\fR
321.br
322\fI% echo \-n foo > /dev/term/b\fR
323.PP
324.SH "RETURN VALUES"
325The following error values are returned:
326.TP
3270
328no errors encountered.
329.TP
330\-1
331operation not supported (
332.I xxd \-r \-i
333still impossible).
334.TP
3351
336error while parsing options.
337.TP
3382
339problems with input file.
340.TP
3413
342problems with output file.
343.TP
3444,5
345desired seek position is unreachable.
346.SH "SEE ALSO"
347uuencode(1), uudecode(1), patch(1)
348.br
349.SH WARNINGS
350The tools weirdness matches its creators brain.
351Use entirely at your own risk. Copy files. Trace it. Become a wizard.
352.br
353.SH VERSION
354This manual page documents xxd version 1.7
355.SH AUTHOR
356.br
357(c) 1990-1997 by Juergen Weigert
358.br
359<jnweiger@informatik.uni-erlangen.de>
360.LP
361Distribute freely and credit me,
362.br
363make money and share with me,
364.br
365lose money and don't ask me.
366.PP
367Manual page started by Tony Nugent
368.br
369<tony@sctnugen.ppp.gu.edu.au> <T.Nugent@sct.gu.edu.au>
370.br
371Small changes by Bram Moolenaar.
372Edited by Juergen Weigert.
373.PP