1.\" $OpenBSD: hexdump.1,v 1.4 1997/09/02 15:31:51 kstailey Exp $ 2.\" Copyright (c) 1989, 1990 The Regents of the University of California. 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 3. All advertising materials mentioning features or use of this software 14.\" must display the following acknowledgement: 15.\" This product includes software developed by the University of 16.\" California, Berkeley and its contributors. 17.\" 4. Neither the name of the University nor the names of its contributors 18.\" may be used to endorse or promote products derived from this software 19.\" without specific prior written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.\" from: @(#)hexdump.1 5.12 (Berkeley) 7/27/91 34.\" 35.Dd July 27, 1991 36.Dt HEXDUMP 1 37.Os 38.Sh NAME 39.Nm hexdump 40.Nd ascii, decimal, hexadecimal, octal dump 41.Sh SYNOPSIS 42.Nm hexdump 43.Op Fl bcdovx 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.Sh DESCRIPTION 52The hexdump utility is a filter which displays the specified files, or 53the standard input, if no files are specified, in a user specified 54format. 55.Pp 56The options are as follows: 57.Bl -tag -width Fl 58.It Fl b 59.Em One-byte octal display . 60Display the input offset in hexadecimal, followed by sixteen 61space-separated, three column, zero-filled, bytes of input data, 62in octal, per line. 63.It Fl c 64.Em One-byte character display . 65Display the input offset in hexadecimal, followed by sixteen 66space-separated, three column, space-filled, characters of input 67data per line. 68.It Fl d 69.Em Two-byte decimal display. 70Display the input offset in hexadecimal, followed by eight 71space-separated, five column, zero-filled, two-byte units 72of input data, in unsigned decimal, per line. 73.It Fl e Ar format_string 74Specify a format string to be used for displaying data. 75.It Fl f Ar format_file 76Specify a file that contains one or more newline separated format strings. 77Empty lines and lines whose first non-blank character is a hash mark 78.Pf ( Cm \&# ) 79are ignored. 80.It Fl n Ar length 81Interpret only 82.Ar length 83bytes of input. 84.It Fl o 85.Em Two-byte octal display. 86Display the input offset in hexadecimal, followed by eight 87space-separated, six column, zero-filled, two byte quantities of 88input data, in octal, per line. 89.It Fl s Ar offset 90Skip 91.Ar offset 92bytes from the beginning of the input. 93By default, 94.Ar offset 95is interpreted as a decimal number. 96With a leading 97.Cm 0x 98or 99.Cm 0X , 100.Ar offset 101is interpreted as a hexadecimal number, 102otherwise, with a leading 103.Cm 0 , 104.Ar offset 105is interpreted as an octal number. 106Appending the character 107.Cm b , 108.Cm k , 109or 110.Cm m 111to 112.Ar offset 113causes it to be interpreted as a multiple of 114.Li 512 , 115.Li 1024 , 116or 117.Li 1048576 , 118respectively. 119.It Fl v 120The 121.Fl v 122option causes hexdump to display all input data. 123Without the 124.Fl v 125option, any number of groups of output lines, which would be 126identical to the immediately preceding group of output lines (except 127for the input offsets), are replaced with a line comprised of a 128single asterisk. 129.It Fl x 130.Em Two-byte hexadecimal display. 131Display the input offset in hexadecimal, followed by eight, space 132separated, four column, zero-filled, two-byte quantities of input 133data, in hexadecimal, per line. 134.El 135.Pp 136For each input file, 137.Nm hexdump 138sequentially copies the input to standard output, transforming the 139data according to the format strings specified by the 140.Fl e 141and 142.Fl f 143options, in the order that they were specified. 144.Ss Formats 145A format string contains any number of format units, separated by 146whitespace. 147A format unit contains up to three items: an iteration count, a byte 148count, and a format. 149.Pp 150The iteration count is an optional positive integer, which defaults to 151one. 152Each format is applied iteration count times. 153.Pp 154The byte count is an optional positive integer. 155If specified it defines the number of bytes to be interpreted by 156each iteration of the format. 157.Pp 158If an iteration count and/or a byte count is specified, a single slash 159must be placed after the iteration count and/or before the byte count 160to disambiguate them. 161Any whitespace before or after the slash is ignored. 162.Pp 163The format is required and must be surrounded by double quote 164(" ") marks. 165It is interpreted as a fprintf-style format string (see 166.Xr fprintf 3 ) , 167with the 168following exceptions: 169.Bl -bullet -offset indent 170.It 171An asterisk (*) may not be used as a field width or precision. 172.It 173A byte count or field precision 174.Em is 175required for each ``s'' conversion 176character (unlike the 177.Xr fprintf 3 178default which prints the entire string if the precision is unspecified). 179.It 180The conversion characters ``h'', ``n'', and ``p'' are not 181supported. 182.It 183The single character escape sequences 184described in the C standard are supported: 185.Bd -ragged -offset indent -compact 186.Bl -column <alert_character> 187.It NUL \e0 188.It <alert character> \ea 189.It <backspace> \eb 190.It <form-feed> \ef 191.It <newline> \en 192.It <carriage return> \er 193.It <tab> \et 194.It <vertical tab> \ev 195.El 196.Ed 197.El 198.Pp 199Hexdump also supports the following additional conversion strings: 200.Bl -tag -width Fl 201.It Cm \&_a Ns Op Cm dox 202Display the input offset, cumulative across input files, of the 203next byte to be displayed. 204The appended characters 205.Cm d , 206.Cm o , 207and 208.Cm x 209specify the display base 210as decimal, octal or hexadecimal respectively. 211.It Cm \&_A Ns Op Cm dox 212Identical to the 213.Cm \&_a 214conversion string except that it is only performed 215once, when all of the input data has been processed. 216.It Cm \&_c 217Output characters in the default character set. 218Nonprinting characters are displayed in three character, zero-padded 219octal, except for those representable by standard escape notation 220(see above), 221which are displayed as two character strings. 222.It Cm _p 223Output characters in the default character set. 224Nonprinting characters are displayed as a single 225.Dq Cm \&. . 226.It Cm _u 227Output US ASCII characters, with the exception that control characters are 228displayed using the following, lower-case, names. 229Characters greater than 0xff, hexadecimal, are displayed as hexadecimal 230strings. 231.Bl -column \&000_nu \&001_so \&002_st \&003_et \&004_eo 232.It \&000\ nul\t001\ soh\t002\ stx\t003\ etx\t004\ eot\t005\ enq 233.It \&006\ ack\t007\ bel\t008\ bs\t009\ ht\t00A\ lf\t00B\ vt 234.It \&00C\ ff\t00D\ cr\t00E\ so\t00F\ si\t010\ dle\t011\ dc1 235.It \&012\ dc2\t013\ dc3\t014\ dc4\t015\ nak\t016\ syn\t017\ etb 236.It \&018\ can\t019\ em\t01A\ sub\t01B\ esc\t01C\ fs\t01D\ gs 237.It \&01E\ rs\t01F\ us\t0FF\ del 238.El 239.El 240.Pp 241The default and supported byte counts for the conversion characters 242are as follows: 243.Bl -tag -width "Xc,_Xc,_Xc,_Xc,_Xc,_Xc" -offset indent 244.It Li \&%_c , \&%_p , \&%_u , \&%c 245One byte counts only. 246.It Xo 247.Li \&%d , \&%i , \&%o , 248.Li \&%u , \&%X , \&%x 249.Xc 250Four byte default, one and two byte counts supported. 251.It Xo 252.Li \&%E , \&%e , \&%f , 253.Li \&%G , \&%g 254.Xc 255Eight byte default, four byte counts supported. 256.El 257.Pp 258The amount of data interpreted by each format string is the sum of the 259data required by each format unit, which is the iteration count times the 260byte count, or the iteration count times the number of bytes required by 261the format if the byte count is not specified. 262.Pp 263The input is manipulated in ``blocks'', where a block is defined as the 264largest amount of data specified by any format string. 265Format strings interpreting less than an input block's worth of data, 266whose last format unit both interprets some number of bytes and does 267not have a specified iteration count, have the iteration count 268incremented until the entire input block has been processed or there 269is not enough data remaining in the block to satisfy the format string. 270.Pp 271If, either as a result of user specification or hexdump modifying 272the iteration count as described above, an iteration count is 273greater than one, no trailing whitespace characters are output 274during the last iteration. 275.Pp 276It is an error to specify a byte count as well as multiple conversion 277characters or strings unless all but one of the conversion characters 278or strings is 279.Cm \&_a 280or 281.Cm \&_A . 282.Pp 283If, as a result of the specification of the 284.Fl n 285option or end-of-file being reached, input data only partially 286satisfies a format string, the input block is zero-padded sufficiently 287to display all available data (i.e. any format units overlapping the 288end of data will display some number of the zero bytes). 289.Pp 290Further output by such format strings is replaced by an equivalent 291number of spaces. 292An equivalent number of spaces is defined as the number of spaces 293output by an 294.Cm s 295conversion character with the same field width 296and precision as the original conversion character or conversion 297string but with any 298.Dq Li \&+ , 299.Dq \&\ \& , 300.Dq Li \&# 301conversion flag characters 302removed, and referencing a NULL string. 303.Pp 304If no format strings are specified, the default display is equivalent 305to specifying the 306.Fl x 307option. 308.Pp 309.Nm hexdump 310exits 0 on success and >0 if an error occurred. 311.Sh EXAMPLES 312Display the input in perusal format: 313.Bd -literal -offset indent 314"%06.6_ao " 12/1 "%3_u " 315"\et\et" "%_p " 316"\en" 317.Ed 318.Pp 319Implement the \-x option: 320.Bd -literal -offset indent 321"%07.7_Ax\en" 322"%07.7_ax " 8/2 "%04x " "\en" 323.Ed 324.Sh STANDARDS 325The 326.Nm hexdump 327utility is expected to be 328.St -p1003.2 329compatible. 330