命令簡介:
hexdump是Linux下的一個二進制文件查看工具,它可以將二進制文件轉換爲ASCII、八進制、十進制、十六進制格式進行查看。
指令所在路徑:/usr/bin/hexdump
命令語法:
hexdump: [-bcCdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]
命令參數:
此命令參數是Red Hat Enterprise Linux Server release 5.7下hexdump命令參數,不同版本Linux的hexdump命令參數有可能不同。
參數 |
長參數 |
描敘 |
-b |
|
每個字節顯示爲8進制。一行共16個字節,一行開始以十六進制顯示偏移值 |
-c |
|
每個字節顯示爲ASCII字符 |
-C |
|
每個字節顯示爲16進制和相應的ASCII字符 |
-d |
|
兩個字節顯示爲10進制 |
-e |
|
格式化輸出 |
-f |
|
Specify a file that contains one or more newline separated format strings. Empty lines and lines whose first non-blank character is a hash mark (#) are ignored. |
-n |
|
只格式前n個長度的字符 |
-o |
|
兩個字節顯示爲8進制 |
-s |
|
從偏移量開始輸出 |
-v |
|
The -v option causes hexdump to display all input data. Without the -v option, any number of groups of output lines, which would be identical to the immediately preceding group of output lines |
-x |
|
雙字節十六進制顯示 |
使用示例:
1: 查看hexdmp命令的幫助信息
[root@DB-Server ~]# man hexdump
2: 以8進制顯示文件裏面的字符。
[root@DB-Server ~]# cat >test.txt
ABCDEF
GHIJKM
123456
[root@DB-Server ~]# hexdump -b test.txt
0000000 101 102 103 104 105 106 012 107 110 111 112 113 115 012 061 062
0000010 063 064 065 066 012
0000015
注意:一行共16個字節,一行開始以十六進制顯示偏移值(如下所示,第一行字符串只顯示到D,第十六個字節,後面的F12*DFDF換行顯示)
[root@DB-Server ~]# cat >test.txt
ABCDEFGHIJKLMNODF12*DFDF
[2]+ Stopped cat > test.txt
You have new mail in /var/spool/mail/root
[root@DB-Server ~]# hexdump -b test.txt
0000000 101 102 103 104 105 106 107 110 111 112 113 114 115 116 117 104
0000010 106 061 062 052 104 106 104 106 012
0000019
[root@DB-Server ~]# hexdump -c test.txt
0000000 A B C D E F G H I J K L M N O D
0000010 F 1 2 * D F D F \n
0000019
3:以ASCII字符顯示文件中字符
[root@DB-Server ~]# hexdump -c test.txt
0000000 A B C D E F G H I J K L M N O D
0000010 F 1 2 * D F D F \n
0000019
hexdump 以ASCII字符顯示時,可以輸出換行符,這個功能可以用來檢查文件是Linux的換行符格式還是Widows格式換行符。如下所示
4:以16進制和相應的ASCII字符顯示文件裏的字符
[root@DB-Server ~]# hexdump -C test.txt
00000000 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 44 |ABCDEFGHIJKLMNOD|
00000010 46 31 32 2a 44 46 44 46 0a |F12*DFDF.|
00000019
5:只格式文件中前n個字符
[root@DB-Server ~]# hexdump -C -n 5 test.txt
00000000 41 42 43 44 45 |ABCDE|
00000005
6:以偏移量開始格式輸出。如下所示指定參數-s 5 ,前面的ABCDE字符沒有了。
[root@DB-Server ~]# hexdump -C test.txt
00000000 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 44 |ABCDEFGHIJKLMNOD|
00000010 46 31 32 2a 44 46 44 46 0a |F12*DFDF.|
00000019
[root@DB-Server ~]# hexdump -C -s 5 test.txt
00000005 46 47 48 49 4a 4b 4c 4d 4e 4f 44 46 31 32 2a 44 |FGHIJKLMNODF12*D|
00000015 46 44 46 0a |FDF.|
00000019