xxd

 

 


xxd - as a hexdump

 

cat test.txt

0123456789abcdef
0123456789abcdef
0123456789abcdef
0123456789abcdef
----------------
0123456789abcdef
0123456789abcdef
0123456789abcdef
0123456789abcdef

# Default: dump 整個 file, 每行 print 16 byte

xxd file       # 由於是 dump 一整個 file, 最好都是 "xxd file | less"

00000000: 3031 3233 3435 3637 3839 6162 6364 6566  0123456789abcdef
00000010: 0a30 3132 3334 3536 3738 3961 6263 6465  .0123456789abcde
00000020: 660a 3031 3233 3435 3637 3839 6162 6364  f.0123456789abcd
00000030: 6566 0a30 3132 3334 3536 3738 3961 6263  ef.0123456789abc
00000040: 6465 660a 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d  def.------------
00000050: 2d2d 2d2d 0a30 3132 3334 3536 3738 3961  ----.0123456789a
00000060: 6263 6465 660a 3031 3233 3435 3637 3839  bcdef.0123456789
00000070: 6162 6364 6566 0a30 3132 3334 3536 3738  abcdef.012345678
00000080: 3961 6263 6465 660a 3031 3233 3435 3637  9abcdef.01234567
00000090: 3839 6162 6364 6566 0a                   89abcdef.

Remark: Size

00000000
*
00001000

以上範圍的 Size = 16^3 = 4096 = 4k

# -l len         Stop after writing <len> octets

# -c cols       Format  <cols> octets per line. Default 16

# Print 16 bytes with 8 octets per line.

xxd -l 16 -c 8 test.txt

00000000: 3031 3233 3435 3637  01234567
00000008: 3839 6162 6364 6566  89abcdef

# plain hexdump style (postscript continuous hexdump style)

-ps

303132333435363738396162636465660a30313233343536373839616263
6465660a303132333435363738396162636465660a303132333435363738
396162636465660a2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d0a3031323334
35363738396162636465660a303132333435363738396162636465660a30
3132333435363738396162636465660a3031323334353637383961626364
65660a

# -s [+][-]seek          start at seek bytes (abs. or rel.)

+  relative to the current stdin file position (meaningless when not reading from stdin)

-   indicates that the seek should be that many characters from the end of the input

xxd -s 0x30 file

xxd -s 0x8 -l 16 test.txt

00000008: 3839 6162 6364 6566 0a30 3132 3334 3536  89abcdef.0123456

# -a | -autoskip

Toggle autoskip: A single '*' replaces nul-lines. Default off.