hexdump of a file

Mar 22, 2016   #GNU  #cli  #unix  #linux 

To view a nice hex dump of some file use GNU od or hexdump utility.

Despite its name od (which used to mean octal dump) supports multiple output formats, including lovely hex along with ASCII:

od -t x1z -Ax /etc/passwd

will result in output like this:

000000 72 6f 6f 74 3a 78 3a 30 3a 30 3a 72 6f 6f 74 3a  >root:x:0:0:root:<
000010 2f 72 6f 6f 74 3a 2f 62 69 6e 2f 62 61 73 68 0a  >/root:/bin/bash.<
000020 64 61 65 6d 6f 6e 3a 78 3a 31 3a 31 3a 64 61 65  >daemon:x:1:1:dae<
000030 6d 6f 6e 3a 2f 75 73 72 2f 73 62 69 6e 3a 2f 75  >mon:/usr/sbin:/u<
000040 73 72 2f 73 62 69 6e 2f 6e 6f 6c 6f 67 69 6e 0a  >sr/sbin/nologin.<
000050 62 69 6e 3a 78 3a 32 3a 32 3a 62 69 6e 3a 2f 62  >bin:x:2:2:bin:/b<
000060 69 6e 3a 2f 75 73 72 2f 73 62 69 6e 2f 6e 6f 6c  >in:/usr/sbin/nol<
000070 6f 67 69 6e 0a 73 79 73 3a 78 3a 33 3a 33 3a 73  >ogin.sys:x:3:3:s<

To get similar result with hexdump use

hexdump -C /etc/passwd

Having hex dump is really useful if you want to check EOL type (CR LF a.k.a. Windows text vs LF a.k.a. Unix/Linux text) or you suspect that this innocently looking ASCII file in reality has nasty BOM in the beginning.