xref: /freebsd/usr.bin/hexdump/hexdump.1 (revision e627b39baccd1ec9129690167cf5e6d860509655)
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.\"
34.Dd April 18, 1994
35.Dt HEXDUMP 1
36.Os
37.Sh NAME
38.Nm hexdump, hd
39.Nd ascii, decimal, hexadecimal, octal dump
40.Sh SYNOPSIS
41.Nm hexdump
42.Op Fl bcCdovx
43.Op Fl e Ar format_string
44.Op Fl f Ar format_file
45.Op Fl n Ar length
46.Bk -words
47.Op Fl s Ar skip
48.Ek
49.Ar file  ...
50.Nm hd
51.Op Fl bcdovx
52.Op Fl e Ar format_string
53.Op Fl f Ar format_file
54.Op Fl n Ar length
55.Bk -words
56.Op Fl s Ar skip
57.Ek
58.Ar file  ...
59.Sh DESCRIPTION
60The hexdump utility 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 Fl
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
137The
138.Fl v
139option causes hexdump to 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 hexdump
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	\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
216Hexdump also supports the the following additional conversion strings:
217.Bl -tag -width Fl
218.It Cm \&_a Ns Op Cm dox
219Display the input offset, cumulative across input files, of the
220next byte to be displayed.
221The appended characters
222.Cm d ,
223.Cm o ,
224and
225.Cm x
226specify the display base
227as decimal, octal or hexadecimal respectively.
228.It Cm \&_A Ns Op Cm dox
229Identical to the
230.Cm \&_a
231conversion string except that it is only performed
232once, when all of the input data has been processed.
233.It Cm \&_c
234Output characters in the default character set.
235Nonprinting characters are displayed in three character, zero-padded
236octal, except for those representable by standard escape notation
237(see above),
238which are displayed as two character strings.
239.It Cm _p
240Output characters in the default character set.
241Nonprinting characters are displayed as a single
242.Dq Cm \&. .
243.It Cm _u
244Output US ASCII characters, with the exception that control characters are
245displayed using the following, lower-case, names.
246Characters greater than 0xff, hexadecimal, are displayed as hexadecimal
247strings.
248.Bl -column \&000_nu \&001_so \&002_st \&003_et \&004_eo
249.It \&000\ nul\t001\ soh\t002\ stx\t003\ etx\t004\ eot\t005\ enq
250.It \&006\ ack\t007\ bel\t008\ bs\t009\ ht\t00A\ lf\t00B\ vt
251.It \&00C\ ff\t00D\ cr\t00E\ so\t00F\ si\t010\ dle\t011\ dc1
252.It \&012\ dc2\t013\ dc3\t014\ dc4\t015\ nak\t016\ syn\t017\ etb
253.It \&018\ can\t019\ em\t01A\ sub\t01B\ esc\t01C\ fs\t01D\ gs
254.It \&01E\ rs\t01F\ us\t0FF\ del
255.El
256.El
257.Pp
258The default and supported byte counts for the conversion characters
259are as follows:
260.Bl -tag -width  "Xc,_Xc,_Xc,_Xc,_Xc,_Xc" -offset indent
261.It Li \&%_c , \&%_p , \&%_u , \&%c
262One byte counts only.
263.It Xo
264.Li \&%d , \&%i , \&%o ,
265.Li \&%u , \&%X , \&%x
266.Xc
267Four byte default, one, two and four byte counts supported.
268.It Xo
269.Li \&%E , \&%e , \&%f ,
270.Li \&%G , \&%g
271.Xc
272Eight byte default, four byte counts supported.
273.El
274.Pp
275The amount of data interpreted by each format string is the sum of the
276data required by each format unit, which is the iteration count times the
277byte count, or the iteration count times the number of bytes required by
278the format if the byte count is not specified.
279.Pp
280The input is manipulated in ``blocks'', where a block is defined as the
281largest amount of data specified by any format string.
282Format strings interpreting less than an input block's worth of data,
283whose last format unit both interprets some number of bytes and does
284not have a specified iteration count, have the iteration count
285incremented until the entire input block has been processed or there
286is not enough data remaining in the block to satisfy the format string.
287.Pp
288If, either as a result of user specification or hexdump modifying
289the iteration count as described above, an iteration count is
290greater than one, no trailing whitespace characters are output
291during the last iteration.
292.Pp
293It is an error to specify a byte count as well as multiple conversion
294characters or strings unless all but one of the conversion characters
295or strings is
296.Cm \&_a
297or
298.Cm \&_A .
299.Pp
300If, as a result of the specification of the
301.Fl n
302option or end-of-file being reached, input data only partially
303satisfies a format string, the input block is zero-padded sufficiently
304to display all available data (i.e. any format units overlapping the
305end of data will display some number of the zero bytes).
306.Pp
307Further output by such format strings is replaced by an equivalent
308number of spaces.
309An equivalent number of spaces is defined as the number of spaces
310output by an
311.Cm s
312conversion character with the same field width
313and precision as the original conversion character or conversion
314string but with any
315.Dq Li \&+ ,
316.Dq \&\ \& ,
317.Dq Li \&#
318conversion flag characters
319removed, and referencing a NULL string.
320.Pp
321If no format strings are specified, the default display is equivalent
322to specifying the
323.Fl x
324option.
325.Pp
326.Nm hexdump
327exits 0 on success and >0 if an error occurred.
328.Sh EXAMPLES
329Display the input in perusal format:
330.Bd -literal -offset indent
331"%06.6_ao "  12/1 "%3_u "
332"\et\et" "%_p "
333"\en"
334.Ed
335.Pp
336Implement the \-x option:
337.Bd -literal -offset indent
338"%07.7_Ax\en"
339"%07.7_ax  " 8/2 "%04x " "\en"
340.Ed
341.Sh SEE ALSO
342.Xr gdb 1
343