关于hexdump
hexdump is an utility that creates an hex dump
The hexdump application may be installed under different names such as:
- od
- xxd like hd
- dump
- D
相关文章
od --help
Usage: od [OPTION]... [FILE]...
or: od [-abcdfilosx]... [FILE] [[+]OFFSET[.][b]]
or: od --traditional [OPTION]... [FILE] [[+]OFFSET[.][b] [+][LABEL][.][b]]
Write an unambiguous representation, octal bytes by default,
of FILE to standard output. With more than one FILE argument,
concatenate them in the listed order to form the input.
With no FILE, or when FILE is -, read standard input.
If first and second call formats both apply, the second format is assumed
if the last operand begins with + or (if there are 2 operands) a digit.
An OFFSET operand means -j OFFSET. LABEL is the pseudo-address
at first byte printed, incremented when dump is progressing.
For OFFSET and LABEL, a 0x or 0X prefix indicates hexadecimal;
suffixes may be . for octal and b for multiply by 512.
Mandatory arguments to long options are mandatory for short options too.
-A, --address-radix=RADIX output format for file offsets; RADIX is one
of [doxn], for Decimal, Octal, Hex or None
-j, --skip-bytes=BYTES skip BYTES input bytes first
-N, --read-bytes=BYTES limit dump to BYTES input bytes
-S BYTES, --strings[=BYTES] output strings of at least BYTES graphic chars;
3 is implied when BYTES is not specified
-t, --format=TYPE select output format or formats
-v, --output-duplicates do not use * to mark line suppression
-w[BYTES], --width[=BYTES] output BYTES bytes per output line;
32 is implied when BYTES is not specified
--traditional accept arguments in third form above
--help display this help and exit
--version output version information and exit
Traditional format specifications may be intermixed; they accumulate:
-a same as -t a, select named characters, ignoring high-order bit
-b same as -t o1, select octal bytes
-c same as -t c, select printable characters or backslash escapes
-d same as -t u2, select unsigned decimal 2-byte units
-f same as -t fF, select floats
-i same as -t dI, select decimal ints
-l same as -t dL, select decimal longs
-o same as -t o2, select octal 2-byte units
-s same as -t d2, select decimal 2-byte units
-x same as -t x2, select hexadecimal 2-byte units
TYPE is made up of one or more of these specifications:
a named character, ignoring high-order bit
c printable character or backslash escape
d[SIZE] signed decimal, SIZE bytes per integer
f[SIZE] floating point, SIZE bytes per integer
o[SIZE] octal, SIZE bytes per integer
u[SIZE] unsigned decimal, SIZE bytes per integer
x[SIZE] hexadecimal, SIZE bytes per integer
SIZE is a number. For TYPE in [doux], SIZE may also be C for
sizeof(char), S for sizeof(short), I for sizeof(int) or L for
sizeof(long). If TYPE is f, SIZE may also be F for sizeof(float), D
for sizeof(double) or L for sizeof(long double).
Adding a z suffix to any type displays printable characters at the end of
each output line.
BYTES is hex with 0x or 0X prefix, and may have a multiplier suffix:
b 512
KB 1000
K 1024
MB 1000*1000
M 1024*1024
and so on for G, T, P, E, Z, Y.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'od invocation'
实例
先准备一个tmp文件
[linuxde@localhost ~]$ echo abcdef g > tmp
[linuxde@localhost ~]$ cat tmp
abcdef g
使用单字节八进制解释进行输出,注意左侧的默认地址格式为八进制
[linuxde@localhost ~]$ od -b tmp
0000000 141 142 143 144 145 146 040 147 012
0000011
使用ASCII码进行输出,注意其中包括转义字符
[linuxde@localhost ~]$ od -c tmp
0000000 a b c d e f g
0000011
使用单字节十进制进行输出
[linuxde@localhost ~]$ od -t d1 tmp
0000000 97 98 99 100 101 102 32 103 10
0000011
设置地址格式为十进制
[linuxde@localhost ~]$ od -A d -c tmp
0000000 a b c d e f g
0000009
设置地址格式为十六进制
[linuxde@localhost ~]$ od -A x -c tmp
000000 a b c d e f g
000009
跳过开始的两个字节
[linuxde@localhost ~]$ od -j 2 -c tmp
0000002 c d e f g
0000011
跳过开始的两个字节,并且仅输出两个字节
[linuxde@localhost ~]$ od -N 2 -j 2 -c tmp
0000002 c d
0000004
每行仅输出1个字节
[linuxde@localhost ~]$ od -w1 -c tmp
0000000 a
0000001 b
0000002 c
0000003 d
0000004 e
0000005 f
0000006
0000007 g
0000010
0000011
每行输出两个字节
[linuxde@localhost ~]$ od -w2 -c tmp
0000000 a b
0000002 c d
0000004 e f
0000006 g
0000010
0000011
每行输出3个字节,并使用八进制单字节进行解释
[linuxde@localhost ~]$ od -w3 -b tmp
0000000 141 142 143
0000003 144 145 146
0000006 040 147 012
0000011
“过一个平凡无趣的人生实在太容易了,你可以不读书,不冒险,不运动,不写作,不外出,不折腾……但是,人生最后悔的事情就是:我本可以。”——陈素封。
转载自 程序员修练之路 https://www.cnblogs.com/hdk1993/p/4395574.html