xxd.man 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. XXD(1) General Commands Manual XXD(1)
  2. NAME
  3. xxd - make a hexdump or do the reverse.
  4. SYNOPSIS
  5. xxd -h[elp]
  6. xxd [options] [infile [outfile]]
  7. xxd -r[evert] [options] [infile [outfile]]
  8. DESCRIPTION
  9. xxd creates a hex dump of a given file or standard input. It can also
  10. convert a hex dump back to its original binary form. Like uuencode(1)
  11. and uudecode(1) it allows the transmission of binary data in a `mail-
  12. safe' ASCII representation, but has the advantage of decoding to stan‐
  13. dard output. Moreover, it can be used to perform binary file patching.
  14. OPTIONS
  15. If no infile is given, standard input is read. If infile is specified
  16. as a `-' character, then input is taken from standard input. If no
  17. outfile is given (or a `-' character is in its place), results are sent
  18. to standard output.
  19. Note that a "lazy" parser is used which does not check for more than
  20. the first option letter, unless the option is followed by a parameter.
  21. Spaces between a single option letter and its parameter are optional.
  22. Parameters to options can be specified in decimal, hexadecimal or octal
  23. notation. Thus -c8, -c 8, -c 010 and -cols 8 are all equivalent.
  24. -a | -autoskip
  25. Toggle autoskip: A single '*' replaces nul-lines. Default off.
  26. -b | -bits
  27. Switch to bits (binary digits) dump, rather than hexdump. This
  28. option writes octets as eight digits "1"s and "0"s instead of a
  29. normal hexadecimal dump. Each line is preceded by a line number
  30. in hexadecimal and followed by an ascii (or ebcdic) representa‐
  31. tion. The command line switches -r, -p, -i do not work with this
  32. mode.
  33. -c cols | -cols cols
  34. Format <cols> octets per line. Default 16 (-i: 12, -ps: 30, -b:
  35. 6). Max 256. No maxmimum for -ps. With -ps, 0 results in one
  36. long line of output.
  37. -C | -capitalize
  38. Capitalize variable names in C include file style, when using
  39. -i.
  40. -E | -EBCDIC
  41. Change the character encoding in the righthand column from ASCII
  42. to EBCDIC. This does not change the hexadecimal representation.
  43. The option is meaningless in combinations with -r, -p or -i.
  44. -e Switch to little-endian hexdump. This option treats byte groups
  45. as words in little-endian byte order. The default grouping of 4
  46. bytes may be changed using -g. This option only applies to hex‐
  47. dump, leaving the ASCII (or EBCDIC) representation unchanged.
  48. The command line switches -r, -p, -i do not work with this mode.
  49. -g bytes | -groupsize bytes
  50. Separate the output of every <bytes> bytes (two hex characters
  51. or eight bit-digits each) by a whitespace. Specify -g 0 to sup‐
  52. press grouping. <Bytes> defaults to 2 in normal mode, 4 in lit‐
  53. tle-endian mode and 1 in bits mode. Grouping does not apply to
  54. postscript or include style.
  55. -h | -help
  56. Print a summary of available commands and exit. No hex dumping
  57. is performed.
  58. -i | -include
  59. Output in C include file style. A complete static array defini‐
  60. tion is written (named after the input file), unless xxd reads
  61. from stdin.
  62. -l len | -len len
  63. Stop after writing <len> octets.
  64. -n name | -name name
  65. Override the variable name output when -i is used. The array is
  66. named name and the length is named name_len.
  67. -o offset
  68. Add <offset> to the displayed file position.
  69. -p | -ps | -postscript | -plain
  70. Output in postscript continuous hexdump style. Also known as
  71. plain hexdump style.
  72. -r | -revert
  73. Reverse operation: convert (or patch) hexdump into binary. If
  74. not writing to stdout, xxd writes into its output file without
  75. truncating it. Use the combination -r -p to read plain hexadeci‐
  76. mal dumps without line number information and without a particu‐
  77. lar column layout. Additional Whitespace and line-breaks are al‐
  78. lowed anywhere.
  79. -seek offset
  80. When used after -r: revert with <offset> added to file positions
  81. found in hexdump.
  82. -s [+][-]seek
  83. Start at <seek> bytes abs. (or rel.) infile offset. + indicates
  84. that the seek is relative to the current stdin file position
  85. (meaningless when not reading from stdin). - indicates that the
  86. seek should be that many characters from the end of the input
  87. (or if combined with +: before the current stdin file position).
  88. Without -s option, xxd starts at the current file position.
  89. -u Use upper case hex letters. Default is lower case.
  90. -v | -version
  91. Show version string.
  92. CAVEATS
  93. xxd -r has some builtin magic while evaluating line number information.
  94. If the output file is seekable, then the linenumbers at the start of
  95. each hexdump line may be out of order, lines may be missing, or over‐
  96. lapping. In these cases xxd will lseek(2) to the next position. If the
  97. output file is not seekable, only gaps are allowed, which will be
  98. filled by null-bytes.
  99. xxd -r never generates parse errors. Garbage is silently skipped.
  100. When editing hexdumps, please note that xxd -r skips everything on the
  101. input line after reading enough columns of hexadecimal data (see option
  102. -c). This also means, that changes to the printable ascii (or ebcdic)
  103. columns are always ignored. Reverting a plain (or postscript) style
  104. hexdump with xxd -r -p does not depend on the correct number of col‐
  105. umns. Here anything that looks like a pair of hex-digits is inter‐
  106. preted.
  107. Note the difference between
  108. % xxd -i file
  109. and
  110. % xxd -i < file
  111. xxd -s +seek may be different from xxd -s seek, as lseek(2) is used to
  112. "rewind" input. A '+' makes a difference if the input source is stdin,
  113. and if stdin's file position is not at the start of the file by the
  114. time xxd is started and given its input. The following examples may
  115. help to clarify (or further confuse!)...
  116. Rewind stdin before reading; needed because the `cat' has already read
  117. to the end of stdin.
  118. % sh -c "cat > plain_copy; xxd -s 0 > hex_copy" < file
  119. Hexdump from file position 0x480 (=1024+128) onwards. The `+' sign
  120. means "relative to the current position", thus the `128' adds to the 1k
  121. where dd left off.
  122. % sh -c "dd of=plain_snippet bs=1k count=1; xxd -s +128 > hex_snippet"
  123. < file
  124. Hexdump from file position 0x100 ( = 1024-768) on.
  125. % sh -c "dd of=plain_snippet bs=1k count=1; xxd -s +-768 > hex_snippet"
  126. < file
  127. However, this is a rare situation and the use of `+' is rarely needed.
  128. The author prefers to monitor the effect of xxd with strace(1) or
  129. truss(1), whenever -s is used.
  130. EXAMPLES
  131. Print everything but the first three lines (hex 0x30 bytes) of file.
  132. % xxd -s 0x30 file
  133. Print 3 lines (hex 0x30 bytes) from the end of file.
  134. % xxd -s -0x30 file
  135. Print 120 bytes as continuous hexdump with 20 octets per line.
  136. % xxd -l 120 -ps -c 20 xxd.1
  137. 2e54482058584420312022417567757374203139
  138. 39362220224d616e75616c207061676520666f72
  139. 20787864220a2e5c220a2e5c222032317374204d
  140. 617920313939360a2e5c22204d616e2070616765
  141. 20617574686f723a0a2e5c2220202020546f6e79
  142. 204e7567656e74203c746f6e79407363746e7567
  143. Hexdump the first 120 bytes of this man page with 12 octets per line.
  144. % xxd -l 120 -c 12 xxd.1
  145. 0000000: 2e54 4820 5858 4420 3120 2241 .TH XXD 1 "A
  146. 000000c: 7567 7573 7420 3139 3936 2220 ugust 1996"
  147. 0000018: 224d 616e 7561 6c20 7061 6765 "Manual page
  148. 0000024: 2066 6f72 2078 7864 220a 2e5c for xxd"..\
  149. 0000030: 220a 2e5c 2220 3231 7374 204d "..\" 21st M
  150. 000003c: 6179 2031 3939 360a 2e5c 2220 ay 1996..\"
  151. 0000048: 4d61 6e20 7061 6765 2061 7574 Man page aut
  152. 0000054: 686f 723a 0a2e 5c22 2020 2020 hor:..\"
  153. 0000060: 546f 6e79 204e 7567 656e 7420 Tony Nugent
  154. 000006c: 3c74 6f6e 7940 7363 746e 7567 <tony@sctnug
  155. Display just the date from the file xxd.1
  156. % xxd -s 0x36 -l 13 -c 13 xxd.1
  157. 0000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996
  158. Copy input_file to output_file and prepend 100 bytes of value 0x00.
  159. % xxd input_file | xxd -r -s 100 > output_file
  160. Patch the date in the file xxd.1
  161. % echo "0000037: 3574 68" | xxd -r - xxd.1
  162. % xxd -s 0x36 -l 13 -c 13 xxd.1
  163. 0000036: 3235 7468 204d 6179 2031 3939 36 25th May 1996
  164. Create a 65537 byte file with all bytes 0x00, except for the last one
  165. which is 'A' (hex 0x41).
  166. % echo "010000: 41" | xxd -r > file
  167. Hexdump this file with autoskip.
  168. % xxd -a -c 12 file
  169. 0000000: 0000 0000 0000 0000 0000 0000 ............
  170. *
  171. 000fffc: 0000 0000 40 ....A
  172. Create a 1 byte file containing a single 'A' character. The number af‐
  173. ter '-r -s' adds to the linenumbers found in the file; in effect, the
  174. leading bytes are suppressed.
  175. % echo "010000: 41" | xxd -r -s -0x10000 > file
  176. Use xxd as a filter within an editor such as vim(1) to hexdump a region
  177. marked between `a' and `z'.
  178. :'a,'z!xxd
  179. Use xxd as a filter within an editor such as vim(1) to recover a binary
  180. hexdump marked between `a' and `z'.
  181. :'a,'z!xxd -r
  182. Use xxd as a filter within an editor such as vim(1) to recover one line
  183. of a hexdump. Move the cursor over the line and type:
  184. !!xxd -r
  185. Read single characters from a serial line
  186. % xxd -c1 < /dev/term/b &
  187. % stty < /dev/term/b -echo -opost -isig -icanon min 1
  188. % echo -n foo > /dev/term/b
  189. RETURN VALUES
  190. The following error values are returned:
  191. 0 no errors encountered.
  192. -1 operation not supported ( xxd -r -i still impossible).
  193. 1 error while parsing options.
  194. 2 problems with input file.
  195. 3 problems with output file.
  196. 4,5 desired seek position is unreachable.
  197. SEE ALSO
  198. uuencode(1), uudecode(1), patch(1)
  199. WARNINGS
  200. The tools weirdness matches its creators brain. Use entirely at your
  201. own risk. Copy files. Trace it. Become a wizard.
  202. VERSION
  203. This manual page documents xxd version 1.7
  204. AUTHOR
  205. (c) 1990-1997 by Juergen Weigert
  206. <jnweiger@informatik.uni-erlangen.de>
  207. Distribute freely and credit me,
  208. make money and share with me,
  209. lose money and don't ask me.
  210. Manual page started by Tony Nugent
  211. <tony@sctnugen.ppp.gu.edu.au> <T.Nugent@sct.gu.edu.au>
  212. Small changes by Bram Moolenaar. Edited by Juergen Weigert.
  213. Manual page for xxd August 1996 XXD(1)