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