xxd.1 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. .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
  21. creates a hex dump of a given file or standard input.
  22. It can also convert a hex dump back to its original binary form.
  23. Like
  24. .BR uuencode (1)
  25. and
  26. .BR uudecode (1)
  27. it allows the transmission of binary data in a `mail-safe' ASCII representation,
  28. but has the advantage of decoding to standard output.
  29. Moreover, it can be used to perform binary file patching.
  30. .SH OPTIONS
  31. If no
  32. .I infile
  33. is given, standard input is read.
  34. If
  35. .I infile
  36. is specified as a
  37. .RB \` \- '
  38. character, then input is taken from standard input.
  39. If no
  40. .I outfile
  41. is given (or a
  42. .RB \` \- '
  43. character is in its place), results are sent to standard output.
  44. .PP
  45. Note that a "lazy" parser is used which does not check for more than the first
  46. option letter, unless the option is followed by a parameter.
  47. Spaces between a single option letter and its parameter are optional.
  48. Parameters to options can be specified in decimal, hexadecimal or octal
  49. notation.
  50. Thus
  51. .BR \-c8 ,
  52. .BR "\-c 8" ,
  53. .B \-c 010
  54. and
  55. .B \-cols 8
  56. are all equivalent.
  57. .PP
  58. .TP
  59. .IR \-a " | " \-autoskip
  60. Toggle autoskip: A single '*' replaces nul-lines. Default off.
  61. .TP
  62. .IR \-b " | " \-bits
  63. Switch to bits (binary digits) dump, rather than hexdump.
  64. This option writes octets as eight digits "1"s and "0"s instead of a normal
  65. hexadecimal dump. Each line is preceded by a line number in hexadecimal and
  66. followed 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. Format
  71. .RI < cols >
  72. octets per line. Default 16 (\-i: 12, \-ps: 30, \-b: 6). Max 256.
  73. No maxmimum for \-ps. With \-ps, 0 results in one long line of output.
  74. .TP
  75. .IR \-C " | " \-capitalize
  76. Capitalize variable names in C include file style, when using \-i.
  77. .TP
  78. .IR \-E " | " \-EBCDIC
  79. Change the character encoding in the righthand column from ASCII to EBCDIC.
  80. This does not change the hexadecimal representation. The option is
  81. meaningless in combinations with \-r, \-p or \-i.
  82. .TP
  83. .IR \-e
  84. Switch to little-endian hexdump.
  85. This option treats byte groups as words in little-endian byte order.
  86. The default grouping of 4 bytes may be changed using
  87. .RI "" \-g .
  88. This option only applies to hexdump, leaving the ASCII (or EBCDIC)
  89. representation unchanged.
  90. The command line switches
  91. \-r, \-p, \-i do not work with this mode.
  92. .TP
  93. .IR "\-g bytes " | " \-groupsize bytes"
  94. Separate the output of every
  95. .RI < bytes >
  96. bytes (two hex characters or eight bit-digits each) by a whitespace.
  97. Specify
  98. .I \-g 0
  99. to suppress grouping.
  100. .RI < Bytes "> defaults to " 2
  101. in normal mode, \fI4\fP in little-endian mode and \fI1\fP in bits mode.
  102. Grouping does not apply to postscript or include style.
  103. .TP
  104. .IR \-h " | " \-help
  105. Print a summary of available commands and exit. No hex dumping is performed.
  106. .TP
  107. .IR \-i " | " \-include
  108. Output in C include file style. A complete static array definition is written
  109. (named after the input file), unless xxd reads from stdin.
  110. .TP
  111. .IR "\-l len " | " \-len len"
  112. Stop after writing
  113. .RI < len >
  114. octets.
  115. .TP
  116. .I "\-n name " | " \-name name"
  117. Override 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
  120. .I \-o offset
  121. Add
  122. .RI < offset >
  123. to the displayed file position.
  124. .TP
  125. .IR \-p " | " \-ps " | " \-postscript " | " \-plain
  126. Output in postscript continuous hexdump style. Also known as plain hexdump
  127. style.
  128. .TP
  129. .IR \-r " | " \-revert
  130. Reverse operation: convert (or patch) hexdump into binary.
  131. If not writing to stdout, xxd writes into its output file without truncating
  132. it. Use the combination
  133. .I \-r \-p
  134. to read plain hexadecimal dumps without line number information and without a
  135. particular column layout. Additional Whitespace and line-breaks are allowed
  136. anywhere.
  137. .TP
  138. .I \-seek offset
  139. When used after
  140. .IR \-r :
  141. revert with
  142. .RI < offset >
  143. added to file positions found in hexdump.
  144. .TP
  145. .I \-s [+][\-]seek
  146. Start at
  147. .RI < seek >
  148. bytes abs. (or rel.) infile offset.
  149. \fI+ \fRindicates that the seek is relative to the current stdin file position
  150. (meaningless when not reading from stdin). \fI\- \fRindicates that the seek
  151. should be that many characters from the end of the input (or if combined with
  152. \fI+\fR: before the current stdin file position).
  153. Without \-s option, xxd starts at the current file position.
  154. .TP
  155. .I \-u
  156. Use upper case hex letters. Default is lower case.
  157. .TP
  158. .IR \-v " | " \-version
  159. Show version string.
  160. .SH CAVEATS
  161. .PP
  162. .I xxd \-r
  163. has some builtin magic while evaluating line number information.
  164. If the output file is seekable, then the linenumbers at the start of each
  165. hexdump line may be out of order, lines may be missing, or overlapping. In
  166. these cases xxd will lseek(2) to the next position. If the output file is not
  167. seekable, only gaps are allowed, which will be filled by null-bytes.
  168. .PP
  169. .I xxd \-r
  170. never generates parse errors. Garbage is silently skipped.
  171. .PP
  172. When editing hexdumps, please note that
  173. .I xxd \-r
  174. skips everything on the input line after reading enough columns of hexadecimal
  175. data (see option \-c). This also means, that changes to the printable ascii (or
  176. ebcdic) columns are always ignored. Reverting a plain (or postscript) style
  177. hexdump 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.
  178. .PP
  179. Note the difference between
  180. .br
  181. \fI% xxd \-i file\fR
  182. .br
  183. and
  184. .br
  185. \fI% xxd \-i < file\fR
  186. .PP
  187. .I xxd \-s +seek
  188. may be different from
  189. .IR "xxd \-s seek" ,
  190. as lseek(2) is used to "rewind" input. A '+'
  191. makes a difference if the input source is stdin, and if stdin's file position
  192. is not at the start of the file by the time xxd is started and given its input.
  193. The following examples may help to clarify (or further confuse!)...
  194. .PP
  195. Rewind stdin before reading; needed because the `cat' has already read to the
  196. end of stdin.
  197. .br
  198. \fI% sh \-c "cat > plain_copy; xxd \-s 0 > hex_copy" < file\fR
  199. .PP
  200. Hexdump from file position 0x480 (=1024+128) onwards.
  201. The `+' sign means "relative to the current position", thus the `128' adds to
  202. the 1k where dd left off.
  203. .br
  204. \fI% sh \-c "dd of=plain_snippet bs=1k count=1; xxd \-s +128 > hex_snippet" < file\fR
  205. .PP
  206. Hexdump from file position 0x100 ( = 1024\-768) on.
  207. .br
  208. \fI% sh \-c "dd of=plain_snippet bs=1k count=1; xxd \-s +\-768 > hex_snippet" < file\fR
  209. .PP
  210. However, this is a rare situation and the use of `+' is rarely needed.
  211. The author prefers to monitor the effect of xxd with strace(1) or truss(1), whenever \-s is used.
  212. .SH EXAMPLES
  213. .PP
  214. .br
  215. Print everything but the first three lines (hex 0x30 bytes) of
  216. .BR file .
  217. .br
  218. \fI% xxd \-s 0x30 file\fR
  219. .PP
  220. .br
  221. Print 3 lines (hex 0x30 bytes) from the end of
  222. .BR file .
  223. .br
  224. \fI% xxd \-s \-0x30 file\fR
  225. .PP
  226. .br
  227. Print 120 bytes as continuous hexdump with 20 octets per line.
  228. .br
  229. \fI% xxd \-l 120 \-ps \-c 20 xxd.1\fR
  230. .br
  231. 2e54482058584420312022417567757374203139
  232. .br
  233. 39362220224d616e75616c207061676520666f72
  234. .br
  235. 20787864220a2e5c220a2e5c222032317374204d
  236. .br
  237. 617920313939360a2e5c22204d616e2070616765
  238. .br
  239. 20617574686f723a0a2e5c2220202020546f6e79
  240. .br
  241. 204e7567656e74203c746f6e79407363746e7567
  242. .br
  243. .br
  244. Hexdump the first 120 bytes of this man page with 12 octets per line.
  245. .br
  246. \fI% xxd \-l 120 \-c 12 xxd.1\fR
  247. .br
  248. 0000000: 2e54 4820 5858 4420 3120 2241 .TH XXD 1 "A
  249. .br
  250. 000000c: 7567 7573 7420 3139 3936 2220 ugust 1996"
  251. .br
  252. 0000018: 224d 616e 7561 6c20 7061 6765 "Manual page
  253. .br
  254. 0000024: 2066 6f72 2078 7864 220a 2e5c for xxd"..\\
  255. .br
  256. 0000030: 220a 2e5c 2220 3231 7374 204d "..\\" 21st M
  257. .br
  258. 000003c: 6179 2031 3939 360a 2e5c 2220 ay 1996..\\"
  259. .br
  260. 0000048: 4d61 6e20 7061 6765 2061 7574 Man page aut
  261. .br
  262. 0000054: 686f 723a 0a2e 5c22 2020 2020 hor:..\\"
  263. .br
  264. 0000060: 546f 6e79 204e 7567 656e 7420 Tony Nugent
  265. .br
  266. 000006c: 3c74 6f6e 7940 7363 746e 7567 <tony@sctnug
  267. .PP
  268. .br
  269. Display just the date from the file xxd.1
  270. .br
  271. \fI% xxd \-s 0x36 \-l 13 \-c 13 xxd.1\fR
  272. .br
  273. 0000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996
  274. .PP
  275. .br
  276. Copy
  277. .B input_file
  278. to
  279. .B output_file
  280. and prepend 100 bytes of value 0x00.
  281. .br
  282. \fI% xxd input_file | xxd \-r \-s 100 > output_file\fR
  283. .br
  284. .br
  285. Patch the date in the file xxd.1
  286. .br
  287. \fI% echo "0000037: 3574 68" | xxd \-r \- xxd.1\fR
  288. .br
  289. \fI% xxd \-s 0x36 \-l 13 \-c 13 xxd.1\fR
  290. .br
  291. 0000036: 3235 7468 204d 6179 2031 3939 36 25th May 1996
  292. .PP
  293. .br
  294. Create a 65537 byte file with all bytes 0x00,
  295. except for the last one which is 'A' (hex 0x41).
  296. .br
  297. \fI% echo "010000: 41" | xxd \-r > file\fR
  298. .PP
  299. .br
  300. Hexdump this file with autoskip.
  301. .br
  302. \fI% xxd \-a \-c 12 file\fR
  303. .br
  304. 0000000: 0000 0000 0000 0000 0000 0000 ............
  305. .br
  306. *
  307. .br
  308. 000fffc: 0000 0000 40 ....A
  309. .PP
  310. Create a 1 byte file containing a single 'A' character.
  311. The number after '\-r \-s' adds to the linenumbers found in the file;
  312. in effect, the leading bytes are suppressed.
  313. .br
  314. \fI% echo "010000: 41" | xxd \-r \-s \-0x10000 > file\fR
  315. .PP
  316. Use xxd as a filter within an editor such as
  317. .B vim(1)
  318. to hexdump a region marked between `a' and `z'.
  319. .br
  320. \fI:'a,'z!xxd\fR
  321. .PP
  322. Use xxd as a filter within an editor such as
  323. .B vim(1)
  324. to recover a binary hexdump marked between `a' and `z'.
  325. .br
  326. \fI:'a,'z!xxd \-r\fR
  327. .PP
  328. Use xxd as a filter within an editor such as
  329. .B vim(1)
  330. to recover one line of a hexdump. Move the cursor over the line and type:
  331. .br
  332. \fI!!xxd \-r\fR
  333. .PP
  334. Read single characters from a serial line
  335. .br
  336. \fI% xxd \-c1 < /dev/term/b &\fR
  337. .br
  338. \fI% stty < /dev/term/b \-echo \-opost \-isig \-icanon min 1\fR
  339. .br
  340. \fI% echo \-n foo > /dev/term/b\fR
  341. .PP
  342. .SH "RETURN VALUES"
  343. The following error values are returned:
  344. .TP
  345. 0
  346. no errors encountered.
  347. .TP
  348. \-1
  349. operation not supported (
  350. .I xxd \-r \-i
  351. still impossible).
  352. .TP
  353. 1
  354. error while parsing options.
  355. .TP
  356. 2
  357. problems with input file.
  358. .TP
  359. 3
  360. problems with output file.
  361. .TP
  362. 4,5
  363. desired seek position is unreachable.
  364. .SH "SEE ALSO"
  365. uuencode(1), uudecode(1), patch(1)
  366. .br
  367. .SH WARNINGS
  368. The tools weirdness matches its creators brain.
  369. Use entirely at your own risk. Copy files. Trace it. Become a wizard.
  370. .br
  371. .SH VERSION
  372. This manual page documents xxd version 1.7
  373. .SH AUTHOR
  374. .br
  375. (c) 1990-1997 by Juergen Weigert
  376. .br
  377. <jnweiger@informatik.uni\-erlangen.de>
  378. .LP
  379. Distribute freely and credit me,
  380. .br
  381. make money and share with me,
  382. .br
  383. lose money and don't ask me.
  384. .PP
  385. Manual page started by Tony Nugent
  386. .br
  387. <tony@sctnugen.ppp.gu.edu.au> <T.Nugent@sct.gu.edu.au>
  388. .br
  389. Small changes by Bram Moolenaar.
  390. Edited by Juergen Weigert.
  391. .PP