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