Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.bin / hexdump / hexdump.1
1 .\" Copyright (c) 1989, 1990, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)hexdump.1   8.2 (Berkeley) 4/18/94
33 .\" $FreeBSD: src/usr.bin/hexdump/hexdump.1,v 1.9.2.9 2003/02/25 20:05:17 trhodes Exp $
34 .\"
35 .Dd April 18, 1994
36 .Dt HEXDUMP 1
37 .Os
38 .Sh NAME
39 .Nm hexdump , hd
40 .Nd ASCII, decimal, hexadecimal, octal dump
41 .Sh SYNOPSIS
42 .Nm
43 .Op Fl bcCdovx
44 .Op Fl e Ar format_string
45 .Op Fl f Ar format_file
46 .Op Fl n Ar length
47 .Bk -words
48 .Op Fl s Ar skip
49 .Ek
50 .Ar
51 .Nm hd
52 .Op Fl bcdovx
53 .Op Fl e Ar format_string
54 .Op Fl f Ar format_file
55 .Op Fl n Ar length
56 .Bk -words
57 .Op Fl s Ar skip
58 .Ek
59 .Ar
60 .Sh DESCRIPTION
61 The
62 .Nm
63 utility is a filter which displays the specified files, or
64 the standard input, if no files are specified, in a user specified
65 format.
66 .Pp
67 The options are as follows:
68 .Bl -tag -width indent
69 .It Fl b
70 .Em One-byte octal display .
71 Display the input offset in hexadecimal, followed by sixteen
72 space-separated, three column, zero-filled, bytes of input data,
73 in octal, per line.
74 .It Fl c
75 .Em One-byte character display .
76 Display the input offset in hexadecimal, followed by sixteen
77 space-separated, three column, space-filled, characters of input
78 data per line.
79 .It Fl C
80 .Em Canonical hex+ASCII display .
81 Display the input offset in hexadecimal, followed by sixteen
82 space-separated, two column, hexadecimal bytes, followed by the
83 same sixteen bytes in %_p format enclosed in ``|'' characters.
84 .Pp
85 Calling the command
86 .Nm hd
87 implies this option.
88 .It Fl d
89 .Em Two-byte decimal display .
90 Display the input offset in hexadecimal, followed by eight
91 space-separated, five column, zero-filled, two-byte units
92 of input data, in unsigned decimal, per line.
93 .It Fl e Ar format_string
94 Specify a format string to be used for displaying data.
95 .It Fl f Ar format_file
96 Specify a file that contains one or more newline separated format strings.
97 Empty lines and lines whose first non-blank character is a hash mark
98 .Pf ( Cm \&# )
99 are ignored.
100 .It Fl n Ar length
101 Interpret only
102 .Ar length
103 bytes of input.
104 .It Fl o
105 .Em Two-byte octal display .
106 Display the input offset in hexadecimal, followed by eight
107 space-separated, six column, zero-filled, two byte quantities of
108 input data, in octal, per line.
109 .It Fl s Ar offset
110 Skip
111 .Ar offset
112 bytes from the beginning of the input.
113 By default,
114 .Ar offset
115 is interpreted as a decimal number.
116 With a leading
117 .Cm 0x
118 or
119 .Cm 0X ,
120 .Ar offset
121 is interpreted as a hexadecimal number,
122 otherwise, with a leading
123 .Cm 0 ,
124 .Ar offset
125 is interpreted as an octal number.
126 Appending the character
127 .Cm b ,
128 .Cm k ,
129 or
130 .Cm m
131 to
132 .Ar offset
133 causes it to be interpreted as a multiple of
134 .Li 512 ,
135 .Li 1024 ,
136 or
137 .Li 1048576 ,
138 respectively.
139 .It Fl v
140 Cause
141 .Nm
142 to display all input data.
143 Without the
144 .Fl v
145 option, any number of groups of output lines, which would be
146 identical to the immediately preceding group of output lines (except
147 for the input offsets), are replaced with a line comprised of a
148 single asterisk.
149 .It Fl x
150 .Em Two-byte hexadecimal display .
151 Display the input offset in hexadecimal, followed by eight, space
152 separated, four column, zero-filled, two-byte quantities of input
153 data, in hexadecimal, per line.
154 .El
155 .Pp
156 For each input file,
157 .Nm
158 sequentially copies the input to standard output, transforming the
159 data according to the format strings specified by the
160 .Fl e
161 and
162 .Fl f
163 options, in the order that they were specified.
164 .Ss Formats
165 A format string contains any number of format units, separated by
166 whitespace.
167 A format unit contains up to three items: an iteration count, a byte
168 count, and a format.
169 .Pp
170 The iteration count is an optional positive integer, which defaults to
171 one.
172 Each format is applied iteration count times.
173 .Pp
174 The byte count is an optional positive integer.
175 If specified it defines the number of bytes to be interpreted by
176 each iteration of the format.
177 .Pp
178 If an iteration count and/or a byte count is specified, a single slash
179 must be placed after the iteration count and/or before the byte count
180 to disambiguate them.
181 Any whitespace before or after the slash is ignored.
182 .Pp
183 The format is required and must be surrounded by double quote
184 (" ") marks.
185 It is interpreted as a fprintf-style format string (see
186 .Xr fprintf 3 ) ,
187 with the
188 following exceptions:
189 .Bl -bullet -offset indent
190 .It
191 An asterisk (*) may not be used as a field width or precision.
192 .It
193 A byte count or field precision
194 .Em is
195 required for each ``s'' conversion
196 character (unlike the
197 .Xr fprintf 3
198 default which prints the entire string if the precision is unspecified).
199 .It
200 The conversion characters ``h'', ``l'', ``n'', ``p'' and ``q'' are
201 not supported.
202 .It
203 The single character escape sequences
204 described in the C standard are supported:
205 .Bd -ragged -offset indent -compact
206 .Bl -column <alert_character>
207 .It "NUL        \e0
208 .It "<alert character>  \ea
209 .It "<backspace>        \eb
210 .It "<form-feed>        \ef
211 .It "<newline>  \en
212 .It "<carriage return>  \er
213 .It "<tab>      \et
214 .It "<vertical tab>     \ev
215 .El
216 .Ed
217 .El
218 .Pp
219 The
220 .Nm
221 utility also supports the following additional conversion strings:
222 .Bl -tag -width Fl
223 .It Cm \&_a Ns Op Cm dox
224 Display the input offset, cumulative across input files, of the
225 next byte to be displayed.
226 The appended characters
227 .Cm d ,
228 .Cm o ,
229 and
230 .Cm x
231 specify the display base
232 as decimal, octal or hexadecimal respectively.
233 .It Cm \&_A Ns Op Cm dox
234 Identical to the
235 .Cm \&_a
236 conversion string except that it is only performed
237 once, when all of the input data has been processed.
238 .It Cm \&_c
239 Output characters in the default character set.
240 Nonprinting characters are displayed in three character, zero-padded
241 octal, except for those representable by standard escape notation
242 (see above),
243 which are displayed as two character strings.
244 .It Cm _p
245 Output characters in the default character set.
246 Nonprinting characters are displayed as a single
247 .Dq Cm \&. .
248 .It Cm _u
249 Output US
250 .Tn ASCII
251 characters, with the exception that control characters are
252 displayed using the following, lower-case, names.
253 Characters greater than 0xff, hexadecimal, are displayed as hexadecimal
254 strings.
255 .Bl -column \&000_nu \&001_so \&002_st \&003_et \&004_eo
256 .It "\&000\ NUL\t001\ SOH\t002\ STX\t003\ ETX\t004\ EOT\t005\ ENQ
257 .It "\&006\ ACK\t007\ BEL\t008\ BS\t009\ HT\t00A\ LF\t00B\ VT
258 .It "\&00C\ FF\t00D\ CR\t00E\ SO\t00F\ SI\t010\ DLE\t011\ DC1
259 .It "\&012\ DC2\t013\ DC3\t014\ DC4\t015\ NAK\t016\ SYN\t017\ ETB
260 .It "\&018\ CAN\t019\ EM\t01A\ SUB\t01B\ ESC\t01C\ FS\t01D\ GS
261 .It "\&01E\ RS\t01F\ US\t0FF\ DEL
262 .El
263 .El
264 .Pp
265 The default and supported byte counts for the conversion characters
266 are as follows:
267 .Bl -tag -width  "Xc,_Xc,_Xc,_Xc,_Xc,_Xc" -offset indent
268 .It Li \&%_c , \&%_p , \&%_u , \&%c
269 One byte counts only.
270 .It Xo
271 .Li \&%d , \&%i , \&%o ,
272 .Li \&%u , \&%X , \&%x
273 .Xc
274 Four byte default, one, two and four byte counts supported.
275 .It Xo
276 .Li \&%E , \&%e , \&%f ,
277 .Li \&%G , \&%g
278 .Xc
279 Eight byte default, four and twelve byte counts supported.
280 .El
281 .Pp
282 The amount of data interpreted by each format string is the sum of the
283 data required by each format unit, which is the iteration count times the
284 byte count, or the iteration count times the number of bytes required by
285 the format if the byte count is not specified.
286 .Pp
287 The input is manipulated in ``blocks'', where a block is defined as the
288 largest amount of data specified by any format string.
289 Format strings interpreting less than an input block's worth of data,
290 whose last format unit both interprets some number of bytes and does
291 not have a specified iteration count, have the iteration count
292 incremented until the entire input block has been processed or there
293 is not enough data remaining in the block to satisfy the format string.
294 .Pp
295 If, either as a result of user specification or
296 .Nm
297 modifying
298 the iteration count as described above, an iteration count is
299 greater than one, no trailing whitespace characters are output
300 during the last iteration.
301 .Pp
302 It is an error to specify a byte count as well as multiple conversion
303 characters or strings unless all but one of the conversion characters
304 or strings is
305 .Cm \&_a
306 or
307 .Cm \&_A .
308 .Pp
309 If, as a result of the specification of the
310 .Fl n
311 option or end-of-file being reached, input data only partially
312 satisfies a format string, the input block is zero-padded sufficiently
313 to display all available data (i.e. any format units overlapping the
314 end of data will display some number of the zero bytes).
315 .Pp
316 Further output by such format strings is replaced by an equivalent
317 number of spaces.
318 An equivalent number of spaces is defined as the number of spaces
319 output by an
320 .Cm s
321 conversion character with the same field width
322 and precision as the original conversion character or conversion
323 string but with any
324 .Dq Li \&+ ,
325 .Dq \&\ \& ,
326 .Dq Li \&#
327 conversion flag characters
328 removed, and referencing a NULL string.
329 .Pp
330 If no format strings are specified, the default display is equivalent
331 to specifying the
332 .Fl x
333 option.
334 .Sh DIAGNOSTICS
335 .Ex -std hexdump hd
336 .Sh EXAMPLES
337 Display the input in perusal format:
338 .Bd -literal -offset indent
339 "%06.6_ao "  12/1 "%3_u "
340 "\et\et" "%_p "
341 "\en"
342 .Ed
343 .Pp
344 Implement the \-x option:
345 .Bd -literal -offset indent
346 "%07.7_Ax\en"
347 "%07.7_ax  " 8/2 "%04x " "\en"
348 .Ed
349 .Sh SEE ALSO
350 .Xr gdb 1