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