1HEXDUMP(1) User Commands HEXDUMP(1)
2
3
4
6 hexdump - display file contents in hexadecimal, decimal, octal, or
7 ascii
8
10 hexdump [options] file...
11
13 The hexdump utility is a filter which displays the specified files, or
14 standard input if no files are specified, in a user-specified format.
15
17 Below, the length and offset arguments may be followed by the multi‐
18 plicative suffixes KiB (=1024), MiB (=1024*1024), and so on for GiB,
19 TiB, PiB, EiB, ZiB and YiB (the "iB" is optional, e.g., "K" has the
20 same meaning as "KiB"), or the suffixes KB (=1000), MB (=1000*1000),
21 and so on for GB, TB, PB, EB, ZB and YB.
22
23 -b, --one-byte-octal
24 One-byte octal display. Display the input offset in hexadeci‐
25 mal, followed by sixteen space-separated, three-column, zero-
26 filled bytes of input data, in octal, per line.
27
28 -c, --one-byte-char
29 One-byte character display. Display the input offset in hexa‐
30 decimal, followed by sixteen space-separated, three-column,
31 space-filled characters of input data per line.
32
33 -C, --canonical
34 Canonical hex+ASCII display. Display the input offset in hexa‐
35 decimal, followed by sixteen space-separated, two-column, hexa‐
36 decimal bytes, followed by the same sixteen bytes in %_p format
37 enclosed in '|' characters. Invoking the program as hd implies
38 this option.
39
40 -d, --two-bytes-decimal
41 Two-byte decimal display. Display the input offset in hexadeci‐
42 mal, followed by eight space-separated, five-column, zero-
43 filled, two-byte units of input data, in unsigned decimal, per
44 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 for‐
51 mat strings. Empty lines and lines whose first non-blank char‐
52 acter is a hash mark (#) are ignored.
53
54 -L, --color[=when]
55 Accept color units for the output. The optional argument when
56 can be auto, never or always. If the when argument is omitted,
57 it defaults to auto. The colors can be disabled; for the cur‐
58 rent built-in default see the --help output. See also the Col‐
59 ors 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 hexadeci‐
66 mal, 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
74 the -v option, any number of groups of output lines which would
75 be identical to the immediately preceding group of output lines
76 (except for the input offsets), are replaced with a line com‐
77 prised of a single asterisk.
78
79 -x, --two-bytes-hex
80 Two-byte hexadecimal display. Display the input offset in hexa‐
81 decimal, followed by eight space-separated, four-column, zero-
82 filled, two-byte quantities of input data, in hexadecimal, per
83 line.
84
85 -V, --version
86 Display version information and exit.
87
88 -h, --help
89 Display help text 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
104 defines the number of bytes to be interpreted by each iteration of the
105 format.
106
107 If an iteration count and/or a byte count is specified, a single slash
108 must be placed after the iteration count and/or before the byte count
109 to disambiguate them. Any whitespace before or after the slash is
110 ignored.
111
112 The format is required and must be surrounded by double quote (" ")
113 marks. It is interpreted as a fprintf-style format string (see
114 fprintf(3), with the following exceptions:
115
116 1. An asterisk (*) may not be used as a field width or precision.
117
118 2. A byte count or field precision is required for each s conver‐
119 sion character (unlike the fprintf(3) default which prints the
120 entire string if the precision is unspecified).
121
122 3. The conversion characters h, l, n, p, and q are not supported.
123
124 4. The single character escape sequences described in the C stan‐
125 dard are supported:
126
127 NULL \0
128 <alert character> \a
129 <backspace> \b
130 <form-feed> \f
131 <newline> \n
132 <carriage return> \r
133 <tab> \t
134 <vertical tab> \v
135
136 Conversion strings
137 The hexdump utility also supports the following additional conversion
138 strings.
139
140 _a[dox]
141 Display the input offset, cumulative across input files, of the
142 next byte to be displayed. The appended characters d, o, and x
143 specify the display base as decimal, octal or hexadecimal
144 respectively.
145
146 _A[dox]
147 Identical to the _a conversion string except that it is only
148 performed once, when all of the input data has been processed.
149
150 _c Output characters in the default character set. Non-printing
151 characters are displayed in three-character, zero-padded octal,
152 except for those representable by standard escape notation (see
153 above), which are displayed as two-character strings.
154
155 _p Output characters in the default character set. Non-printing
156 characters are displayed as a single '.'.
157
158 _u Output US ASCII characters, with the exception that control
159 characters are displayed using the following, lower-case, names.
160 Characters greater than 0xff, hexadecimal, are displayed as
161 hexadecimal strings.
162
163 000 nul 001 soh 002 stx 003 etx 004 eot 005 enq
164 006 ack 007 bel 008 bs 009 ht 00A lf 00B vt
165 00C ff 00D cr 00E so 00F si 010 dle 011 dc1
166 012 dc2 013 dc3 014 dc4 015 nak 016 syn 017 etb
167 018 can 019 em 01A sub 01B esc 01C fs 01D gs
168 01E rs 01F us 0FF del
169
170 Colors
171 When put at the end of a format specifier, hexdump highlights the
172 respective string with the color specified. Conditions, if present,
173 are evaluated prior to highlighting.
174
175 _L[color_unit_1,color_unit_2,...,color_unit_n]
176
177 The full syntax of a color unit is as follows:
178
179 [!]COLOR[:VALUE][@OFFSET_START[-END]]
180
181 ! Negate the condition. Please note that it only makes sense to
182 negate a unit if both a value/string and an offset are speci‐
183 fied. In that case the respective output string will be high‐
184 lighted if and only if the value/string does not match the one
185 at the offset.
186
187 COLOR One of the 8 basic shell colors.
188
189 VALUE A value to be matched specified in hexadecimal, or octal base,
190 or as a string. Please note that the usual C escape sequences
191 are not interpreted by hexdump inside the color_units.
192
193 OFFSET An offset or an offset range at which to check for a match.
194 Please note that lone OFFSET_START uses the same value as END
195 offset.
196
197 Counters
198 The default and supported byte counts for the conversion characters are
199 as follows:
200
201 %_c, %_p, %_u, %c
202 One byte counts only.
203
204 %d, %i, %o, %u, %X, %x
205 Four byte default, one, two and four byte counts supported.
206
207 %E, %e, %f, %G, %g
208 Eight byte default, four byte counts supported.
209
210 The amount of data interpreted by each format string is the sum of the
211 data required by each format unit, which is the iteration count times
212 the byte count, or the iteration count times the number of bytes
213 required by the format if the byte count is not specified.
214
215 The input is manipulated in blocks, where a block is defined as the
216 largest amount of data specified by any format string. Format strings
217 interpreting less than an input block's worth of data, whose last for‐
218 mat unit both interprets some number of bytes and does not have a spec‐
219 ified iteration count, have the iteration count incremented until the
220 entire input block has been processed or there is not enough data
221 remaining in the block to satisfy the format string.
222
223 If, either as a result of user specification or hexdump modifying the
224 iteration count as described above, an iteration count is greater than
225 one, no trailing whitespace characters are output during the last iter‐
226 ation.
227
228 It is an error to specify a byte count as well as multiple conversion
229 characters or strings unless all but one of the conversion characters
230 or strings is _a or _A.
231
232 If, as a result of the specification of the -n option or end-of-file
233 being reached, input data only partially satisfies a format string, the
234 input block is zero-padded sufficiently to display all available data
235 (i.e., any format units overlapping the end of data will display some
236 number of the zero bytes).
237
238 Further output by such format strings is replaced by an equivalent num‐
239 ber of spaces. An equivalent number of spaces is defined as the number
240 of spaces output by an s conversion character with the same field width
241 and precision as the original conversion character or conversion string
242 but with any '+', ´ ´, '#' conversion flag characters removed, and ref‐
243 erencing a NULL string.
244
245 If no format strings are specified, the default display is very similar
246 to the -x output format (the -x option causes more space to be used
247 between format units than in the default output).
248
250 hexdump exits 0 on success and >0 if an error occurred.
251
253 The hexdump utility is expected to be IEEE Std 1003.2 ("POSIX.2") com‐
254 patible.
255
257 Display the input in perusal format:
258 "%06.6_ao " 12/1 "%3_u "
259 "\t\t" "%_p "
260 "\n"
261
262 Implement the -x option:
263 "%07.7_Ax\n"
264 "%07.7_ax " 8/2 "%04x " "\n"
265
266 MBR Boot Signature example: Highlight the addresses cyan and the bytes
267 at offsets 510 and 511 green if their value is 0xAA55, red otherwise.
268 "%07.7_Ax_L[cyan]\n"
269 "%07.7_ax_L[cyan] " 8/2 " %04x_L[green:0xAA55@510-511,!red:0xAA55@510-511] " "\n"
270
272 Implicit coloring can be disabled by an empty file /etc/terminal-col‐
273 ors.d/hexdump.disable.
274
275 See terminal-colors.d(5) for more details about colorization configura‐
276 tion.
277
279 The hexdump command is part of the util-linux package and is available
280 from Linux Kernel Archive ⟨https://www.kernel.org/pub/linux/utils/util-
281 linux/⟩.
282
283
284
285util-linux April 2013 HEXDUMP(1)