你的位置:首页 > 软件开发 > 操作系统 > Linux命令学习总结:hexdump

Linux命令学习总结:hexdump

发布时间:2015-12-26 12:00:04
命令简介: hexdump是Linux下的一个二进制文件查看工具,它可以将二进制文件转换为ASCII、八进制、十进制、十六进制格式进行查看。 指令所在路径:/usr/bin/hexdump 命令语法: hexdump: [-bcCdovx] [-e fmt] [- ...

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的cp命令参数有可能不同。

参数

长参数

描叙

-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

Linux命令学习总结:hexdump

 

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格式换行符。如下所示

Linux命令学习总结:hexdump

 

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

原标题:Linux命令学习总结:hexdump

关键词:linux

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录