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