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