hexdump常用參數

  • 2019 年 10 月 5 日
  • 筆記

在分析mysql binlog或者ibd文件時候,常會用到hexdump 查看物理文件的存儲內容。

參考:http://www.cnblogs.com/kerrycode/p/5077687.html

node1:~ # hexdump –help  (常用下面3個紅色標註的參數)

hexdump: invalid option — '-'

Usage:

hexdump [options] file…

Options:

-b              one-byte octal display           8進制顯示

-c              one-byte character display       ASCII顯示

-C              canonical hex+ASCII display       十六進制+ASCII顯示

-d              two-byte decimal display        兩位元組計算,顯示為10進制方式

-o              two-byte octal display         兩位元組計算,顯示為8進制方式

-x              two-byte hexadecimal display    兩位元組計算,顯示為16進制方式

-e format       format string to be used for displaying data   格式化輸出

-f format_file  file that contains format strings

-n length       interpret only length bytes of input    輸出多少個bytes的字符長度的內容

-s offset       skip offset bytes from the beginning    輸出文件的開始偏移量  【注意:偏移量從0開始的!】

-v              display without squeezing similar lines    

-V              output version information and exit

案例:

cat > test.txt < EOF  AbCDEF  GHIJKL  123456  EOF    [root@node1 ~]$ hexdump -b test.txt  0000000 101 142 103 104 105 106 012 107 110 111 112 113 114 012 061 062  0000010 063 064 065 066 012  [root@node1 ~]$ hexdump -c test.txt   可以看到n表示文件中有換行(注意:linux下換行是n  windows下換行是rn)  0000000   A   b   C   D   E   F  n   G   H   I   J   K   L  n   1   2  0000010   3   4   5   6  n                                              0000015    [root@node1 ~]$ hexdump -C test.txt  00000000  41 62 43 44 45 46 0a 47  48 49 4a 4b 4c 0a 31 32  |AbCDEF.GHIJKL.12|  00000010  33 34 35 36 0a                                    |3456.|  00000015    [root@node1 ~]$ hexdump -d test.txt  0000000   25153   17475   17989   18186   18760   19274   02636   12849  0000010   13363   13877   00010                                          0000015    [root@node1 ~]$ hexdump -C -s 0 -n 3 test.txt  00000000  41 62 43                                          |AbC|  00000003    [root@node1 ~]$ hexdump -C -s 8  test.txt   從偏移量8開始輸出全部內容  00000008  48 49 4a 4b 4c 0a 31 32  33 34 35 36 0a           |HIJKL.123456.|  00000015