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