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