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.\" @(#)hexdump.1 8.2 (Berkeley) 4/18/94 33.\" $FreeBSD$ 34.\" 35.Dd April 18, 1994 36.Dt HEXDUMP 1 37.Os 38.Sh NAME 39.Nm hexdump, hd 40.Nd ASCII, decimal, hexadecimal, octal dump 41.Sh SYNOPSIS 42.Nm hexdump 43.Op Fl bcCdovx 44.Op Fl e Ar format_string 45.Op Fl f Ar format_file 46.Op Fl n Ar length 47.Bk -words 48.Op Fl s Ar skip 49.Ek 50.Ar file ... 51.Nm hd 52.Op Fl bcdovx 53.Op Fl e Ar format_string 54.Op Fl f Ar format_file 55.Op Fl n Ar length 56.Bk -words 57.Op Fl s Ar skip 58.Ek 59.Ar file ... 60.Sh DESCRIPTION 61The hexdump utility is a filter which displays the specified files, or 62the standard input, if no files are specified, in a user specified 63format. 64.Pp 65The options are as follows: 66.Bl -tag -width Fl 67.It Fl b 68.Em One-byte octal display . 69Display the input offset in hexadecimal, followed by sixteen 70space-separated, three column, zero-filled, bytes of input data, 71in octal, per line. 72.It Fl c 73.Em One-byte character display . 74Display the input offset in hexadecimal, followed by sixteen 75space-separated, three column, space-filled, characters of input 76data per line. 77.It Fl C 78.Em Canonical hex+ASCII display. 79Display the input offset in hexadecimal, followed by sixteen 80space-separated, two column, hexadecimal bytes, followed by the 81same sixteen bytes in %_p format enclosed in ``|'' characters. 82.Pp 83Calling the command 84.Nm hd 85implies this option. 86.It Fl d 87.Em Two-byte decimal display. 88Display the input offset in hexadecimal, followed by eight 89space-separated, five column, zero-filled, two-byte units 90of input data, in unsigned decimal, per line. 91.It Fl e Ar format_string 92Specify a format string to be used for displaying data. 93.It Fl f Ar format_file 94Specify a file that contains one or more newline separated format strings. 95Empty lines and lines whose first non-blank character is a hash mark 96.Pf ( Cm \&# ) 97are ignored. 98.It Fl n Ar length 99Interpret only 100.Ar length 101bytes of input. 102.It Fl o 103.Em Two-byte octal display. 104Display the input offset in hexadecimal, followed by eight 105space-separated, six column, zero-filled, two byte quantities of 106input data, in octal, per line. 107.It Fl s Ar offset 108Skip 109.Ar offset 110bytes from the beginning of the input. 111By default, 112.Ar offset 113is interpreted as a decimal number. 114With a leading 115.Cm 0x 116or 117.Cm 0X , 118.Ar offset 119is interpreted as a hexadecimal number, 120otherwise, with a leading 121.Cm 0 , 122.Ar offset 123is interpreted as an octal number. 124Appending the character 125.Cm b , 126.Cm k , 127or 128.Cm m 129to 130.Ar offset 131causes it to be interpreted as a multiple of 132.Li 512 , 133.Li 1024 , 134or 135.Li 1048576 , 136respectively. 137.It Fl v 138The 139.Fl v 140option causes hexdump to display all input data. 141Without the 142.Fl v 143option, any number of groups of output lines, which would be 144identical to the immediately preceding group of output lines (except 145for the input offsets), are replaced with a line comprised of a 146single asterisk. 147.It Fl x 148.Em Two-byte hexadecimal display. 149Display the input offset in hexadecimal, followed by eight, space 150separated, four column, zero-filled, two-byte quantities of input 151data, in hexadecimal, per line. 152.El 153.Pp 154For each input file, 155.Nm hexdump 156sequentially copies the input to standard output, transforming the 157data according to the format strings specified by the 158.Fl e 159and 160.Fl f 161options, in the order that they were specified. 162.Ss Formats 163A format string contains any number of format units, separated by 164whitespace. 165A format unit contains up to three items: an iteration count, a byte 166count, and a format. 167.Pp 168The iteration count is an optional positive integer, which defaults to 169one. 170Each format is applied iteration count times. 171.Pp 172The byte count is an optional positive integer. 173If specified it defines the number of bytes to be interpreted by 174each iteration of the format. 175.Pp 176If an iteration count and/or a byte count is specified, a single slash 177must be placed after the iteration count and/or before the byte count 178to disambiguate them. 179Any whitespace before or after the slash is ignored. 180.Pp 181The format is required and must be surrounded by double quote 182(" ") marks. 183It is interpreted as a fprintf-style format string (see 184.Xr fprintf 3 ) , 185with the 186following exceptions: 187.Bl -bullet -offset indent 188.It 189An asterisk (*) may not be used as a field width or precision. 190.It 191A byte count or field precision 192.Em is 193required for each ``s'' conversion 194character (unlike the 195.Xr fprintf 3 196default which prints the entire string if the precision is unspecified). 197.It 198The conversion characters ``h'', ``l'', ``n'', ``p'' and ``q'' are 199not supported. 200.It 201The single character escape sequences 202described in the C standard are supported: 203.Bd -ragged -offset indent -compact 204.Bl -column <alert_character> 205.It NUL \e0 206.It <alert character> \ea 207.It <backspace> \eb 208.It <form-feed> \ef 209.It <newline> \en 210.It <carriage return> \er 211.It <tab> \et 212.It <vertical tab> \ev 213.El 214.Ed 215.El 216.Pp 217Hexdump also supports the following additional conversion strings: 218.Bl -tag -width Fl 219.It Cm \&_a Ns Op Cm dox 220Display the input offset, cumulative across input files, of the 221next byte to be displayed. 222The appended characters 223.Cm d , 224.Cm o , 225and 226.Cm x 227specify the display base 228as decimal, octal or hexadecimal respectively. 229.It Cm \&_A Ns Op Cm dox 230Identical to the 231.Cm \&_a 232conversion string except that it is only performed 233once, when all of the input data has been processed. 234.It Cm \&_c 235Output characters in the default character set. 236Nonprinting characters are displayed in three character, zero-padded 237octal, except for those representable by standard escape notation 238(see above), 239which are displayed as two character strings. 240.It Cm _p 241Output characters in the default character set. 242Nonprinting characters are displayed as a single 243.Dq Cm \&. . 244.It Cm _u 245Output US ASCII characters, with the exception that control characters are 246displayed using the following, lower-case, names. 247Characters greater than 0xff, hexadecimal, are displayed as hexadecimal 248strings. 249.Bl -column \&000_nu \&001_so \&002_st \&003_et \&004_eo 250.It \&000\ nul\t001\ soh\t002\ stx\t003\ etx\t004\ eot\t005\ enq 251.It \&006\ ack\t007\ bel\t008\ bs\t009\ ht\t00A\ lf\t00B\ vt 252.It \&00C\ ff\t00D\ cr\t00E\ so\t00F\ si\t010\ dle\t011\ dc1 253.It \&012\ dc2\t013\ dc3\t014\ dc4\t015\ nak\t016\ syn\t017\ etb 254.It \&018\ can\t019\ em\t01A\ sub\t01B\ esc\t01C\ fs\t01D\ gs 255.It \&01E\ rs\t01F\ us\t0FF\ del 256.El 257.El 258.Pp 259The default and supported byte counts for the conversion characters 260are as follows: 261.Bl -tag -width "Xc,_Xc,_Xc,_Xc,_Xc,_Xc" -offset indent 262.It Li \&%_c , \&%_p , \&%_u , \&%c 263One byte counts only. 264.It Xo 265.Li \&%d , \&%i , \&%o , 266.Li \&%u , \&%X , \&%x 267.Xc 268Four byte default, one, two and four byte counts supported. 269.It Xo 270.Li \&%E , \&%e , \&%f , 271.Li \&%G , \&%g 272.Xc 273Eight byte default, four byte counts supported. 274.El 275.Pp 276The amount of data interpreted by each format string is the sum of the 277data required by each format unit, which is the iteration count times the 278byte count, or the iteration count times the number of bytes required by 279the format if the byte count is not specified. 280.Pp 281The input is manipulated in ``blocks'', where a block is defined as the 282largest amount of data specified by any format string. 283Format strings interpreting less than an input block's worth of data, 284whose last format unit both interprets some number of bytes and does 285not have a specified iteration count, have the iteration count 286incremented until the entire input block has been processed or there 287is not enough data remaining in the block to satisfy the format string. 288.Pp 289If, either as a result of user specification or hexdump modifying 290the iteration count as described above, an iteration count is 291greater than one, no trailing whitespace characters are output 292during the last iteration. 293.Pp 294It is an error to specify a byte count as well as multiple conversion 295characters or strings unless all but one of the conversion characters 296or strings is 297.Cm \&_a 298or 299.Cm \&_A . 300.Pp 301If, as a result of the specification of the 302.Fl n 303option or end-of-file being reached, input data only partially 304satisfies a format string, the input block is zero-padded sufficiently 305to display all available data (i.e. any format units overlapping the 306end of data will display some number of the zero bytes). 307.Pp 308Further output by such format strings is replaced by an equivalent 309number of spaces. 310An equivalent number of spaces is defined as the number of spaces 311output by an 312.Cm s 313conversion character with the same field width 314and precision as the original conversion character or conversion 315string but with any 316.Dq Li \&+ , 317.Dq \&\ \& , 318.Dq Li \&# 319conversion flag characters 320removed, and referencing a NULL string. 321.Pp 322If no format strings are specified, the default display is equivalent 323to specifying the 324.Fl x 325option. 326.Pp 327.Nm hexdump 328exits 0 on success and >0 if an error occurred. 329.Sh EXAMPLES 330Display the input in perusal format: 331.Bd -literal -offset indent 332"%06.6_ao " 12/1 "%3_u " 333"\et\et" "%_p " 334"\en" 335.Ed 336.Pp 337Implement the \-x option: 338.Bd -literal -offset indent 339"%07.7_Ax\en" 340"%07.7_ax " 8/2 "%04x " "\en" 341.Ed 342.Sh SEE ALSO 343.Xr gdb 1 344