]> git.ipfire.org Git - thirdparty/util-linux.git/blob - text-utils/hexdump.1
docs: make hexdump.1 color specification easier to understand
[thirdparty/util-linux.git] / text-utils / hexdump.1
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 .\" from: @(#)hexdump.1 8.2 (Berkeley) 4/18/94
33 .\"
34 .TH HEXDUMP "1" "April 2013" "util-linux" "User Commands"
35 .SH NAME
36 hexdump \- display file contents in ascii, decimal, hexadecimal, or octal
37 .SH SYNOPSIS
38 .B hexdump
39 [options] file [...]
40 .SH DESCRIPTION
41 The
42 .B hexdump
43 utility is a filter which displays the specified files, or
44 standard input if no files are specified, in a user-specified
45 format.
46 .SH OPTIONS
47 The \fIlength\fR and \fIoffset\fR arguments may be followed by the multiplicative
48 suffixes KiB=1024, MiB=1024*1024, and so on for GiB, TiB, PiB, EiB, ZiB and YiB
49 (the "iB" is optional, e.g. "K" has the same meaning as "KiB") or the suffixes
50 KB=1000, MB=1000*1000, and so on for GB, TB, PB, EB, ZB and YB.
51 .TP
52 \fB\-b\fR, \fB\-\-one\-byte\-octal\fR
53 \fIOne-byte octal display\fR. Display the input offset in hexadecimal,
54 followed by sixteen space-separated, three-column, zero-filled bytes of input
55 data, in octal, per line.
56 .TP
57 \fB\-c\fR, \fB\-\-one\-byte\-char\fR
58 \fIOne-byte character display\fR. Display the input offset in hexadecimal,
59 followed by sixteen space-separated, three-column, space-filled characters of
60 input data per line.
61 .TP
62 \fB\-C\fR, \fB\-\-canonical\fR
63 \fICanonical hex+ASCII display\fR. Display the input offset in hexadecimal,
64 followed by sixteen space-separated, two-column, hexadecimal bytes, followed
65 by the same sixteen bytes in
66 .B %_p
67 format enclosed in
68 .RB ' | '
69 characters.
70 .TP
71 \fB\-d\fR, \fB\-\-two\-bytes\-decimal\fR
72 \fITwo-byte decimal display\fR. Display the input offset in hexadecimal,
73 followed by eight space-separated, five-column, zero-filled, two-byte units
74 of input data, in unsigned decimal, per line.
75 .TP
76 \fB\-e\fR, \fB\-\-format\fR \fIformat_string\fR
77 Specify a format string to be used for displaying data.
78 .TP
79 \fB\-r\fR, \fB\-\-format\-file\fR \fIfile\fR
80 Specify a file that contains one or more newline separated format strings.
81 Empty lines and lines whose first non-blank character is a hash mark (\&#)
82 are ignored.
83 .TP
84 \fB\-n\fR, \fB\-\-length\fR \fIlength\fR
85 Interpret only
86 .I length
87 bytes of input.
88 .TP
89 \fB\-o\fR, \fB\-\-two\-bytes\-octal\fR
90 \fITwo-byte octal display\fR. Display the input offset in hexadecimal,
91 followed by eight space-separated, six-column, zero-filled, two-byte
92 quantities of input data, in octal, per line.
93 .TP
94 \fB\-s\fR, \fB\-\-skip\fR \fIoffset\fR
95 Skip
96 .I offset
97 bytes from the beginning of the input.
98 .TP
99 \fB\-v\fR, \fB\-\-no\-squeezing\fR
100 The
101 .B \-v
102 option causes
103 .B hexdump
104 to display all input data. Without the
105 .B \-v
106 option, any number of groups of output lines which would be identical to the
107 immediately preceding group of output lines (except for the input offsets),
108 are replaced with a line comprised of a single asterisk.
109 .TP
110 \fB\-x\fR, \fB\-\-two\-bytes\-hex\fR
111 \fITwo-byte hexadecimal display\fR. Display the input offset in hexadecimal,
112 followed by eight space-separated, four-column, zero-filled, two-byte
113 quantities of input data, in hexadecimal, per line.
114 .PP
115 For each input file,
116 .B hexdump
117 sequentially copies the input to standard output, transforming the data
118 according to the format strings specified by the
119 .B \-e
120 and
121 .B \-f
122 options, in the order that they were specified.
123 .SH FORMATS
124 A format string contains any number of format units, separated by whitespace.
125 A format unit contains up to three items: an iteration count, a byte count,
126 and a format.
127 .PP
128 The iteration count is an optional positive integer, which defaults to one.
129 Each format is applied iteration count times.
130 .PP
131 The byte count is an optional positive integer. If specified it defines the
132 number of bytes to be interpreted by each iteration of the format.
133 .PP
134 If an iteration count and/or a byte count is specified, a single slash must
135 be placed after the iteration count and/or before the byte count to
136 disambiguate them. Any whitespace before or after the slash is ignored.
137 .PP
138 The format is required and must be surrounded by double quote (" ") marks.
139 It is interpreted as a fprintf-style format string (see
140 .BR fprintf (3),
141 with the following exceptions:
142 .TP
143 1.
144 An asterisk (*) may not be used as a field width or precision.
145 .TP
146 2.
147 A byte count or field precision
148 .I is
149 required for each
150 .B s
151 conversion character (unlike the
152 .BR fprintf (3)
153 default which prints the entire string if the precision is unspecified).
154 .TP
155 3.
156 The conversion characters
157 .BR h , \ l , \ n , \ p ,
158 .RB and \ q
159 are not supported.
160 .TP
161 4.
162 The single character escape sequences described in the C standard are
163 supported:
164 .PP
165 .RS 13
166 .PD 0
167 .TP 21
168 NULL
169 \e0
170 .TP
171 <alert character>
172 \ea
173 .TP
174 <backspace>
175 \eb
176 .TP
177 <form-feed>
178 \ef
179 .TP
180 <newline>
181 \en
182 .TP
183 <carriage return>
184 \er
185 .TP
186 <tab>
187 \et
188 .TP
189 <vertical tab>
190 \ev
191 .PD
192 .RE
193 .PP
194 .SS Conversion strings
195 The
196 .B hexdump
197 utility also supports the following additional conversion strings.
198 .TP
199 .B \&_a[dox]
200 Display the input offset, cumulative across input files, of the next byte to
201 be displayed. The appended characters
202 .BR d ,
203 .BR o ,
204 and
205 .B x
206 specify the display base as decimal, octal or hexadecimal respectively.
207 .TP
208 .B \&_A[dox]
209 Identical to the
210 .B \&_a
211 conversion string except that it is only performed once, when all of the
212 input data has been processed.
213 .TP
214 .B \&_c
215 Output characters in the default character set. Nonprinting characters are
216 displayed in three-character, zero-padded octal, except for those
217 representable by standard escape notation (see above), which are displayed as
218 two-character strings.
219 .TP
220 .B \&_p
221 Output characters in the default character set. Nonprinting characters are
222 displayed as a single
223 .RB ' \&. '.
224 .TP
225 .B \&_u
226 Output US ASCII characters, with the exception that control characters are
227 displayed using the following, lower-case, names. Characters greater than
228 0xff, hexadecimal, are displayed as hexadecimal strings.
229 .RS 10
230 .TS
231 tab(|);
232 left l l l l l.
233 000 nul|001 soh|002 stx|003 etx|004 eot|005 enq
234 006 ack|007 bel|008 bs|009 ht|00A lf|00B vt
235 00C ff|00D cr|00E so|00F si|010 dle|011 dc1
236 012 dc2|013 dc3|014 dc4|015 nak|016 syn|017 etb
237 018 can|019 em|01A sub|01B esc|01C fs|01D gs
238 01E rs|01F us|0FF del
239 .TE
240 .SS Colors
241 When put at the end of a format specifier, hexdump highlights the
242 respective string with the color specified. Conditions, if present, are
243 evaluated prior to highlighting.
244 .PP
245 .B \&_L[color_unit_1,\:color_unit_2,\:...,\:color_unit_n]
246 .PP
247 The full syntax of a color unit is as follows:
248 .PP
249 .B [!]COLOR\:[:VALUE]\:[@OFFSET_START[-END]]
250 .TP
251 .B !
252 Negate the condition. Please note that it only makes sense to negate a
253 unit if both a value/\:string and an offset are specified. In that case
254 the respective output string will be highlighted if and only if the
255 value/\:string does not match the one at the offset.
256 .TP
257 .BR COLOR
258 One of the 8 basic shell colors.
259 .TP
260 .B VALUE
261 A value to be matched specified in hexadecimal, or octal base, or as a
262 string. Please note that the usual C escape sequences are not
263 interpreted by hexdump inside the color_units.
264 .TP
265 .B OFFSET
266 An offset or an offset range at which to check for a match. Please note
267 that lone OFFSET_START uses the same value as END offset. Also, the
268 range may not be larger than the respective format byte count.
269 .SS Counters
270 The default and supported byte counts for the conversion characters
271 are as follows:
272 .TP
273 .BR \&%_c , \ \&%_p , \ \&%_u , \ \&%c
274 One byte counts only.
275 .TP
276 .BR \&%d , \ \&%i , \ \&%o , \ \&%u , \ \&%X , \ \&%x
277 Four byte default, one, two and four byte counts supported.
278 .TP
279 .BR \&%E , \ \&%e , \ \&%f , \ \&%G , \ \&%g
280 Eight byte default, four byte counts supported.
281 .PP
282 The amount of data interpreted by each format string is the sum of the data
283 required by each format unit, which is the iteration count times the byte
284 count, or the iteration count times the number of bytes required by the
285 format if the byte count is not specified.
286 .PP
287 The input is manipulated in
288 .IR blocks ,
289 where a block is defined as the largest amount of data specified by any
290 format string. Format strings interpreting less than an input block's worth
291 of data, whose last format unit both interprets some number of bytes and does
292 not have a specified iteration count, have the iteration count incremented
293 until the entire input block has been processed or there is not enough data
294 remaining in the block to satisfy the format string.
295 .PP
296 If, either as a result of user specification or
297 .B hexdump
298 modifying the iteration count as described above, an iteration count is
299 greater than one, no trailing whitespace characters are output during the
300 last iteration.
301 .PP
302 It is an error to specify a byte count as well as multiple conversion
303 characters or strings unless all but one of the conversion characters or
304 strings is
305 .B \&_a
306 or
307 .BR \&_A .
308 .PP
309 If, as a result of the specification of the
310 .B \-n
311 option or end-of-file being reached, input data only partially satisfies a
312 format string, the input block is zero-padded sufficiently to display all
313 available data (i.e. any format units overlapping the end of data will
314 display some number of the zero bytes).
315 .PP
316 Further output by such format strings is replaced by an equivalent number of
317 spaces. An equivalent number of spaces is defined as the number of spaces
318 output by an
319 .B s
320 conversion character with the same field width and precision as the original
321 conversion character or conversion string but with any
322 .RB ' \&+ ',
323 \' \',
324 .RB ' \&# '
325 conversion flag characters removed, and referencing a NULL string.
326 .PP
327 If no format strings are specified, the default display is equivalent
328 to specifying the
329 .B \-x
330 option.
331 .SH "EXIT STATUS"
332 .B hexdump
333 exits 0 on success and >0 if an error occurred.
334 .SH EXAMPLES
335 Display the input in perusal format:
336 .nf
337 "%06.6_ao " 12/1 "%3_u "
338 "\et\et" "%_p "
339 "\en"
340 .nf
341 .PP
342 Implement the \-x option:
343 .nf
344 "%07.7_Ax\en"
345 "%07.7_ax " 8/2 "%04x " "\en"
346 .nf
347 .PP
348 MBR Boot Signature example: Highlight the addresses cyan and the bytes at
349 offsets 510 and 511 green if their value is 0xAA55, red otherwise.
350 .nf
351 "%07.7_Ax_L[cyan]\en"
352 "%07.7_ax_L[cyan] " 8/2 " %04x_L[green:0xAA55@510-511,!red:0xAA55@510-511] " "\en"
353 .nf
354 .SH STANDARDS
355 The
356 .B hexdump
357 utility is expected to be IEEE Std 1003.2 ("POSIX.2") compatible.
358 .SH AVAILABILITY
359 The hexdump command is part of the util-linux package and is available from
360 .UR ftp://\:ftp.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
361 Linux Kernel Archive
362 .UE .