blob: 1251591f2fbe09e552dd79b4c91f8298b9e27d6e [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
Christian Brabandte845b382023-09-27 23:33:39 +02006 xxd - make a hex dump or do the reverse.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007
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
Christian Brabandte845b382023-09-27 23:33:39 +020033 Toggle autoskip: A single '*' replaces NUL-lines. Default off.
Bram Moolenaar071d4272004-06-13 20:20:40 +000034
35 -b | -bits
Christian Brabandte845b382023-09-27 23:33:39 +020036 Switch to bits (binary digits) dump, rather than hex dump. This
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000037 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
Christian Brabandte845b382023-09-27 23:33:39 +020039 in hexadecimal and followed by an ASCII (or EBCDIC) representa
tristhaus85f45212023-10-06 19:51:13 +020040 tion. The command line switches -p, -i do not work with this
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000041 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:
Christian Brabandte845b382023-09-27 23:33:39 +020045 6). Max 256. No maximum for -ps. With -ps, 0 results in one
Erik Auerswaldc0a1d372022-01-14 11:58:48 +000046 long line of output.
Bram Moolenaar071d4272004-06-13 20:20:40 +000047
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020048 -C | -capitalize
Bram Moolenaar0d878b92022-07-01 18:45:04 +010049 Capitalize variable names in C include file style, when using
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020050 -i.
51
Lennard Hofmann67797192024-05-10 14:17:26 +020052 -d show offset in decimal instead of hex.
53
Bram Moolenaar071d4272004-06-13 20:20:40 +000054 -E | -EBCDIC
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000055 Change the character encoding in the righthand column from ASCII
56 to EBCDIC. This does not change the hexadecimal representation.
57 The option is meaningless in combinations with -r, -p or -i.
Bram Moolenaar071d4272004-06-13 20:20:40 +000058
Christian Brabandte845b382023-09-27 23:33:39 +020059 -e Switch to little-endian hex dump. This option treats byte
60 groups as words in little-endian byte order. The default group
61 ing of 4 bytes may be changed using -g. This option only ap
62 plies to the hex dump, leaving the ASCII (or EBCDIC) representa
63 tion unchanged. The command line switches -r, -p, -i do not
64 work with this mode.
Bram Moolenaar86ae7202015-07-10 19:31:35 +020065
Bram Moolenaar071d4272004-06-13 20:20:40 +000066 -g bytes | -groupsize bytes
Christian Brabandte845b382023-09-27 23:33:39 +020067 Separate the output of every <bytes> bytes (two hex characters
68 or eight bit digits each) by a whitespace. Specify -g 0 to sup
Bram Moolenaar86ae7202015-07-10 19:31:35 +020069 press grouping. <Bytes> defaults to 2 in normal mode, 4 in lit
Christian Brabandte845b382023-09-27 23:33:39 +020070 tle-endian mode and 1 in bits mode. Grouping does not apply to
71 PostScript or include style.
Bram Moolenaar071d4272004-06-13 20:20:40 +000072
73 -h | -help
Christian Brabandte845b382023-09-27 23:33:39 +020074 Print a summary of available commands and exit. No hex dumping
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000075 is performed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000076
77 -i | -include
Christian Brabandte845b382023-09-27 23:33:39 +020078 Output in C include file style. A complete static array defini
79 tion is written (named after the input file), unless xxd reads
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000080 from stdin.
Bram Moolenaar071d4272004-06-13 20:20:40 +000081
82 -l len | -len len
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020083 Stop after writing <len> octets.
Bram Moolenaar071d4272004-06-13 20:20:40 +000084
Bram Moolenaar0d878b92022-07-01 18:45:04 +010085 -n name | -name name
Christian Brabandte845b382023-09-27 23:33:39 +020086 Override the variable name output when -i is used. The array is
Bram Moolenaar0d878b92022-07-01 18:45:04 +010087 named name and the length is named name_len.
88
Bram Moolenaar86ae7202015-07-10 19:31:35 +020089 -o offset
Bram Moolenaar79cf7c02018-04-03 14:21:16 +020090 Add <offset> to the displayed file position.
Bram Moolenaar86ae7202015-07-10 19:31:35 +020091
Bram Moolenaar071d4272004-06-13 20:20:40 +000092 -p | -ps | -postscript | -plain
Christian Brabandte845b382023-09-27 23:33:39 +020093 Output in PostScript continuous hex dump style. Also known as
94 plain hex dump style.
Bram Moolenaar071d4272004-06-13 20:20:40 +000095
96 -r | -revert
Christian Brabandte845b382023-09-27 23:33:39 +020097 Reverse operation: convert (or patch) hex dump into binary. If
98 not writing to stdout, xxd writes into its output file without
Bram Moolenaar86ae7202015-07-10 19:31:35 +020099 truncating it. Use the combination -r -p to read plain hexadeci
100 mal dumps without line number information and without a particu
Christian Brabandte845b382023-09-27 23:33:39 +0200101 lar column layout. Additional whitespace and line breaks are al
Lennard Hofmann67797192024-05-10 14:17:26 +0200102 lowed anywhere. Use the combination -r -b to read a bits dump
tristhaus85f45212023-10-06 19:51:13 +0200103 instead of a hex dump.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104
Christian Brabandte845b382023-09-27 23:33:39 +0200105 -R when
Lennard Hofmann67797192024-05-10 14:17:26 +0200106 In the output the hex-value and the value are both colored with
107 the same color depending on the hex-value. Mostly helping to
108 differentiate printable and non-printable characters. when is
109 never, always, or auto (default: auto). When the $NO_COLOR en
110 vironment variable is set, colorization will be disabled.
Christian Brabandte845b382023-09-27 23:33:39 +0200111
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112 -seek offset
Bram Moolenaarc0761132005-03-18 20:30:32 +0000113 When used after -r: revert with <offset> added to file positions
Christian Brabandte845b382023-09-27 23:33:39 +0200114 found in hex dump.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115
116 -s [+][-]seek
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200117 Start at <seek> bytes abs. (or rel.) infile offset. + indicates
Lennard Hofmann67797192024-05-10 14:17:26 +0200118 that the seek is relative to the current stdin file position
Bram Moolenaar83e138c2007-05-05 18:27:07 +0000119 (meaningless when not reading from stdin). - indicates that the
Lennard Hofmann67797192024-05-10 14:17:26 +0200120 seek should be that many characters from the end of the input
Bram Moolenaar83e138c2007-05-05 18:27:07 +0000121 (or if combined with +: before the current stdin file position).
122 Without -s option, xxd starts at the current file position.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000123
Christian Brabandte845b382023-09-27 23:33:39 +0200124 -u Use upper-case hex letters. Default is lower-case.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125
126 -v | -version
Bram Moolenaar79cf7c02018-04-03 14:21:16 +0200127 Show version string.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128
Bram Moolenaar071d4272004-06-13 20:20:40 +0000129CAVEATS
Lennard Hofmann67797192024-05-10 14:17:26 +0200130 xxd -r has some built-in magic while evaluating line number informa
131 tion. If the output file is seekable, then the line numbers at the
132 start of each hex dump line may be out of order, lines may be missing,
133 or overlapping. In these cases xxd will lseek(2) to the next position.
134 If the output file is not seekable, only gaps are allowed, which will
Christian Brabandte845b382023-09-27 23:33:39 +0200135 be filled by null-bytes.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000136
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000137 xxd -r never generates parse errors. Garbage is silently skipped.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138
Christian Brabandte845b382023-09-27 23:33:39 +0200139 When editing hex dumps, please note that xxd -r skips everything on the
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000140 input line after reading enough columns of hexadecimal data (see option
Lennard Hofmann67797192024-05-10 14:17:26 +0200141 -c). This also means that changes to the printable ASCII (or EBCDIC)
Christian Brabandte845b382023-09-27 23:33:39 +0200142 columns are always ignored. Reverting a plain (or PostScript) style hex
Lennard Hofmann67797192024-05-10 14:17:26 +0200143 dump with xxd -r -p does not depend on the correct number of columns.
Christian Brabandte845b382023-09-27 23:33:39 +0200144 Here, anything that looks like a pair of hex digits is interpreted.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000145
146 Note the difference between
147 % xxd -i file
148 and
149 % xxd -i < file
150
Lennard Hofmann67797192024-05-10 14:17:26 +0200151 xxd -s +seek may be different from xxd -s seek, as lseek(2) is used to
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000152 "rewind" input. A '+' makes a difference if the input source is stdin,
Lennard Hofmann67797192024-05-10 14:17:26 +0200153 and if stdin's file position is not at the start of the file by the
154 time xxd is started and given its input. The following examples may
Christian Brabandte845b382023-09-27 23:33:39 +0200155 help to clarify (or further confuse!):
Bram Moolenaar071d4272004-06-13 20:20:40 +0000156
Lennard Hofmann67797192024-05-10 14:17:26 +0200157 Rewind stdin before reading; needed because the `cat' has already read
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000158 to the end of stdin.
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000159 % sh -c "cat > plain_copy; xxd -s 0 > hex_copy" < file
Bram Moolenaar071d4272004-06-13 20:20:40 +0000160
Lennard Hofmann67797192024-05-10 14:17:26 +0200161 Hex dump from file position 0x480 (=1024+128) onwards. The `+' sign
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000162 means "relative to the current position", thus the `128' adds to the 1k
163 where dd left off.
Lennard Hofmann67797192024-05-10 14:17:26 +0200164 % sh -c "dd of=plain_snippet bs=1k count=1; xxd -s +128 > hex_snippet"
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000165 < file
Bram Moolenaar071d4272004-06-13 20:20:40 +0000166
Christian Brabandte845b382023-09-27 23:33:39 +0200167 Hex dump from file position 0x100 (=1024-768) onwards.
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000168 % sh -c "dd of=plain_snippet bs=1k count=1; xxd -s +-768 > hex_snippet"
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000169 < file
Bram Moolenaar071d4272004-06-13 20:20:40 +0000170
Lennard Hofmann67797192024-05-10 14:17:26 +0200171 However, this is a rare situation and the use of `+' is rarely needed.
172 The author prefers to monitor the effect of xxd with strace(1) or
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000173 truss(1), whenever -s is used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000174
175EXAMPLES
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000176 Print everything but the first three lines (hex 0x30 bytes) of file.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000177 % xxd -s 0x30 file
178
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000179 Print 3 lines (hex 0x30 bytes) from the end of file.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000180 % xxd -s -0x30 file
181
RestorerZ81b62dd2024-08-15 21:39:33 +0200182 Note: The results of the examples below are relevant to the xxd.1 man
183 page as of May 2024
184
Christian Brabandte845b382023-09-27 23:33:39 +0200185 Print 120 bytes as a continuous hex dump with 20 octets per line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000186 % xxd -l 120 -ps -c 20 xxd.1
RestorerZ81b62dd2024-08-15 21:39:33 +0200187 2e544820585844203120224d6179203230323422
188 20224d616e75616c207061676520666f72207878
189 64220a2e5c220a2e5c222032317374204d617920
190 313939360a2e5c22204d616e2070616765206175
191 74686f723a0a2e5c2220202020546f6e79204e75
192 67656e74203c746f6e79407363746e7567656e2e
Bram Moolenaar071d4272004-06-13 20:20:40 +0000193
Christian Brabandte845b382023-09-27 23:33:39 +0200194 Hex dump the first 120 bytes of this man page with 12 octets per line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000195 % xxd -l 120 -c 12 xxd.1
RestorerZ81b62dd2024-08-15 21:39:33 +0200196 00000000: 2e54 4820 5858 4420 3120 224d .TH XXD 1 "M
197 0000000c: 6179 2032 3032 3422 2022 4d61 ay 2024" "Ma
198 00000018: 6e75 616c 2070 6167 6520 666f nual page fo
199 00000024: 7220 7878 6422 0a2e 5c22 0a2e r xxd"..\"..
200 00000030: 5c22 2032 3173 7420 4d61 7920 \" 21st May
201 0000003c: 3139 3936 0a2e 5c22 204d 616e 1996..\" Man
202 00000048: 2070 6167 6520 6175 7468 6f72 page author
203 00000054: 3a0a 2e5c 2220 2020 2054 6f6e :..\" Ton
204 00000060: 7920 4e75 6765 6e74 203c 746f y Nugent <to
205 0000006c: 6e79 4073 6374 6e75 6765 6e2e ny@sctnugen.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000206
207 Display just the date from the file xxd.1
RestorerZ81b62dd2024-08-15 21:39:33 +0200208 % xxd -s 0x33 -l 13 -c 13 xxd.1
RestorerZ8f3f7852024-08-16 21:03:58 +0200209 00000033: 3231 7374 204d 6179 2031 3939 36 21st May 1996
Bram Moolenaar071d4272004-06-13 20:20:40 +0000210
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000211 Copy input_file to output_file and prepend 100 bytes of value 0x00.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000212 % xxd input_file | xxd -r -s 100 > output_file
213
214 Patch the date in the file xxd.1
RestorerZ81b62dd2024-08-15 21:39:33 +0200215 % echo "0000034: 3574 68" | xxd -r - xxd.1
216 % xxd -s 0x33 -l 13 -c 13 xxd.1
RestorerZ8f3f7852024-08-16 21:03:58 +0200217 00000033: 3235 7468 204d 6179 2031 3939 36 25th May 1996
Bram Moolenaar071d4272004-06-13 20:20:40 +0000218
Lennard Hofmann67797192024-05-10 14:17:26 +0200219 Create a 65537 byte file with all bytes 0x00, except for the last one
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000220 which is 'A' (hex 0x41).
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000221 % echo "010000: 41" | xxd -r > file
Bram Moolenaar071d4272004-06-13 20:20:40 +0000222
Christian Brabandte845b382023-09-27 23:33:39 +0200223 Hex dump this file with autoskip.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000224 % xxd -a -c 12 file
RestorerZ8f3f7852024-08-16 21:03:58 +0200225 00000000: 0000 0000 0000 0000 0000 0000 ............
Bram Moolenaar071d4272004-06-13 20:20:40 +0000226 *
RestorerZ8f3f7852024-08-16 21:03:58 +0200227 0000fffc: 0000 0000 41 ....A
Bram Moolenaar071d4272004-06-13 20:20:40 +0000228
Bram Moolenaar0d878b92022-07-01 18:45:04 +0100229 Create a 1 byte file containing a single 'A' character. The number af
Lennard Hofmann67797192024-05-10 14:17:26 +0200230 ter '-r -s' adds to the line numbers found in the file; in effect, the
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000231 leading bytes are suppressed.
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000232 % echo "010000: 41" | xxd -r -s -0x10000 > file
Bram Moolenaar071d4272004-06-13 20:20:40 +0000233
Lennard Hofmann67797192024-05-10 14:17:26 +0200234 Use xxd as a filter within an editor such as vim(1) to hex dump a re
Christian Brabandte845b382023-09-27 23:33:39 +0200235 gion marked between `a' and `z'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000236 :'a,'z!xxd
237
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000238 Use xxd as a filter within an editor such as vim(1) to recover a binary
Christian Brabandte845b382023-09-27 23:33:39 +0200239 hex dump marked between `a' and `z'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000240 :'a,'z!xxd -r
241
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000242 Use xxd as a filter within an editor such as vim(1) to recover one line
Christian Brabandte845b382023-09-27 23:33:39 +0200243 of a hex dump. Move the cursor over the line and type:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000244 !!xxd -r
245
246 Read single characters from a serial line
247 % xxd -c1 < /dev/term/b &
248 % stty < /dev/term/b -echo -opost -isig -icanon min 1
249 % echo -n foo > /dev/term/b
250
Bram Moolenaar071d4272004-06-13 20:20:40 +0000251RETURN VALUES
252 The following error values are returned:
253
254 0 no errors encountered.
255
Christian Brabandte845b382023-09-27 23:33:39 +0200256 -1 operation not supported (xxd -r -i still impossible).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000257
258 1 error while parsing options.
259
260 2 problems with input file.
261
262 3 problems with output file.
263
264 4,5 desired seek position is unreachable.
265
266SEE ALSO
267 uuencode(1), uudecode(1), patch(1)
268
269WARNINGS
Christian Brabandte845b382023-09-27 23:33:39 +0200270 The tool's weirdness matches its creator's brain. Use entirely at your
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000271 own risk. Copy files. Trace it. Become a wizard.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000272
273VERSION
RestorerZ81b62dd2024-08-15 21:39:33 +0200274 This manual page documents xxd version 1.7 from 2024-05.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275
276AUTHOR
277 (c) 1990-1997 by Juergen Weigert
278 <jnweiger@informatik.uni-erlangen.de>
279
280 Distribute freely and credit me,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281 make money and share with me,
282 lose money and don't ask me.
283
284 Manual page started by Tony Nugent
285 <tony@sctnugen.ppp.gu.edu.au> <T.Nugent@sct.gu.edu.au>
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000286 Small changes by Bram Moolenaar. Edited by Juergen Weigert.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000287
RestorerZ81b62dd2024-08-15 21:39:33 +0200288Manual page for xxd May 2024 XXD(1)