_c should zero-pad the hexnumbers, which should be octal
[unix-history] / usr / src / usr.bin / hexdump / hexdump.1
CommitLineData
90e4be46
KB
1.\" Copyright (c) 1989 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms are permitted
5.\" provided that the above copyright notice and this paragraph are
6.\" duplicated in all such forms and that any documentation,
7.\" advertising materials, and other materials related to such
8.\" distribution and use acknowledge that the software was developed
9.\" by the University of California, Berkeley. The name of the
10.\" University may not be used to endorse or promote products derived
11.\" from this software without specific prior written permission.
12.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15.\"
6d23aef6 16.\" @(#)hexdump.1 5.2 (Berkeley) %G%
90e4be46
KB
17.\"
18.TH HEXDUMP 1 ""
19.UC 7
20.SH NAME
21hexdump - ascii, decimal, hexadecimal, octal dump
22.SH SYNOPSIS
23hexdump
24.ft B
25[
26.I -bcdov
27.ft B
28] [
29.I -e format_string
30.ft B
31] [
32.I -f format_file
33.ft B
34] [
35.I -n length
36.ft B
37] [
38.I -s skip
39.ft B
40] [
41.I file ...
42.ft B
43]
44.ft R
45.SH DESCRIPTION
46The hexdump utility is a filter that displays the specified files, or
47the standard input, if no files are specified, in a user specified
48format.
49.PP
50The options are as follows:
51.TP
52-b
53Display the input offset in hexadecimal, followed by sixteen
54space-separated, three column, zero-filled, bytes of input data,
55in octal, per line.
56It is equivalent to specifying the following format strings:
57.ti +5
58"%07.7_Ax\en"
59.ti +5
60"%07.7_ax " 16/1 "%03o " "\en"
61.TP
62-c
63Display the input offset in hexadecimal, followed by sixteen
64space-separated, three column, space-filled, characters of input
65data per line.
66It is equivalent to specifying the following format strings:
67.ti +5
68"%07.7_Ax\en"
69.ti +5
70"%07.7_ax " 16/1 "%3_c " "\en"
71.TP
72-d
73Display the input offset in hexadecimal, followed by eight
74space-separated, five column, zero-filled, two-byte units
75of input data, in unsigned decimal, per line.
76It is equivalent to specifying the following format strings:
77.ti +5
78"%07.7_Ax\en"
79.ti +5
80"%07.7_ax " 8/2 "%05u " "\en"
81.TP
82-e
83Specify a format string to be used for displaying data.
84.TP
85-f
86Specify a file that contains one or more newline separated format strings.
87Empty lines and lines whose first non-blank character is a hash mark
88(#) are ignored.
89.TP
90-n
91Interpret only
92.I length
93bytes of input.
94.TP
95-o
96Display the input offset in hexadecimal, followed by eight
97space-separated, six column, zero-filled, two byte quantities of
98input data, in octal, per line.
99It is equivalent to specifying the following format strings:
100.ti +5
101"%07.7_Ax\en"
102.ti +5
103"%07.7_ax " 8/2 "%06o " "\en"
104.TP
105-s
106Skip
107.I offset
108bytes from the beginning of the input.
109By default,
110.I offset
111is interpreted as a decimal number.
112With a leading ``0x'' or ``0X'',
113.I offset
114is interpreted as a hexadecimal number,
115otherwise, with a leading ``0'',
116.I offset
117is interpreted as an octal number.
118Appending the character ``b'', ``k'', or ``m'' to
119.I offset
120causes it to be interpreted as a multiple of 512, 1024, or 1048576,
121respectively.
122.TP
123-v
124The
125.I -v
126option causes hexdump to display all input data.
127Without the
128.I -v
129option, any number of groups of output lines, which would be
130identical to the immediately preceding group of output lines (except
131for the input offsets), are replaced with a line comprised of a
132single asterisk.
133.PP
134For each input file,
135.I hexdump
136sequentially copies the input to standard output, transforming the
137data according to the format strings specified by the
138.I -e
139and
140.I -f
141options, in the order that they were specified.
142.PP
143A format string contains any number of format units, separated by
144whitespace.
145A format unit contains up to three items: an iteration count, a byte
146count, and a format.
147.PP
148The iteration count is an optional positive integer, which defaults to
149one.
150Each format is applied iteration count times.
151.PP
152The byte count is an optional positive integer.
153If specified it defines the number of bytes to be interpreted by
154each iteration of the format.
155.PP
156If an iteration count and/or a byte count is specified, a single slash
157must be placed after the iteration count and/or before the byte count
158to disambiguate them.
159Any whitespace before or after the slash is ignored.
160.PP
161The format is required and must be surrounded by double quote
162(" ") marks.
163It is interpreted as a fprintf-style format string, with the
164following exceptions:
165.TP
166.B \(bu
167An asterisk (*) may not be used as a field width or precision.
168.TP
169.B \(bu
170A byte count or field precision is required for each ``s'' conversion
171character.
172.TP
173.B \(bu
174The conversion characters ``h'', ``l'', ``n'', and ``p'' are not
175supported.
176.TP
177.B \(bu
178The single character escape sequences (\ea, \eb, \ef, \en, \er,
179\et, and \ev) described in the C standard are supported.
180.PP
181Hexdump also supports the the following additional conversion strings:
182.PP
183.TP
184_a[dox]
185Display the input offset, cumulative across input files, of the
186next byte to be displayed.
187The appended characters ``d'', ``o'', and ``x'' specify the display base
188as decimal, octal or hexadecimal respectively.
189.TP
190_A[dox]
191Identical to the _a conversion string except that it is only performed
192once, when all of the input data has been processed.
193.TP
194_c
195Output characters in the default character set.
196Nonprinting characters are displayed in hexadecimal, except for those
197representable by standard escape notation, which are displayed
198as follows:
199.in +5
200.TS
201l l.
202NUL \e0
203<alert character> \ea
204<backspace> \eb
205<form-feed> \ef
206<newline> \en
207<carriage return> \er
208<tab> \et
209<vertical tab> \ev
210.TE
211.TP
212_p
213Output characters in the default character set.
214Nonprinting characters are displayed as a single ``.''.
215.TP
216_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.in +5
222.TS
223l l l l l l.
22400 nul 001 soh 002 stx 003 etx 004 eot 005 enq
22506 ack 007 bel 008 bs 009 ht 00A lf 00B vt
2260C ff 00D cr 00E so 00F si 010 dle 011 dc1
22712 dc2 013 dc3 014 dc4 015 nak 016 syn 017 etb
22818 can 019 em 01A sub 01B esc 01C fs 01D gs
22901E rs 01F us 0FF del
230.TE
231.PP
232The default and supported byte counts are as follows:
233.in +5
234.TS
235l l l.
236Conversion type Default (bytes) Other Supported (bytes)
237_
238%_c 1
239%_p 1
240%_u 1
241%c 1
242%d (%i) 4 1, 2
243%o 4 1, 2
244%u 4 1, 2
245%x (%X) 4 1, 2
246%e (%E) 8 4
247%f 8 4
248%g (%G) 8 4
249.TE
250.PP
251The amount of data interpreted by each format string is the sum of the
252data required by each format unit, which is the iteration count times the
253byte count, or the iteration count times the number of bytes required by
254the format if the byte count is not specified.
255.PP
256The input is manipulated in ``blocks'', where a block is defined as the
257largest amount of data specified by any format string.
258Format strings interpreting less than an input block's worth of data,
259whose last format unit both interprets some number of bytes and does
260not have a specified iteration count, have the the interation count
261incremented until the entire input block has been processed or there
262is not enough data remaining in the block to satisfy the format string.
263.PP
264If, either as a result of user specification or hexdump modifying
265the iteration count as described above, an iteration count is
266greater than one, no trailing whitespace characters are output
267during the last iteration.
268.PP
269It is an error to specify a byte count as well as multiple conversion
270characters or strings unless all but one of the conversion characters
271or strings is ``_a'' or ``_A''.
272.PP
273If, as a result of the specification of the
274.I -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 ``s'' conversion character with the same field width
284and precision as the original conversion character or conversion
285string but with any ``+'', `` '', or ``#'' conversion flag characters
286removed, and referencing a NULL string.
90e4be46
KB
287.PP
288If no format strings are specified, the default display is equivalent
289to specifying the following format strings:
290.ti +5
291"%07.7_Ax\en"
292.ti +5
293"%07.7_ax " 8/2 "%04x " "\en"
294.sp
295This displays the input offset in hexadecimal, followed by eight, space
296separated, four column, zero-filled, two-byte quantities of input
297data, in hexadecimal, per line.
298.PP
299.I Hexdump
300exits 0 on success and >0 if an error occurred.
301.SH EXAMPLES
302Display the input in perusal format:
303.sp
304.ti +5
305"%06.6_ao " 12/1 "%3o "
306.ti +5
307"\et\et" "%_p "
308.ti +5
309"\en"