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