Displaying a file or device in hex

A while back I came across the hexdump utility, which allows you to dump the contents of a device or file in hexadecimal:

$ dd if=/dev/hda count=1 | hexdump -x

1+0 records in
1+0 records out
0000000    48eb    1090    d08e    00bc    b8b0    0000    d88e    c08e
0000010    befb    7c00    00bf    b906    0200    a4f3    21ea    0006
0000020    be00    07be    0438    0b75    c683    8110    fefe    7507
0000030    ebf3    b416    b002    bb01    7c00    80b2    748a    0203
0000040    0080    8000    e051    0001    0800    80fa    80ca    53ea

This is a super useful utility!

3 Comments

Jeff Schroeder  on December 5th, 2009

When in vi, try this to convert to hex:
%!xxd

Edit whatever you want and then to change back to binary do:
%!xxd -r

An old solaris guy taught me that nifty trick.

Dustin J. Mitchell  on December 5th, 2009

The -C option outputs per-byte data, which can be more helpful sometimes:

00000000 2f 2a 0a 20 2a 20 41 6d 61 6e 64 61 2c 20 54 68 |/*. * Amanda, Th|
00000010 65 20 41 64 76 61 6e 63 65 64 20 4d 61 72 79 6c |e Advanced Maryl|
00000020 61 6e 64 20 41 75 74 6f 6d 61 74 69 63 20 4e 65 |and Automatic Ne|
00000030 74 77 6f 72 6b 20 44 69 73 6b 20 41 72 63 68 69 |twork Disk Archi|
00000040 76 65 72 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 |ver. * Copyright|

BrianDKing  on December 11th, 2009

Or you can use “od” which will probably be found on more systems (including AIX, HPUX, and Solaris). “od -x” and “od -c” are 2 fairly useful ones.

Leave a Comment