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 &
ABCDEF
GHIJKM
123456
[root@DB-Server ~]#  hexdump -
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 &
ABCDEFGHIJKLMNODF12*DFDF
[2]+  Stopped                cat >
You have new mail in /var/spool/mail/root
[root@DB-Server ~]# hexdump -
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 -
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换行按哪个键
3:以ASCII字符显⽰⽂件中字符
[root@DB-Server ~]# hexdump -
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 -
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
00000000  41 42 43 44 45                                    |ABCDE|
00000005
6:以偏移量开始格式输出。如下所⽰指定参数-s 5 ,前⾯的ABCDE字符没有了。
[root@DB-Server ~]# hexdump -
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
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