hexdump

ascii, character, decimal, hexadecimal, octal dump

hexdump [-bcCdovx] [-e "formatString"] [-f formatFile] [‑n count] [‑s skip] file ...

Multiple inputs are considered a continuous input.

Default the first digits are the offset in hexadecimal.
The last line is the number of bytes in the input in hexadecimal.

-s offset Skip offset bytes from the beginning of the input.
Default: offset is decimal, 0x or 0X prefixes hexadecimal, 0 prefixes octal.
Appending a b, k, or m to offset indicates a block of 512, 1024, or 1,048,576 bytes.
-n count only count bytes of input.(decimal only)
hexdump -n 32 -C numbersAndLetters.txt
00000000  30 31 32 33 34 35 36 37  38 39 20 0a 61 62 63 64  |0123456789 .abcd|
00000010  65 66 67 68 69 6a 6b 6c  6d 6e 6f 70 71 72 73 74  |efghijklmnopqrst|
00000020 
-v Verbose, display all input data.
Default: duplicate output lines are represented by an * (asterisk).
 cat 00
1234567890
00000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
abcdefg

hexdump -C 00
00000000  31 32 33 34 35 36 37 38  39 30 0a 30 30 30 30 30  |1234567890.00000|
00000010  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30  |0000000000000000|
*
00000060  30 30 30 30 30 30 30 30  0a 30 30 30 30 30 30 30  |00000000.0000000|
00000070  30 30 30 30 30 30 30 30  30 30 30 30 30 0a 30 30  |0000000000000.00|
00000080  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30  |0000000000000000|
00000090  30 30 0a 61 62 63 64 65  66 67 0a                 |00.abcdefg.|
0000009b

hexdump -v -C 00
00000000  31 32 33 34 35 36 37 38  39 30 0a 30 30 30 30 30  |1234567890.00000|
00000010  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30  |0000000000000000|
00000020  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30  |0000000000000000|
00000030  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30  |0000000000000000|
00000040  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30  |0000000000000000|
00000050  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30  |0000000000000000|
00000060  30 30 30 30 30 30 30 30  0a 30 30 30 30 30 30 30  |00000000.0000000|
00000070  30 30 30 30 30 30 30 30  30 30 30 30 30 0a 30 30  |0000000000000.00|
00000080  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30  |0000000000000000|
00000090  30 30 0a 61 62 63 64 65  66 67 0a                 |00.abcdefg.|
0000009b 
Pre-Defined Formatting
defaultOne-Byte Hexadecimal.
rows of 16, two digit, hexadecimal bytes.
hexdump  000
0000000 00 30 00 31 01 33 ff ff 03 02 05 04 0a         
000000d (number of bytes in the file)
hexdump  numbersAndLetters.txt
0000000 30 31 32 33 34 35 36 37 38 39 20 0a 61 62 63 64
0000010 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74
0000020 75 76 77 78 79 7a 0a 41 42 43 44 45 46 47 48 49
0000030 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59
0000040 5a 0a 01 02 03 04 05 06 07 08 09 00 0e 0f 10 11
0000050 12 13 14 15 16 17 18 19 1a 0a                  
000005a (number of bytes in the file)
-C
upper
case
hex + ASCII
16, two digit, hexadecimal bytes,
followed by the same 16 bytes in ASCII if printable or a dot if unprintable
This is locale specific (i.e. LC_CTYPE="POSIX"LC_TYPE="en_US.UTF-8").
hexdump  -C numbersAndLetters.txt
00000000  30 31 32 33 34 35 36 37  38 39 20 0a 61 62 63 64  |0123456789 .abcd|
00000010  65 66 67 68 69 6a 6b 6c  6d 6e 6f 70 71 72 73 74  |efghijklmnopqrst|
00000020  75 76 77 78 79 7a 0a 41  42 43 44 45 46 47 48 49  |uvwxyz.ABCDEFGHI|
00000030  4a 4b 4c 4d 4e 4f 50 51  52 53 54 55 56 57 58 59  |JKLMNOPQRSTUVWXY|
00000040  5a 0a 01 02 03 04 05 06  07 08 09 00 0e 0f 10 11  |Z...............|
00000050  12 13 14 15 16 17 18 19  1a 0a                    |..........|
0000005a (number of bytes in the file)
-c THREE-byte character
16, 3 position, space-filled, ACSII characters
hexdump  -c numbersAndLetters.txt
0000000   0   1   2   3   4   5   6   7   8   9      \n   a   b   c   d
0000010   e   f   g   h   i   j   k   l   m   n   o   p   q   r   s   t
0000020   u   v   w   x   y   z  \n   A   B   C   D   E   F   G   H   I
0000030   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y
0000040   Z  \n 001 002 003 004 005 006  \a  \b  \t  \0 016 017 020 021
0000050 022 023 024 025 026 027 030 031 032  \n                        
000005a 
Control characters (unprintable characters with values less then a space)
are displayed in 3 digit octal format or backslashMneumonic format where
\a is alert or bell, \b is backspace, \t is tab \0 is a NULL \n is newline

-x Two-byte hexadecimal
8, 4 position, hexadecimal, two-byte units
hexdump  -x 000
0000000    0030    0031    0133    ffff    0302    0504    0a00        
000000d 
-d Two-byte decimal, unsigned 16bit integers
8, 5 digit, zero-filled
hexdump  -d 000
0000000   00048   00049   00307   65535   00770   01284   02560        
000000d 
-o Two-byte octal.
8 space-separated, 6 digit, zero-filled, two byte quantities of input data, in octal
hexdump -o numbersAndLetters.txt
0000000  030061  031063  032065  033067  034071  020012  060542  061544
0000010  062546  063550  064552  065554  066556  067560  070562  071564
0000020  072566  073570  074572  005101  041103  042105  043107  044111
0000030  045113  046115  047117  050121  051123  052125  053127  054131
0000040  055012  000402  001404  002406  003410  004400  007017  010021
0000050  011023  012025  013027  014031  015012                        
000005a 
-b One-byte octal .
16 space-separated, 3 digit, zero-filled, bytes in octal, per line.
hexdump  -b numbersAndLetters.txt
0000000 060 061 062 063 064 065 066 067 070 071 040 012 141 142 143 144
0000010 145 146 147 150 151 152 153 154 155 156 157 160 161 162 163 164
0000020 165 166 167 170 171 172 012 101 102 103 104 105 106 107 110 111
0000030 112 113 114 115 116 117 120 121 122 123 124 125 126 127 130 131
0000040 132 012 001 002 003 004 005 006 007 010 011 000 016 017 020 021
0000050 022 023 024 025 026 027 030 031 032 012                        
000005a
Custom Formatting
‑e "formatString" Quotes (") within the formatString need to be escaped to prevent being intrepreted by the shell.
-f fmt_file contains formatStrings. Lines beginning with # or empty ignored.

Formats

formatString := formatUnit formatUnit … . Default:-x
formatUnit := [iterationCount]/[byteCount]"conversionCode[text]"
  • iterationCount
  • := integer number of output groups, default:1
        Each formatUnit is applied iterationCount times.
  • byteCount
  • := integer number of input bytes to be formatted
        If byte count is omitted it is the default of the conversion character.
  • conversionCode
  • := %[[0]n]]d|x|o|s|c|u|X|x|G|g|f|_c|_p|_c|_A|_a

        The byteCounts for the ConversionCodes are

    %_c, %_p, %_u, %c 1 byte
    %u, %X, %x' 4 byte default, 1, 2 and 4 byte counts
    %G, %g' %f, 8 byte default or 4 byte count
  • text
  • := arbitary text including space, :, etc for output clairification.

    'single character escape sequences' are:

    NULL
    \0
    alert
    \a
    backspace
    \b
    form‑feed
    \f
    newline
    \n
    carriage return
    \r
    tab
    \t
    vertical tab
    \v
    Additional conversion strings:
    _a[dox] input offset (address), cumulative across input files, of the next byte to be displayed.
    The suffix characters d, o, and x specify the display base as decimal, octal or hexadecimal

    _c Output characters in the default character set.
    Nonprinting characters are displayed in 3 character, zero-padded octal,
    except for those representable by 'single character escape sequences' which are displayed as two character strings.
    _p Output characters in the default character set,
    Nonprinting characters are displayed as a . (dot)
    _u Output US ASCII characters,
    with the exception that control characters are displayed using these names.
       00 nul    01 soh    02 stx    03 etx    04 eot    05 enq
       06 ack    07 bel    08 bs     09 ht     0A lf     0B vt
       0C ff     0D cr     0E so     0F si     10 dle    11 dc1
       12 dc2    13 dc3    14 dc4    15 nak    16 syn    17 etb
       18 can    19 em     1A sub    1B esc    1C fs     1D gs
       1E rs     1F us     FF del

    Characters greater than 0xFF are displayed as hexadecimal.

    _A[dox] number of bytes in input.
    Performed once, when all of the input data has been processed.

    The amount of input data interpreted by each formatString is :
              ( ic * bc ) + ( ic * bc ) …
    the sum of the data required by each formatUnit ie: ( iterationCount times byteCount ).

    The input is intrepreted in blocks which is the largest amount of data specified by any formatString.
    A formatString that interprets less than a block,
    where the final formatUnit does not specify an iteration count,
    the iteration count is increased to intrepret the remainder of the block.

    If, as a result of user specification or hexdump modifying the iteration count,
    an iteration count is greater than one, no trailing whitespace is output during the last iteration.

    It is an error to specify a byte count and multiple conversion strings ( except for _a or _A offset or fileSize).

    If, as a result of the specification of -n or end-of-file being reached, input data only partially satisfies a formatString, the input block is zero-padded sufficiently to display all available data (i.e. any formatUnits overlapping the end of data will display some number of the zero bytes).
    Further output by such formatStrings is replaced by the number of spaces output by an s conversionCode with the same field width and precision as the original conversion character or conversion string but with any +, , # conversion flag characters removed, and referencing a null string.

    hexdump exits 0 on success and >0 if an error occurred.

    Examples

    File 64c.hexdump contains:
    "%07.7_ax " 16/1 "%_p" " " 16/1 "%_p" " " 16/1 "%_p" " " 16/1 "%_p" "\n"

    produces:

    hexdump -f 64c.hexdump timestampso
    0000000  ............a... ............(... U............... ................
    0000040  ........9...?... ..............h^ ................ ................
    0000080  ................ ................ ................ ................
    *
    0001000  ................ ................ ....x.V.K.2.'... ..........i.^.&.
    0001040  ............{.H. =............... y.`.U.)......... ......[.P.-."...
    0001080  ..........e.Z... ..........j._.7. ,.........y.n.R. G.............a.
    00010c0  V.%............. ..|.q.J.?.$..... ..........V.K.!. ..............d.
    0001100  Y.9............. ..m.b.&......... ..........w.l.N. C.!.............
    0001140  ..|.q.V.K...2911 895552.wgegerm@p ppg.org|ip=67.22 8.1437728768.ere
    0001180  pwatch@taipeieye .com|ip=85.121.1 437728768.nopes@ musicpride.ru|ip
    00011c0  =109.188.1437728 768.nnegi@itmmi. com|ip=64.147.14 37728768.marylin
    0001200  h.h@gmail.com|ip =64.27.143772876 8.avipyxu9999@td cmobil.dk|ip=62.
    0001240  135.1437728768.j eremycole@boc.co m|ip=218.111.143 7728768.r20j19@m
    0001280  s29.hi.651034624 .trustfundslt@gm ail.com|ip=201.3 3.2211184640.onl
    00012c0  inedoctorate.zsm un@huggyt.wetpla cetold.net|ip=67 .50.3675783168.s
    0001300  imon@ruderich.or g|ip=93.206.3458 334720.timeshare agent.tqkzvpr@ee
    …
    0001e40  on.networkworld. info|ip=66.186.1 437728768.freecr editscorecom.kme
    0001e80  kux@aulvuj.mesop hy.net|ip=70.98. 1437728768.esimp son@mspu.us|ip=6
    0001ec0  4.34.3352233568. fred_pryor_semin ars@busenetwork. net|ip=208.89.30
    0001f00  57647616.kbauer@ corp.ptd.net|ip= 204.186.28754575 36.info@honda.co
    0001f40  m|ip=41.138.1455 947776.michaelwo okey@gmail.com|i p=209.85.1528823
    0001f80  808.allen.l.park er@gmail.com|ip= 209.85.291189555 2.postmaster@nos
    0001fc0  e.obic.co.jp|ip= 202.224.28754575 36.specials@regf ly.com|ip=67.212
    0002000  ................ ......[......... ..|.q.I.>....... ......c.X.7.-...
    
    Just see an "almost" text file with unprintable characters replaced by dots and wraped at

    Display the input in perusal format:

               "%06.6_ao "  12/1 "%3_u "
               "\t\t" "%_p "
               "\n"
    
    hexdump  -x 000
    0000000 0030  0031  0133   ffff   0302    0504  0a00
    000000d
    
    hexdump -f 0x 000
    000000 nul 0  nul 1 soh 3  ? ?   etx stx  enq eot     . 0 . 1 . 3 ? ? . . . .
    000014  lf  
    
    Implement the -x option:
               "%07.7_Ax\n"
               "%07.7_ax  " 8/2 "%04x " "\n"
    


    STANDARDS The hexdump utility is expected to be IEEE Std 1003.2 (POSIX.2) compatible.

    adapted from: BSD April 18, 1994

    see also

    xxd convert to hex and back