blob: 26d89e5659e72d522e1a730d85da00edad723e21 [file] [log] [blame]
Bram Moolenaar86ae7202015-07-10 19:31:35 +02001XXD(1) General Commands Manual XXD(1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
4
Bram Moolenaar071d4272004-06-13 20:20:40 +00005NAME
6 xxd - make a hexdump or do the reverse.
7
8SYNOPSIS
9 xxd -h[elp]
10 xxd [options] [infile [outfile]]
11 xxd -r[evert] [options] [infile [outfile]]
12
13DESCRIPTION
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000014 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-
Bram Moolenaar86ae7202015-07-10 19:31:35 +020017 safe' ASCII representation, but has the advantage of decoding to stan‐
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000018 dard output. Moreover, it can be used to perform binary file patching.
Bram Moolenaar071d4272004-06-13 20:20:40 +000019
20OPTIONS
Bram Moolenaar86ae7202015-07-10 19:31:35 +020021 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
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000023 outfile is given (or a `-' character is in its place), results are sent
24 to standard output.
Bram Moolenaar071d4272004-06-13 20:20:40 +000025
Bram Moolenaar86ae7202015-07-10 19:31:35 +020026 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.
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000029 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.
Bram Moolenaar071d4272004-06-13 20:20:40 +000031
Bram Moolenaar071d4272004-06-13 20:20:40 +000032 -a | -autoskip
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020033 Toggle autoskip: A single '*' replaces nul-lines. Default off.
Bram Moolenaar071d4272004-06-13 20:20:40 +000034
35 -b | -bits
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000036 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
Bram Moolenaar86ae7202015-07-10 19:31:35 +020039 in hexadecimal and followed by an ascii (or ebcdic) representa
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000040 tion. The command line switches -r, -p, -i do not work with this
41 mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +000042
43 -c cols | -cols cols
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020044 Format <cols> octets per line. Default 16 (-i: 12, -ps: 30, -b:
Erik Auerswaldc0a1d372022-01-14 11:58:48 +000045 6). Max 256. No maxmimum for -ps. With -ps, 0 results in one
46 long line of output.
Bram Moolenaar071d4272004-06-13 20:20:40 +000047
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020048 -C | -capitalize
49 Capitalize variable names in C include file style, when using
50 -i.
51
Bram Moolenaar071d4272004-06-13 20:20:40 +000052 -E | -EBCDIC
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000053 Change the character encoding in the righthand column from ASCII
54 to EBCDIC. This does not change the hexadecimal representation.
55 The option is meaningless in combinations with -r, -p or -i.
Bram Moolenaar071d4272004-06-13 20:20:40 +000056
Bram Moolenaar86ae7202015-07-10 19:31:35 +020057 -e Switch to little-endian hexdump. This option treats byte groups
58 as words in little-endian byte order. The default grouping of 4
59 bytes may be changed using -g. This option only applies to hex
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020060 dump, leaving the ASCII (or EBCDIC) representation unchanged.
Bram Moolenaar86ae7202015-07-10 19:31:35 +020061 The command line switches -r, -p, -i do not work with this mode.
62
Bram Moolenaar071d4272004-06-13 20:20:40 +000063 -g bytes | -groupsize bytes
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020064 Separate the output of every <bytes> bytes (two hex characters
Bram Moolenaar86ae7202015-07-10 19:31:35 +020065 or eight bit-digits each) by a whitespace. Specify -g 0 to sup
66 press grouping. <Bytes> defaults to 2 in normal mode, 4 in lit
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020067 tle-endian mode and 1 in bits mode. Grouping does not apply to
Bram Moolenaar86ae7202015-07-10 19:31:35 +020068 postscript or include style.
Bram Moolenaar071d4272004-06-13 20:20:40 +000069
70 -h | -help
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020071 Print a summary of available commands and exit. No hex dumping
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000072 is performed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000073
74 -i | -include
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020075 Output in C include file style. A complete static array defini
76 tion is written (named after the input file), unless xxd reads
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000077 from stdin.
Bram Moolenaar071d4272004-06-13 20:20:40 +000078
79 -l len | -len len
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020080 Stop after writing <len> octets.
Bram Moolenaar071d4272004-06-13 20:20:40 +000081
Bram Moolenaar86ae7202015-07-10 19:31:35 +020082 -o offset
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020083 Add <offset> to the displayed file position.
Bram Moolenaar86ae7202015-07-10 19:31:35 +020084
Bram Moolenaar071d4272004-06-13 20:20:40 +000085 -p | -ps | -postscript | -plain
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020086 Output in postscript continuous hexdump style. Also known as
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000087 plain hexdump style.
Bram Moolenaar071d4272004-06-13 20:20:40 +000088
89 -r | -revert
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020090 Reverse operation: convert (or patch) hexdump into binary. If
91 not writing to stdout, xxd writes into its output file without
Bram Moolenaar86ae7202015-07-10 19:31:35 +020092 truncating it. Use the combination -r -p to read plain hexadeci
93 mal dumps without line number information and without a particu
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020094 lar column layout. Additional Whitespace and line-breaks are
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000095 allowed anywhere.
Bram Moolenaar071d4272004-06-13 20:20:40 +000096
97 -seek offset
Bram Moolenaarc0761132005-03-18 20:30:32 +000098 When used after -r: revert with <offset> added to file positions
99 found in hexdump.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100
101 -s [+][-]seek
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200102 Start at <seek> bytes abs. (or rel.) infile offset. + indicates
103 that the seek is relative to the current stdin file position
Bram Moolenaar83e138c2007-05-05 18:27:07 +0000104 (meaningless when not reading from stdin). - indicates that the
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200105 seek should be that many characters from the end of the input
Bram Moolenaar83e138c2007-05-05 18:27:07 +0000106 (or if combined with +: before the current stdin file position).
107 Without -s option, xxd starts at the current file position.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200109 -u Use upper case hex letters. Default is lower case.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000110
111 -v | -version
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200112 Show version string.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113
Bram Moolenaar071d4272004-06-13 20:20:40 +0000114CAVEATS
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000115 xxd -r has some builtin magic while evaluating line number information.
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200116 If the output file is seekable, then the linenumbers at the start of
117 each hexdump line may be out of order, lines may be missing, or over
118 lapping. In these cases xxd will lseek(2) to the next position. If the
119 output file is not seekable, only gaps are allowed, which will be
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000120 filled by null-bytes.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000122 xxd -r never generates parse errors. Garbage is silently skipped.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000123
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200124 When editing hexdumps, please note that xxd -r skips everything on the
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000125 input line after reading enough columns of hexadecimal data (see option
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200126 -c). This also means, that changes to the printable ascii (or ebcdic)
127 columns are always ignored. Reverting a plain (or postscript) style
128 hexdump with xxd -r -p does not depend on the correct number of col
129 umns. Here anything that looks like a pair of hex-digits is inter
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000130 preted.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131
132 Note the difference between
133 % xxd -i file
134 and
135 % xxd -i < file
136
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200137 xxd -s +seek may be different from xxd -s seek, as lseek(2) is used to
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000138 "rewind" input. A '+' makes a difference if the input source is stdin,
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200139 and if stdin's file position is not at the start of the file by the
140 time xxd is started and given its input. The following examples may
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000141 help to clarify (or further confuse!)...
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200143 Rewind stdin before reading; needed because the `cat' has already read
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000144 to the end of stdin.
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000145 % sh -c "cat > plain_copy; xxd -s 0 > hex_copy" < file
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200147 Hexdump from file position 0x480 (=1024+128) onwards. The `+' sign
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000148 means "relative to the current position", thus the `128' adds to the 1k
149 where dd left off.
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200150 % sh -c "dd of=plain_snippet bs=1k count=1; xxd -s +128 > hex_snippet"
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000151 < file
Bram Moolenaar071d4272004-06-13 20:20:40 +0000152
153 Hexdump from file position 0x100 ( = 1024-768) on.
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000154 % sh -c "dd of=plain_snippet bs=1k count=1; xxd -s +-768 > hex_snippet"
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000155 < file
Bram Moolenaar071d4272004-06-13 20:20:40 +0000156
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200157 However, this is a rare situation and the use of `+' is rarely needed.
158 The author prefers to monitor the effect of xxd with strace(1) or
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000159 truss(1), whenever -s is used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000160
161EXAMPLES
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000162 Print everything but the first three lines (hex 0x30 bytes) of file.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000163 % xxd -s 0x30 file
164
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000165 Print 3 lines (hex 0x30 bytes) from the end of file.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000166 % xxd -s -0x30 file
167
Bram Moolenaar83e138c2007-05-05 18:27:07 +0000168 Print 120 bytes as continuous hexdump with 20 octets per line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000169 % xxd -l 120 -ps -c 20 xxd.1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000170 2e54482058584420312022417567757374203139
171 39362220224d616e75616c207061676520666f72
172 20787864220a2e5c220a2e5c222032317374204d
173 617920313939360a2e5c22204d616e2070616765
174 20617574686f723a0a2e5c2220202020546f6e79
175 204e7567656e74203c746f6e79407363746e7567
Bram Moolenaar071d4272004-06-13 20:20:40 +0000176
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000177 Hexdump the first 120 bytes of this man page with 12 octets per line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178 % xxd -l 120 -c 12 xxd.1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000179 0000000: 2e54 4820 5858 4420 3120 2241 .TH XXD 1 "A
180 000000c: 7567 7573 7420 3139 3936 2220 ugust 1996"
181 0000018: 224d 616e 7561 6c20 7061 6765 "Manual page
182 0000024: 2066 6f72 2078 7864 220a 2e5c for xxd"..\
183 0000030: 220a 2e5c 2220 3231 7374 204d "..\" 21st M
184 000003c: 6179 2031 3939 360a 2e5c 2220 ay 1996..\"
185 0000048: 4d61 6e20 7061 6765 2061 7574 Man page aut
186 0000054: 686f 723a 0a2e 5c22 2020 2020 hor:..\"
187 0000060: 546f 6e79 204e 7567 656e 7420 Tony Nugent
188 000006c: 3c74 6f6e 7940 7363 746e 7567 <tony@sctnug
Bram Moolenaar071d4272004-06-13 20:20:40 +0000189
190 Display just the date from the file xxd.1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000191 % xxd -s 0x36 -l 13 -c 13 xxd.1
192 0000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996
Bram Moolenaar071d4272004-06-13 20:20:40 +0000193
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000194 Copy input_file to output_file and prepend 100 bytes of value 0x00.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000195 % xxd input_file | xxd -r -s 100 > output_file
196
197 Patch the date in the file xxd.1
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000198 % echo "0000037: 3574 68" | xxd -r - xxd.1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000199 % xxd -s 0x36 -l 13 -c 13 xxd.1
200 0000036: 3235 7468 204d 6179 2031 3939 36 25th May 1996
Bram Moolenaar071d4272004-06-13 20:20:40 +0000201
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200202 Create a 65537 byte file with all bytes 0x00, except for the last one
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000203 which is 'A' (hex 0x41).
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000204 % echo "010000: 41" | xxd -r > file
Bram Moolenaar071d4272004-06-13 20:20:40 +0000205
206 Hexdump this file with autoskip.
207 % xxd -a -c 12 file
208 0000000: 0000 0000 0000 0000 0000 0000 ............
209 *
210 000fffc: 0000 0000 40 ....A
211
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200212 Create a 1 byte file containing a single 'A' character. The number
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000213 after '-r -s' adds to the linenumbers found in the file; in effect, the
214 leading bytes are suppressed.
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000215 % echo "010000: 41" | xxd -r -s -0x10000 > file
Bram Moolenaar071d4272004-06-13 20:20:40 +0000216
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000217 Use xxd as a filter within an editor such as vim(1) to hexdump a region
218 marked between `a' and `z'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000219 :'a,'z!xxd
220
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000221 Use xxd as a filter within an editor such as vim(1) to recover a binary
222 hexdump marked between `a' and `z'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000223 :'a,'z!xxd -r
224
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000225 Use xxd as a filter within an editor such as vim(1) to recover one line
226 of a hexdump. Move the cursor over the line and type:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000227 !!xxd -r
228
229 Read single characters from a serial line
230 % xxd -c1 < /dev/term/b &
231 % stty < /dev/term/b -echo -opost -isig -icanon min 1
232 % echo -n foo > /dev/term/b
233
Bram Moolenaar071d4272004-06-13 20:20:40 +0000234RETURN VALUES
235 The following error values are returned:
236
237 0 no errors encountered.
238
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000239 -1 operation not supported ( xxd -r -i still impossible).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000240
241 1 error while parsing options.
242
243 2 problems with input file.
244
245 3 problems with output file.
246
247 4,5 desired seek position is unreachable.
248
249SEE ALSO
250 uuencode(1), uudecode(1), patch(1)
251
252WARNINGS
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200253 The tools weirdness matches its creators brain. Use entirely at your
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000254 own risk. Copy files. Trace it. Become a wizard.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000255
256VERSION
257 This manual page documents xxd version 1.7
258
259AUTHOR
260 (c) 1990-1997 by Juergen Weigert
261 <jnweiger@informatik.uni-erlangen.de>
262
263 Distribute freely and credit me,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000264 make money and share with me,
265 lose money and don't ask me.
266
267 Manual page started by Tony Nugent
268 <tony@sctnugen.ppp.gu.edu.au> <T.Nugent@sct.gu.edu.au>
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000269 Small changes by Bram Moolenaar. Edited by Juergen Weigert.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000270
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000271Manual page for xxd August 1996 XXD(1)