应用
- 在某些情况下,可能会用到全为某个值的 bin 文件,可使用 dd 命令配合 /dev/zero 这个特殊的文件设备,来生成全为 0x00 的 bin 文件,而后在使用 tr 命令,替换0x00 为 0xFF,命令如下所示:
dd if=/dev/zero bs=1M count=2 | tr "\000" "\377" > test.bin
命令生成全为 0xFF 的 2MB 的 bin 文件。 其中 \377 为八进制数,即 0xFF。
echo hello | dd bs=512 seek=2 conv=notrunc of=test.bin
可将 hello 写入到 test.bin 文件的 0x400 地址处,文件大小不变。 使用命令查看 
- 在新生成的 test.bin 中,从 0x200 地址开始,截取 2K 文件,生成 test1.bin 文件:
dd if=test.bin conv=notrunc bs=512 skip=1 count=4 of=test1.bin
此时 test1.bin 为 2K 大小,hello 位于 0x200 地址处 
相关参考
https://www.runoob.com/linux/linux-comm-tr.html https://www.runoob.com/linux/linux-comm-dd.html https://qastack.cn/superuser/274972/how-to-pad-a-file-with-ff-using-dd
|