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