Linux命令學習總結:hexdump,

來源:互聯網
上載者:User

Linux命令學習總結:hexdump,

命令簡介:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.