hexdump - ascii, character, decimal, hexadecimal, octal dump

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

Multiple input files are considered a continuous input.

In the default format 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.
By default, offset is interpreted as a decimal number.
0x or 0X prefixes a hexadecimal number
0 prefixes an octal number.
Appending a b, k, or m to offset indicates a block of 512, 1024, or 1,048,576 bytes.
-n count Interpret 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.
Without -v , 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 .
16 space-separated, 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 hex + ASCII .
16 space-separated, 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 space-separated, 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 new-line

-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 ( as in int) .
8 space-separated, 5 digit, zero-filled, two-byte units of input data, in unsigned decimal Used when the input contains 2 byte integer values.
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" a formatString to be used for displaying data.
Quotes ("s) within the formatString need to be escaped to prevent being intrepreted by the shell.
-f fmt_file a file that contains one or more newline separated formatStrings.
Lines beginning with # and Empty lines are ignored.

Formats

formatString := formatUnit formatUnit …
formatUnit := "[iterationCount]/[byteCount]ConversionCode[text]"
iterationCount := integer number of output groups, default=1
byteCount := integer number of input bytes to be formatted
ConversionCode := %[[0]n]d|x|o|s|c|u|X|x|G|g|f|_c|_p|_c|_A|_a
text := arbitary text including space, :, etc for output clairification.

A formatString contains any number of formatUnits separated by whitespace.
A formatUnit contains up to three items: an iteration count, a byte count, and a format.

The optional iteration count (default: 1).
Each format is applied iteration count times.

The optional byte count is the number of bytes of input to be interpreted by each iteration of the format.

If an iteration count and,or a byte count is specified, a slash must be placed after the iteration count. Example: 8/2 8 groups of 2 bytes

It is interpreted simular to a fprintf format string except:

NULL
\0
alert
\a
backspace \b form‑feed \f
newline \ncarriage 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
_A[dox] number of bytes in input.
Performed once, when all of the input data has been processed.

_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 .
_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.

The byte counts for the conversion characters 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

The amount of input data interpreted by each formatString is :
          ( ic * bc ) + ( ic * bc ) …
the sum of the data required by each formatUnit ie: ( iteration count times byte count ).
If byte count is omitted it is the default of the conversion character.

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 an equivalent number of spaces. An equivalent number of spaces is defined as the number of spaces output by an s conversion character 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.

If no formatStrings are specified, the default display is equivalent to specifying -x .

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.-...

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