xref: /csrg-svn/usr.bin/hexdump/hexdump.1 (revision 44280)
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.8 (Berkeley) 06/26/90
7.\"
8.Dd
9.Dt HEXDUMP 1
10.Os BSD 4.4
11.Sh NAME
12.Nm hexdump
13.Nd ascii, decimal, hexadecimal, octal dump
14.Sh SYNOPSIS
15.Ar hexdump
16.Op Fl bcdovx
17.Op Fl e format_string
18.Op Fl f format_file
19.Op Fl n length
20.Op Fl s skip
21.Op
22.Ar file  . . .
23.Sh DESCRIPTION
24The hexdump utility is a filter that displays the specified files, or
25the standard input, if no files are specified, in a user specified
26format.
27.Pp
28The options are as follows:
29.Tp
30-b
31One-byte octal display.
32.Pp
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
37-c
38One-byte character display.
39.Pp
40Display the input offset in hexadecimal, followed by sixteen
41space-separated, three column, space-filled, characters of input
42data per line.
43.Tp
44-d
45Two-byte decimal display.
46.Pp
47Display the input offset in hexadecimal, followed by eight
48space-separated, five column, zero-filled, two-byte units
49of input data, in unsigned decimal, per line.
50.Tp
51-e
52Specify a format string to be used for displaying data.
53.Tp
54-f
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(#) are ignored.
58.Tp
59-n
60Interpret only
61.Ar length
62bytes of input.
63.Tp
64-o
65Two-byte octal display.
66.Pp
67Display the input offset in hexadecimal, followed by eight
68space-separated, six column, zero-filled, two byte quantities of
69input data, in octal, per line.
70.Tp
71-s
72Skip
73.Ar offset
74bytes from the beginning of the input.
75By default,
76.Ar offset
77is interpreted as a decimal number.
78With a leading ``0x'' or ``0X'',
79.Ar offset
80is interpreted as a hexadecimal number,
81otherwise, with a leading ``0'',
82.Ar offset
83is interpreted as an octal number.
84Appending the character ``b'', ``k'', or ``m'' to
85.Ar offset
86causes it to be interpreted as a multiple of 512, 1024, or 1048576,
87respectively.
88.Tp
89-v
90The
91.Fl v
92option causes hexdump to display all input data.
93Without the
94.Fl v
95option, any number of groups of output lines, which would be
96identical to the immediately preceding group of output lines (except
97for the input offsets), are replaced with a line comprised of a
98single asterisk.
99.Tp
100-x
101Two-byte hexadecimal display.
102.Pp
103Display the input offset in hexadecimal, followed by eight, space
104separated, four column, zero-filled, two-byte quantities of input
105data, in hexadecimal, per line.
106.Pp
107For each input file,
108.Nm hexdump
109sequentially copies the input to standard output, transforming the
110data according to the format strings specified by the
111.Fl e
112and
113.Fl f
114options, in the order that they were specified.
115.Pp
116A format string contains any number of format units, separated by
117whitespace.
118A format unit contains up to three items: an iteration count, a byte
119count, and a format.
120.Pp
121The iteration count is an optional positive integer, which defaults to
122one.
123Each format is applied iteration count times.
124.Pp
125The byte count is an optional positive integer.
126If specified it defines the number of bytes to be interpreted by
127each iteration of the format.
128.Pp
129If an iteration count and/or a byte count is specified, a single slash
130must be placed after the iteration count and/or before the byte count
131to disambiguate them.
132Any whitespace before or after the slash is ignored.
133.Pp
134The format is required and must be surrounded by double quote
135(" ") marks.
136It is interpreted as a fprintf-style format string, with the
137following exceptions:
138.Tp
139.Ar \ (bu
140An asterisk (*) may not be used as a field width or precision.
141.Tp
142.Ar \ (bu
143A byte count or field precision is required for each ``s'' conversion
144character.
145.Tp
146.Ar \ (bu
147The conversion characters ``h'', ``n'', and ``p'' are not
148supported.
149.Tp
150.Ar \ (bu
151The single character escape sequences (\ea, \eb, \ef, \en, \er,
152\et, and \ev) described in the C standard are supported.
153.Pp
154Hexdump also supports the the following additional conversion strings:
155.Pp
156.Tp
157_a
158.Op dox
159Display the input offset, cumulative across input files, of the
160next byte to be displayed.
161The appended characters ``d'', ``o'', and ``x'' specify the display base
162as decimal, octal or hexadecimal respectively.
163.Tp
164_A
165.Op dox
166Identical to the _a conversion string except that it is only performed
167once, when all of the input data has been processed.
168.Tp
169_c
170Output characters in the default character set.
171Nonprinting characters are displayed in three character, zero-padded
172octal, except for those representable by standard escape notation,
173which are displayed as the following two character strings:
174.in +5
175.TS
176l l.
177NUL	\e0
178<alert character>	\ea
179<backspace>	\eb
180<form-feed>	\ef
181<newline>	\en
182<carriage return>	\er
183<tab>	\et
184<vertical tab>	\ev
185.TE
186.Tp
187_p
188Output characters in the default character set.
189Nonprinting characters are displayed as a single ``.''.
190.Tp
191_u
192Output US ASCII characters, with the exception that control characters are
193displayed using the following, lower-case, names.
194Characters greater than 0xff, hexadecimal, are displayed as hexadecimal
195strings.
196.Pp
197.Tp
198000 nul  001 soh  002 stx  003 etx  004 eot  005 enq
199006 ack  007 bel  008  bs  009  ht  00A  lf  00B  vt
20000C  ff  00D  cr  00E  so  00F  si  010 dle  011 dc1
201012 dc2  013 dc3  014 dc4  015 nak  016 syn  017 etb
202018 can  019  em  01A sub  01B esc  01C  fs  01D  gs
20301E rs   01F  us  0FF del
204.Tp Pp
205The default and supported byte counts for the conversion characters
206are as follows:
207.Tp
208"%_c, %_p, %_u, %c"
209One byte counts only.
210.Tp
211"%d, %i, %o, %u, %X, %x"
212Four byte default, one and two byte counts supported.
213.Tp
214"%E, %e, %f, %G, %g"
215Eight byte default, four byte counts supported.
216.Pp
217The amount of data interpreted by each format string is the sum of the
218data required by each format unit, which is the iteration count times the
219byte count, or the iteration count times the number of bytes required by
220the format if the byte count is not specified.
221.Pp
222The input is manipulated in ``blocks'', where a block is defined as the
223largest amount of data specified by any format string.
224Format strings interpreting less than an input block's worth of data,
225whose last format unit both interprets some number of bytes and does
226not have a specified iteration count, have the the interation count
227incremented until the entire input block has been processed or there
228is not enough data remaining in the block to satisfy the format string.
229.Pp
230If, either as a result of user specification or hexdump modifying
231the iteration count as described above, an iteration count is
232greater than one, no trailing whitespace characters are output
233during the last iteration.
234.Pp
235It is an error to specify a byte count as well as multiple conversion
236characters or strings unless all but one of the conversion characters
237or strings is ``_a'' or ``_A''.
238.Pp
239If, as a result of the specification of the
240.Fl n
241option or end-of-file being reached, input data only partially
242satisfies a format string, the input block is zero-padded sufficiently
243to display all available data (i.e. any format units overlapping the
244end of data will display some number of the zero bytes).
245.Pp
246Further output by such format strings is replaced by an equivalent
247number of spaces.
248An equivalent number of spaces is defined as the number of spaces
249output by an ``s'' conversion character with the same field width
250and precision as the original conversion character or conversion
251string but with any ``+'', `` '', or ``#'' conversion flag characters
252removed, and referencing a NULL string.
253.Pp
254If no format strings are specified, the default display is equivalent
255to specifying the
256.Fl x
257option.
258.Pp
259.Nm Hexdump
260exits 0 on success and >0 if an error occurred.
261.Sh EXAMPLES
262Display the input in perusal format:
263.Pp
264.Tp
265"%06.6_ao
266.Ar 12/1 "%3_u "
267.br
268"\et\et" "%_p "
269.br
270"\en"
271.Tp Pp
272Implement the \-x option:
273.Pp
274.Tp
275"%07.7_Ax\en"
276.br
277"%07.7_ax
278.Ar 8/2 "%04x
279.Ar "\en"
280.Tp
281-PTXX FROM- 4.3
282-ENV USAGE-
283-MANPAGE HISTORY-
284/usr/src/usr.bin/hexdump/odsyntax.c:	while ((ch = getopt(argc, argv, "aBbcDdeFfHhIiLlOoPpswvXx")) != EOF)
285/usr/src/usr.bin/hexdump/hexsyntax.c:	while ((ch = getopt(argc, argv, "bcde:f:n:os:vx")) != EOF)
286/usr/src/usr.bin/hexdump/odsyntax.c:	while ((ch = getopt(argc, argv, "aBbcDdeFfHhIiLlOoPpswvXx")) != EOF)
287/usr/src/usr.bin/hexdump/hexsyntax.c:	while ((ch = getopt(argc, argv, "bcde:f:n:os:vx")) != EOF)
288