1.\" $OpenBSD: hexdump.1,v 1.24 2011/05/06 18:11:43 otto Exp $ 2.\" $NetBSD: hexdump.1,v 1.14 2001/12/07 14:46:24 bjh21 Exp $ 3.\" 4.\" Copyright (c) 1989, 1990, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" from: @(#)hexdump.1 8.2 (Berkeley) 4/18/94 32.\" 33.Dd $Mdocdate: May 6 2011 $ 34.Dt HEXDUMP 1 35.Os 36.Sh NAME 37.Nm hexdump 38.Nd ascii, decimal, hexadecimal, octal dump 39.Sh SYNOPSIS 40.Nm hexdump 41.Bk -words 42.Op Fl bCcdovx 43.Op Fl e Ar format_string 44.Op Fl f Ar format_file 45.Op Fl n Ar length 46.Op Fl s Ar offset 47.Op Ar 48.Ek 49.Sh DESCRIPTION 50The 51.Nm 52utility 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 Ds 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 Canonical hex+ASCII display . 65Display the input offset in hexadecimal, followed by sixteen 66space-separated, two column, hexadecimal bytes, followed by the 67same sixteen bytes in %_p format enclosed in ``|'' characters. 68.It Fl c 69.Em One-byte character display . 70Display the input offset in hexadecimal, followed by sixteen 71space-separated, three column, space-filled, characters of input 72data per line. 73.It Fl d 74.Em Two-byte decimal display . 75Display the input offset in hexadecimal, followed by eight 76space-separated, five column, zero-filled, two-byte units 77of input data, in unsigned decimal, per line. 78.It Fl e Ar format_string 79Specify a format string to be used for displaying data. 80.It Fl f Ar format_file 81Specify a file that contains one or more newline separated format strings. 82Empty lines and lines whose first non-blank character is a hash mark 83.Pq Ql # 84are ignored. 85.It Fl n Ar length 86Interpret only 87.Ar length 88bytes of input. 89By default, 90.Ar length 91is interpreted as a decimal number. 92With a leading 93.Cm 0x 94or 95.Cm 0X , 96.Ar length 97is interpreted as a hexadecimal number, 98otherwise, with a leading 99.Cm 0 , 100.Ar length 101is interpreted as an octal number. 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.Pq Ql * . 148.It Fl x 149.Em Two-byte hexadecimal display . 150Display the input offset in hexadecimal, followed by eight, space 151separated, four column, zero-filled, two-byte quantities of input 152data, in hexadecimal, per line. 153.El 154.Pp 155For each input file, 156.Nm 157sequentially copies the input to standard output, transforming the 158data according to the format strings specified by the 159.Fl e 160and 161.Fl f 162options, in the order that they were specified. 163.Ss Formats 164A format string contains any number of format units, separated by 165whitespace. 166A format unit contains up to three items: an iteration count, a byte 167count, and a format. 168.Pp 169The iteration count is an optional positive integer, which defaults to 170one. 171Each format is applied iteration count times. 172.Pp 173The byte count is an optional positive integer. 174If specified it defines the number of bytes to be interpreted by 175each iteration of the format. 176.Pp 177If an iteration count and/or a byte count is specified, a single slash 178.Pq Sq / 179must be placed after the iteration count and/or before the byte count 180to disambiguate them. 181Any whitespace before or after the slash is ignored. 182.Pp 183The format is required and must be surrounded by double quote 184.Pq \&"\& \&" 185marks 186(the quote mark is a special character in many shell programs, 187and may have to be escaped from the shell). 188It is interpreted as a fprintf-style format string (see 189.Xr fprintf 3 ) , 190with the 191following exceptions: 192.Bl -bullet -offset indent 193.It 194An asterisk (*) may not be used as a field width or precision. 195.It 196A byte count or field precision 197.Em is 198required for each 199.Sq s 200conversion character (unlike the 201.Xr fprintf 3 202default which prints the entire string if the precision is unspecified). 203.It 204The conversion characters 205.Sq h , 206.Sq l , 207.Sq n , 208.Sq p , 209and 210.Sq q 211are not supported. 212.It 213The single character escape sequences 214described in the C standard are supported: 215.Pp 216.Bl -tag -width "Xalert characterXXX" -offset indent -compact 217.It NUL 218\e0 219.It Aq alert character 220\ea 221.It Aq backspace 222\eb 223.It Aq form-feed 224\ef 225.It Aq newline 226\en 227.It Aq carriage return 228\er 229.It Aq tab 230\et 231.It Aq vertical tab 232\ev 233.El 234.El 235.Pp 236.Nm 237also supports the following additional conversion strings: 238.Bl -tag -width Fl 239.It Cm \&_a Ns Op Cm dox 240Display the input offset, cumulative across input files, of the 241next byte to be displayed. 242The appended characters 243.Cm d , 244.Cm o , 245and 246.Cm x 247specify the display base 248as decimal, octal or hexadecimal respectively. 249.It Cm \&_A Ns Op Cm dox 250Identical to the 251.Cm \&_a 252conversion string except that it is only performed 253once, when all of the input data has been processed. 254.It Cm \&_c 255Output characters in the default character set. 256Nonprinting characters are displayed in three character, zero-padded 257octal, except for those representable by standard escape notation 258(see above), 259which are displayed as two character strings. 260.It Cm _p 261Output characters in the default character set. 262Nonprinting characters are displayed as a single dot 263.Ql \&. . 264.It Cm _u 265Output US ASCII characters, with the exception that control characters are 266displayed using the following, lower-case, names. 267Other non-printable characters are displayed as hexadecimal strings. 268.Bd -literal -offset 3n 269000 nul 001 soh 002 stx 003 etx 004 eot 005 enq 270006 ack 007 bel 008 bs 009 ht 00A lf 00B vt 27100C ff 00D cr 00E so 00F si 010 dle 011 dc1 272012 dc2 013 dc3 014 dc4 015 nak 016 syn 017 etb 273018 can 019 em 01A sub 01B esc 01C fs 01D gs 27401E rs 01F us 07F del 275.Ed 276.El 277.Pp 278The default and supported byte counts for the conversion characters 279are as follows: 280.Bl -tag -width "Xc,_Xc,_Xc,_Xc,_Xc,_Xc" -offset indent 281.It Li \&%_c , \&%_p , \&%_u , \&%c 282One byte counts only. 283.It Xo 284.Li \&%d , \&%i , \&%o , 285.Li \&%u , \&%X , \&%x 286.Xc 287Four byte default, one, two, four and eight byte counts supported. 288.It Xo 289.Li \&%E , \&%e , \&%f , 290.Li \&%G , \&%g 291.Xc 292Eight byte default, four byte counts supported. 293.El 294.Pp 295The amount of data interpreted by each format string is the sum of the 296data required by each format unit, which is the iteration count times the 297byte count, or the iteration count times the number of bytes required by 298the format if the byte count is not specified. 299.Pp 300The input is manipulated in 301.Dq blocks , 302where a block is defined as the 303largest amount of data specified by any format string. 304Format strings interpreting less than an input block's worth of data, 305whose last format unit both interprets some number of bytes and does 306not have a specified iteration count, have the iteration count 307incremented until the entire input block has been processed or there 308is not enough data remaining in the block to satisfy the format string. 309.Pp 310If, either as a result of user specification or hexdump modifying 311the iteration count as described above, an iteration count is 312greater than one, no trailing whitespace characters are output 313during the last iteration. 314.Pp 315It is an error to specify a byte count as well as multiple conversion 316characters or strings unless all but one of the conversion characters 317or strings is 318.Cm \&_a 319or 320.Cm \&_A . 321.Pp 322If, as a result of the specification of the 323.Fl n 324option or end-of-file being reached, input data only partially 325satisfies a format string, the input block is zero-padded sufficiently 326to display all available data (i.e., any format units overlapping the 327end of data will display some number of the zero bytes). 328.Pp 329Further output by such format strings is replaced by an equivalent 330number of spaces. 331An equivalent number of spaces is defined as the number of spaces 332output by an 333.Cm s 334conversion character with the same field width 335and precision as the original conversion character or conversion 336string but with any 337.Ql + , 338.Ql \&\ \& , 339.Ql # 340conversion flag characters 341removed, and referencing a NULL string. 342.Pp 343If no format strings are specified, the default display is equivalent 344to specifying the 345.Fl x 346option. 347.Sh EXIT STATUS 348.Ex -std hexdump 349.Sh EXAMPLES 350Display characters using a fieldwidth of 4, 351and using special names for control characters: 352.Pp 353.Dl $ hexdump -e '"%4_u"' file 354.Pp 355An example file for use with the 356.Fl f 357option, to display the input in perusal format: 358.Bd -literal -offset indent 359"%06.6_ao " 12/1 "%3_u " 360"\et\et" "%_p " 361"\en" 362.Ed 363.Pp 364An example file for use with the 365.Fl f 366option, which implements the equivalent of the 367.Fl x 368option: 369.Bd -literal -offset indent 370"%07.7_Ax\en" 371"%07.7_ax " 8/2 " %04x " "\en" 372.Ed 373.Sh SEE ALSO 374.Xr od 1 375