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