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