Shell command: od
od dumps files in octal and other formats (such as hex numbers).
od 命令可以用来格式化查看文件或者内存块的数据内容
基本格式: od 选项 文件
Specify format (格式)
-t TYPE (see man od)
几种进制符号:
c printable character or backslash escape 按字符输出
d[SIZE] signed decimal, SIZE bytes per integer 有符号十进制,SIZE 表示每隔几个字节输出下一个十进制
f[SIZE] floating point, SIZE bytes per integer 浮点输出,
o[SIZE] octal, SIZE bytes per integer 八进制输出,默认
x[SIZE] hexadecimal, SIZE bytes per integer 十六进制输出
-A 指定地址的类型
n 不显示地址,
其他后面可接 x o 等显示16进制8进制的格式地址;
-t 指定输出内容的格式
可接 c d f o x 等类型
-w[SIZE] 每行显示的字节数
下面例子中/dev/shm/RECORD_EDIT_SERVER_DATA_BACK 为/dev/shm目录下的一片共享内存区域(文件)
如 od -A n -t c 不显示地址,内容以字符的形式显示:
[root@localhost test]# od -A n -t c /dev/shm/RECORD_EDIT_SERVER_DATA_BACK
\0 \0 \0 \0 002 \0 \0 \0 4 _ 0 _ 1 7 4 4
1 d 4 f 6 8 6 9 4 2 e d 9 4 2 2
8 f 5 a 9 f e d b 6 1 9 _ 1 5 5
3 3 3 0 9 0 6 8 6 3 \0 \0 \0 \0 \0 \0
\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
如 od -A x -t c 16进制显示地址,内容为字符显示:
[root@localhost test]# od -A x -t c /dev/shm/RECORD_EDIT_SERVER_DATA_BACK
000000 \0 \0 \0 \0 002 \0 \0 \0 4 _ 0 _ 1 7 4 4
000010 1 d 4 f 6 8 6 9 4 2 e d 9 4 2 2
000020 8 f 5 a 9 f e d b 6 1 9 _ 1 5 5
000030 3 3 3 0 9 0 6 8 6 3 \0 \0 \0 \0 \0 \0
000040 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
如 od -A x -t x 16进制显示地址,内容为16进制显示:
[root@localhost test]# od -A x -t x /dev/shm/RECORD_EDIT_SERVER_DATA_BACK
000000 00000000 00000002 5f305f34 34343731
000010 66346431 39363836 64653234 32323439
000020 61356638 64656639 39313662 3535315f
000030 30333333 38363039 00003336 00000000
000040 00000000 00000000 00000000 00000000
如 od -t x1 16进制显示地址,内容为16进制显示,显示单位1字节,-A省略,默认地址16进制输出:
[root@localhost test]# od -t x1 /dev/shm/RECORD_EDIT_SERVER_DATA_BACK
0000000 00 00 00 00 02 00 00 00 34 5f 30 5f 31 37 34 34
0000020 31 64 34 66 36 38 36 39 34 32 65 64 39 34 32 32
0000040 38 66 35 61 39 66 65 64 62 36 31 39 5f 31 35 35
0000060 33 33 33 30 39 30 36 38 36 33 00 00 00 00 00 00
0000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
如 od -t x2 -w8 16进制显示地址,内容为16进制显示,显示单位2字节, 每八个字节一行,(注意字节序):
[root@localhost test]# od -t x2 -w8 /dev/shm/RECORD_EDIT_SERVER_DATA_BACK
0000000 0000 0000 0002 0000
0000010 5f34 5f30 3731 3434
0000020 6431 6634 3836 3936
0000030 3234 6465 3439 3232
0000040 6638 6135 6639 6465
0000050 3662 3931 315f 3535
0000060 3333 3033 3039 3836
0000070 3336 0000 0000 0000
Specify range to be dumped (读取范围的指定)
The options -j (how many bytes to skip at the beginning) and -N (how many bytes to read) allow to specify a range that should be dumped:
od -j $startAtByte -N $countBytes $file
-j 指定从第几个字节读起
-N 读取多少个字节
如 od -j 4 -N 8 -t x1 从第4个字节开始,读取8个字节,16进制显示,显示单位为一字节,如下
[root@localhost test]# od -j 4 -N 8 -t x1 /dev/shm/RECORD_EDIT_SERVER_DATA_BACK
0000004 02 00 00 00 34 5f 30 5f
0000014