use btree instead of hashing, don't have to resort later
[unix-history] / usr / src / usr.bin / hexdump / hexdump.1
CommitLineData
dd9e2e8d 1.\" Copyright (c) 1989, 1990 The Regents of the University of California.
d9d7a9f0
CL
2.\" All rights reserved.
3.\"
263cc8fc 4.\" %sccs.include.redist.roff%
d9d7a9f0 5.\"
263cc8fc 6.\" @(#)hexdump.1 5.12 (Berkeley) %G%
d9d7a9f0
CL
7.\"
8.Dd
d9d7a9f0 9.Dt HEXDUMP 1
ee9b0a0a 10.Os
d9d7a9f0
CL
11.Sh NAME
12.Nm hexdump
13.Nd ascii, decimal, hexadecimal, octal dump
14.Sh SYNOPSIS
6a55f534 15.Nm hexdump
d9d7a9f0 16.Op Fl bcdovx
6a55f534
CL
17.Op Fl e Ar format_string
18.Op Fl f Ar format_file
19.Op Fl n Ar length
263cc8fc 20.Bk -words
6a55f534 21.Op Fl s Ar skip
263cc8fc 22.Ek
6a55f534 23.Ar file ...
d9d7a9f0 24.Sh DESCRIPTION
6a55f534 25The hexdump utility is a filter which displays the specified files, or
90e4be46
KB
26the standard input, if no files are specified, in a user specified
27format.
d9d7a9f0 28.Pp
90e4be46 29The options are as follows:
263cc8fc
CL
30.Bl -tag -width Fl
31.It Fl b
6a55f534 32.Em One-byte octal display .
90e4be46
KB
33Display the input offset in hexadecimal, followed by sixteen
34space-separated, three column, zero-filled, bytes of input data,
35in octal, per line.
263cc8fc 36.It Fl c
6a55f534 37.Em One-byte character display .
90e4be46
KB
38Display the input offset in hexadecimal, followed by sixteen
39space-separated, three column, space-filled, characters of input
40data per line.
263cc8fc 41.It Fl d
5325ced3 42.Em Two-byte decimal display.
90e4be46
KB
43Display the input offset in hexadecimal, followed by eight
44space-separated, five column, zero-filled, two-byte units
45of input data, in unsigned decimal, per line.
263cc8fc 46.It Fl e Ar format_string
90e4be46 47Specify a format string to be used for displaying data.
263cc8fc 48.It Fl f Ar format_file
90e4be46
KB
49Specify a file that contains one or more newline separated format strings.
50Empty lines and lines whose first non-blank character is a hash mark
263cc8fc 51.Pf ( Cm \&# )
5325ced3 52are ignored.
263cc8fc 53.It Fl n Ar length
90e4be46 54Interpret only
d9d7a9f0 55.Ar length
90e4be46 56bytes of input.
263cc8fc 57.It Fl o
5325ced3 58.Em Two-byte octal display.
90e4be46
KB
59Display the input offset in hexadecimal, followed by eight
60space-separated, six column, zero-filled, two byte quantities of
61input data, in octal, per line.
263cc8fc 62.It Fl s Ar offset
90e4be46 63Skip
d9d7a9f0 64.Ar offset
90e4be46
KB
65bytes from the beginning of the input.
66By default,
d9d7a9f0 67.Ar offset
90e4be46 68is interpreted as a decimal number.
5325ced3
CL
69With a leading
70.Cm 0x
71or
72.Cm 0X ,
d9d7a9f0 73.Ar offset
90e4be46 74is interpreted as a hexadecimal number,
5325ced3
CL
75otherwise, with a leading
76.Cm 0 ,
d9d7a9f0 77.Ar offset
90e4be46 78is interpreted as an octal number.
5325ced3
CL
79Appending the character
80.Cm b ,
81.Cm k ,
82or
83.Cm m
84to
d9d7a9f0 85.Ar offset
5325ced3
CL
86causes it to be interpreted as a multiple of
87.Li 512 ,
88.Li 1024 ,
89or
90.Li 1048576 ,
90e4be46 91respectively.
263cc8fc 92.It Fl v
90e4be46 93The
d9d7a9f0 94.Fl v
90e4be46
KB
95option causes hexdump to display all input data.
96Without the
d9d7a9f0 97.Fl v
90e4be46
KB
98option, any number of groups of output lines, which would be
99identical to the immediately preceding group of output lines (except
100for the input offsets), are replaced with a line comprised of a
101single asterisk.
263cc8fc 102.It Fl x
5325ced3 103.Em Two-byte hexadecimal display.
594c68cf
KB
104Display the input offset in hexadecimal, followed by eight, space
105separated, four column, zero-filled, two-byte quantities of input
106data, in hexadecimal, per line.
263cc8fc 107.El
d9d7a9f0 108.Pp
90e4be46 109For each input file,
d9d7a9f0 110.Nm hexdump
90e4be46
KB
111sequentially copies the input to standard output, transforming the
112data according to the format strings specified by the
d9d7a9f0 113.Fl e
90e4be46 114and
d9d7a9f0 115.Fl f
90e4be46 116options, in the order that they were specified.
6a55f534 117.Ss Formats
90e4be46
KB
118A format string contains any number of format units, separated by
119whitespace.
120A format unit contains up to three items: an iteration count, a byte
121count, and a format.
d9d7a9f0 122.Pp
90e4be46
KB
123The iteration count is an optional positive integer, which defaults to
124one.
125Each format is applied iteration count times.
d9d7a9f0 126.Pp
90e4be46
KB
127The byte count is an optional positive integer.
128If specified it defines the number of bytes to be interpreted by
129each iteration of the format.
d9d7a9f0 130.Pp
90e4be46
KB
131If an iteration count and/or a byte count is specified, a single slash
132must be placed after the iteration count and/or before the byte count
133to disambiguate them.
134Any whitespace before or after the slash is ignored.
d9d7a9f0 135.Pp
90e4be46
KB
136The format is required and must be surrounded by double quote
137(" ") marks.
5325ced3
CL
138It is interpreted as a fprintf-style format string (see
139.Xr fprintf 3 ) ,
140with the
90e4be46 141following exceptions:
263cc8fc
CL
142.Bl -bullet -offset indent
143.It
5325ced3 144An asterisk (*) may not be used as a field width or precision.
263cc8fc 145.It
5325ced3
CL
146A byte count or field precision
147.Em is
148required for each ``s'' conversion
149character (unlike the
150.Xr fprintf 3
151default which prints the entire string if the precision is unspecified).
263cc8fc 152.It
277bce47 153The conversion characters ``h'', ``n'', and ``p'' are not
90e4be46 154supported.
263cc8fc 155.It
6a55f534
CL
156The single character escape sequences
157described in the C standard are supported:
263cc8fc
CL
158.Bd -ragged -offset indent -compact
159.Bl -column <alert_character>
160.It NUL \e0
161.It <alert character> \ea
162.It <backspace> \eb
163.It <form-feed> \ef
164.It <newline> \en
165.It <carriage return> \er
166.It <tab> \et
167.It <vertical tab> \ev
168.El
169.Ed
170.El
d9d7a9f0 171.Pp
90e4be46 172Hexdump also supports the the following additional conversion strings:
263cc8fc
CL
173.Bl -tag -width Fl
174.It Cm \&_a Ns Op Cm dox
90e4be46
KB
175Display the input offset, cumulative across input files, of the
176next byte to be displayed.
5325ced3
CL
177The appended characters
178.Cm d ,
179.Cm o ,
180and
181.Cm x
182specify the display base
90e4be46 183as decimal, octal or hexadecimal respectively.
263cc8fc 184.It Cm \&_A Ns Op Cm dox
5325ced3
CL
185Identical to the
186.Cm \&_a
187conversion string except that it is only performed
90e4be46 188once, when all of the input data has been processed.
263cc8fc 189.It Cm \&_c
90e4be46 190Output characters in the default character set.
837340b9 191Nonprinting characters are displayed in three character, zero-padded
5325ced3
CL
192octal, except for those representable by standard escape notation
193(see above),
194which are displayed as two character strings.
263cc8fc 195.It Cm _p
90e4be46 196Output characters in the default character set.
5325ced3
CL
197Nonprinting characters are displayed as a single
198.Dq Cm \&. .
263cc8fc 199.It Cm _u
90e4be46
KB
200Output US ASCII characters, with the exception that control characters are
201displayed using the following, lower-case, names.
202Characters greater than 0xff, hexadecimal, are displayed as hexadecimal
203strings.
263cc8fc
CL
204.Bl -column \&000_nu \&001_so \&002_st \&003_et \&004_eo
205.It \&000\ nul\t001\ soh\t002\ stx\t003\ etx\t004\ eot\t005\ enq
206.It \&006\ ack\t007\ bel\t008\ bs\t009\ ht\t00A\ lf\t00B\ vt
207.It \&00C\ ff\t00D\ cr\t00E\ so\t00F\ si\t010\ dle\t011\ dc1
208.It \&012\ dc2\t013\ dc3\t014\ dc4\t015\ nak\t016\ syn\t017\ etb
209.It \&018\ can\t019\ em\t01A\ sub\t01B\ esc\t01C\ fs\t01D\ gs
210.It \&01E\ rs\t01F\ us\t0FF\ del
211.El
212.El
6a55f534 213.Pp
277bce47
KB
214The default and supported byte counts for the conversion characters
215are as follows:
263cc8fc
CL
216.Bl -tag -width "Xc,_Xc,_Xc,_Xc,_Xc,_Xc" -offset indent
217.It Li \&%_c , \&%_p , \&%_u , \&%c
277bce47 218One byte counts only.
263cc8fc
CL
219.It Xo
220.Li \&%d , \&%i , \&%o ,
221.Li \&%u , \&%X , \&%x
222.Xc
277bce47 223Four byte default, one and two byte counts supported.
263cc8fc
CL
224.It Xo
225.Li \&%E , \&%e , \&%f ,
226.Li \&%G , \&%g
227.Xc
277bce47 228Eight byte default, four byte counts supported.
263cc8fc 229.El
d9d7a9f0 230.Pp
90e4be46
KB
231The amount of data interpreted by each format string is the sum of the
232data required by each format unit, which is the iteration count times the
233byte count, or the iteration count times the number of bytes required by
234the format if the byte count is not specified.
d9d7a9f0 235.Pp
90e4be46
KB
236The input is manipulated in ``blocks'', where a block is defined as the
237largest amount of data specified by any format string.
238Format strings interpreting less than an input block's worth of data,
239whose last format unit both interprets some number of bytes and does
240not have a specified iteration count, have the the interation count
241incremented until the entire input block has been processed or there
242is not enough data remaining in the block to satisfy the format string.
d9d7a9f0 243.Pp
90e4be46
KB
244If, either as a result of user specification or hexdump modifying
245the iteration count as described above, an iteration count is
246greater than one, no trailing whitespace characters are output
247during the last iteration.
d9d7a9f0 248.Pp
90e4be46
KB
249It is an error to specify a byte count as well as multiple conversion
250characters or strings unless all but one of the conversion characters
5325ced3
CL
251or strings is
252.Cm \&_a
253or
254.Cm \&_A .
d9d7a9f0 255.Pp
90e4be46 256If, as a result of the specification of the
d9d7a9f0 257.Fl n
90e4be46
KB
258option or end-of-file being reached, input data only partially
259satisfies a format string, the input block is zero-padded sufficiently
260to display all available data (i.e. any format units overlapping the
261end of data will display some number of the zero bytes).
d9d7a9f0 262.Pp
90e4be46
KB
263Further output by such format strings is replaced by an equivalent
264number of spaces.
265An equivalent number of spaces is defined as the number of spaces
5325ced3
CL
266output by an
267.Cm s
268conversion character with the same field width
90e4be46 269and precision as the original conversion character or conversion
5325ced3
CL
270string but with any
271.Dq Li \&+ ,
272.Dq \&\ \& ,
273.Dq Li \&#
274conversion flag characters
90e4be46 275removed, and referencing a NULL string.
d9d7a9f0 276.Pp
90e4be46 277If no format strings are specified, the default display is equivalent
594c68cf 278to specifying the
d9d7a9f0 279.Fl x
594c68cf 280option.
d9d7a9f0 281.Pp
5325ced3 282.Nm hexdump
90e4be46 283exits 0 on success and >0 if an error occurred.
d9d7a9f0 284.Sh EXAMPLES
90e4be46 285Display the input in perusal format:
263cc8fc 286.Bd -literal -offset indent
6a55f534 287"%06.6_ao " 12/1 "%3_u "
90e4be46 288"\et\et" "%_p "
90e4be46 289"\en"
263cc8fc 290.Ed
6a55f534 291.Pp
810e1e77 292Implement the \-x option:
263cc8fc 293.Bd -literal -offset indent
810e1e77 294"%07.7_Ax\en"
6a55f534 295"%07.7_ax " 8/2 "%04x " "\en"
263cc8fc 296.Ed
5325ced3
CL
297.Sh SEE ALSO
298.Xr adb 1
6a55f534
CL
299.Sh STANDARDS
300The
5325ced3 301.Nm hexdump
263cc8fc
CL
302utility is expected to be
303.St -p1003.2
304compatible.